How does Nsys calculate CPU utilization?

I ran the nsys profile command from my terminal with --sample none as a parameter, so it doesnt collect any CPU Samples, but i still see my CPU utilization here. How does it calculate that black line there if it is not collecting CPU samples? How can I extract it from the sqlite file. There is no COMPOSITE_EVENTS table if I dont sample.


Hi abhinav.chawla.95,

By default, nsys will collect CPU IP/backtrace samples and CPU context switch activity. Even when CPU IP/backtrace sampling is disabled with the ‘–sample none’ switch, CPU context switch activity is still collected. You can disable the CPU context switch tracing with the ‘–cpuctxsw none’ switch.

CPU Utilization is calculated using the CPU context switch data. You can find the CPU context switch data in the SCHED_EVENTS table when you export your collection, that includes CPU context switch data, to an sqlite DB.

Thanks a lot @rknight ! This does help! On the same topic, I do see a utilization percentage. Considering you schedule only the entry and exit of threads by a particular CPU how can you get a non 100% utilization of the CPU? For example, here how does your system tell its 5.5%?

Sorry for the slow reply. When you see a tooltip that provides both a Maximum and Average CPU utilization, it means that the cursor is on top of a pixel in a timeline row that represents multiple sched events. If you zoom into that area of the timeline, you will find that software threads have been scheduled on and off the CPU. If you zoom in enough, the CPU utilization tooltip will always show “>99.9” for the times when a thread is scheduled and no tooltip is shown for times when a thread is not scheduled.

Tooltips that only show a Maximum CPU utilization indicate the one or more threads were always scheduled on that CPU - i.e. the CPU was always busy at that point in the timeline.

This is an example. Notice that top timeline tooltip shows a Maximum of >99.9% and an Average of 65.7%. When I zoomed into this part of the timeline, the bottom timeline is produced and the times when the CPU was scheduled and unscheduled become more obvious. You can see that the CPU Utilization tooltips are all going to report >99.9% if you zoom in enough to see all of the scheduling changes.