Pthread id from pthread_self () does not match data from dtrace script

I use this dtrace script from here to try and find when context switches are encountered for Java program threads.

I am trying to match the data collected from the script with the trace data collected from the running program (for example, when the method is entered / exited). I get the pthread id of the working thread using the short JNI method, which simply returns the value of pthread_self ().

The problem is that the thread id that I get from pthread_self () call is completely different from any thread id that I get in the dtrace script. I am interested because I am calling pthread_self () incorrectly as it returns a pointer, however it was hard to find information that pthread_t is actually located on mac osx.

+3
source share
4 answers

, , curthread tid dtrace , dtrace . .

, , , , ​​ , , . , , .

+3

/usr/include/pthread.h:

typedef __darwin_pthread_t pthread_t;

/usr/include/sys/_types.h:

struct _opaque_pthread_t {
  long __sig;
  struct __darwin_pthread_handler_rec* __cleanup_stack;
  char __opaque[__PTHREAD_SIZE__];
};
typedef struct _opaque_pthread_t* __darwin_pthread_t;

- :)

+2

- pid , ?

# dtrace -n 'pid$target::pthread_self:return {printf("%p", arg1)}' -c 'java'
dtrace: description 'pid$target::pthread_self:return ' matched 1 probe
dtrace: pid 87631 has exited
CPU     ID                    FUNCTION:NAME
  0  90705              pthread_self:return 1053a7000
  0  90705              pthread_self:return 1054ad000
  2  90705              pthread_self:return 7fff7b479180
  2  90705              pthread_self:return 7fff7b479180
  2  90705              pthread_self:return 7fff7b479180
  2  90705              pthread_self:return 7fff7b479180
  2  90705              pthread_self:return 7fff7b479180
  4  90705              pthread_self:return 10542a000
  4  90705              pthread_self:return 10542a000

!

arg1 , . , , copyin(arg1, size_of_struct) , (. @Nikolai , #include DTrace, -C ). pid$target pid1234, 1234 , -C - java.

( dtrace).

0

linux - :

pidstat -hluwrt  | grep "processname"

"tid" (# 3) "gettid()", , . , , gettid(): printf ( "% lul", gettid()).

2 , , "cswtch/s" () "nvcswtch/s" () .

"cswtch/s" (1000), "" "". , - , . ex: , . , , .

"nvswtch/s" (1000), , , . , : "" "htop" - .

script / ( 20 ):

stdbuf -oL pidstat -hluwrt  20 | stdbuf -oL grep -e "processname" -e "^#"

gettid: (doc here)
pidstat: (doc here)
stdbuf: (doc )

0

Source: https://habr.com/ru/post/1716067/


All Articles