Reading performance counters at this rate is a bit of a stretch in terms of overhead. That is exactly the reason why perf stat
has a lower limit of 10 ms
periods. It runs a userspace task for reading the counters in those intervals.
On the other hand, perf record
will setup the perf events such that they are recorded by the kernel itself on an overflow of the counter. The advantage is that it has less overhead, but the event is not necessarily recorded in regular time intervals. If you set perf record --frequency 1000
, the kernel will adapt the overflow rate of the counter trying to achieve the requested 1 millisecond intervals. The resulting time intervals will not be constant unless your event rate is really stable. If your event rate varies greatly, so will the time intervals.
Note that there is a mechanism in the kernel that will try to prevent perf from causing too much overhead. At your requested rate you will probably hit it.
Also you should not setup recording for an excessive amount of pids, instead setup a system-wide recording e.g.:
perf record --all-cpus --timestamp --freq 1000
You get one result file that you can process according to the pid. perf script
. In addition to the text output, perf script
allows you to process the events in python or perl (see man perf-script-python
, man perf-script-perl
).
perf stat --interval-print msecs -p $tmp
so you're not trying to fork+exec a newperf
process every millisecond. The manual says the minimum interval is 10ms, for that, but you could maybe build a custom version. The default timeslice is normally 10ms, so you might a kernel configured differently, maybe with HZ=1000 if Linux still uses HZ. (I haven't paid attention to scheduler tick resolution vs. NO_HZ tickless kernels recently.) – Peter Cordesperf record --timestamp will record timestamps on events
. The manual says "you can useperf report -D
to see the timestamps". I think something likeperf report
might be your best bet for recording things, and then process that data later. If you need something to happen every 1ms, you definitely want to avoid running a shell loop while recording data; that's a lot of system load. Useperf
's system-wide mode to have one instance ofperf
collect data from everything. – Peter Cordesperf record --all-cpus --timestamp
/perf report -D
, or other monitoring tools? – Peter Cordesperf stat
can only log every 10ms.perf record --timestamp
records all events as they happen, with high-resolution timestamps. The 10ms limit doesn't apply in any way toperf record
. – Peter Cordes