Under sample mode, when I test on all cpus, pid = 1:
fd = perf_event_open(&attr, 1, -1, -1, 0);
I always see pid == tid:
**********************************
value of meta_page: 7fd262ce2000
value of meta_page->data_head: 9838
value of meta_page->data_tail: 9820
value of meta_page->data_size: 10000
The size of the data section is: 18
sample.addr: 0x5622ef76f948
sample.pid: 1
sample.tid: 1
the final current is: 36197080
the final upper bound is: 36197080
**********************************
**********************************
value of meta_page: 7fd262ce2000
value of meta_page->data_head: 9850
value of meta_page->data_tail: 9838
value of meta_page->data_size: 10000
The size of the data section is: 18
sample.addr: 0x7fffc51ef080
sample.pid: 1
sample.tid: 1
the final current is: 36197080
the final upper bound is: 36197080
**********************************
**********************************
value of meta_page: 7fd262ce2000
value of meta_page->data_head: 9850
value of meta_page->data_tail: 9850
value of meta_page->data_size: 10000
Full ring buffer
**********************************
I have done the following trials:
a) I bind mysqld to cpu 0 and 1, with taskset -cp 0,1 pidof(mysqld)
b) I test with fd = perf_event_open(&attr, -1, 0, -1, 0);
and I can see many results with pid == pidof(mysqld), which is 2211374 in the following example:
**********************************
value of meta_page: 7f6fa4a18000
value of meta_page->data_head: 15820
value of meta_page->data_tail: 157e8
value of meta_page->data_size: 10000
The size of the data section is: 38
the header type is: 6
sample.addr: 0x7f8dd802e058
sample.pid: 2211374
sample.tid: 3148307
the final current is: 12784408
the final upper bound is: 12784408
**********************************
**********************************
value of meta_page: 7f6fa4a18000
value of meta_page->data_head: 15858
value of meta_page->data_tail: 15820
value of meta_page->data_size: 10000
The size of the data section is: 38
the header type is: 5
sample.addr: 0x7f8e3ff75d90
sample.pid: 2211374
sample.tid: 3148308
the final current is: 12784408
the final upper bound is: 12784408
**********************************
**********************************
value of meta_page: 7f6fa4a18000
value of meta_page->data_head: 15890
value of meta_page->data_tail: 15858
value of meta_page->data_size: 10000
The size of the data section is: 38
the header type is: 6
sample.addr: 0x7f8da803b6e0
sample.pid: 2211374
sample.tid: 3148306
the final current is: 12784408
the final upper bound is: 12784408
**********************************
c) but I can get barely anything testing with fd = perf_event_open(&attr, pidof(mysqld), 0, -1, 0);
and fd = perf_event_open(&attr, pidof(mysqld), -1, -1, 0);
d) Quick summary of my tests:
i) I can get desired results when listening on specific CPU for all processes, including mysqld
ii) I can barely get anything when listening for specific process[mysqld], whether listening on all CPU/specific CPU
iii) I can see pid == tid when listening for process with pid = 1
Therefore I think it will be natural to make the assumption that the pid here in perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags)
is actually tid