开发者

PIN tool does not work on Postgresql

开发者 https://www.devze.com 2023-04-12 17:18 出处:网络
I am using PIN Tool to trace how many memory reads and writes while running a sql query. However, something strange happened. The memory addresses in the pinatrace.out for read/write I got from runnin

I am using PIN Tool to trace how many memory reads and writes while running a sql query. However, something strange happened. The memory addresses in the pinatrace.out for read/write I got from running

./pin -t pinatrace.so -- /usr/local/pgsql/bin/psql postgres < tmp.sql

... won't overlap with the memory addresses I printed from postgresql.

I added a few lines in the postgresql source code to print out addresses of some dummy pointers. It did print out the memory addresses in the log as I expected, but the addresses can not be found in the "pinatrace.out" that conta开发者_如何转开发ins all the memory addresses that have been accessed when attaching pin to psql.

However, when I copy the same lines of printing addresses of dummy pointers into a simple test.c file and run

./pin -t pinatrace.so -- ./test

... the addresses from the screen output can be found in the the pinatrace.out.

Both tests were run by postgres since I change the owner of PIN to be postgres.

I am really puzzled. Can someone be kind enough to point out what's going on? Does postgres allocate memory differently or I might run pin incorrectly? Any thoughts would help!

Please let me know if you want me to clarify the question further.


psql and the postgresql server never share memory, even if they are running as the same user: all their communication is done over a socket. If you want to investigate how a server backend is accessing memory, you need to attach your tracer to a backend process, not psql.

When you connect with psql, a new backend process is created that is dedicated to that connection. So you can call pg_backend_pid() from that psql and find the process ID to attach to, if PIN Tool supports that (e.g. like gdb does).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号