Closed Bug 1329600 Opened 4 years ago Closed 2 months ago

Add CPU time usage to profiler

Categories

(Core :: Gecko Profiler, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
86 Branch
Tracking Status
firefox53 --- wontfix
firefox86 --- fixed

People

(Reporter: sinker, Assigned: gerald)

References

(Blocks 4 open bugs)

Details

Attachments

(4 files)

Running of a task does not mean that it is served for 100% of CPU time.  In another word, a task may be scheduled out for having a lower priority and other high priority tasks.  It would be useful to understand how much CPU time the kernel actually allocated for a thread.

For linux (MacOS?), getrusage(2) can be used to determine how much time a thread is scheduled for.  I am not sure, but there must be some similar API in Windows.
Blocks: 1329137
No longer blocks: 1329161
Duplicate of this bug: 1621407

In bug 1621407, :snorp wrote:

AFAIK we currently only record real time with each sample. If we also recorded the CPU time (CLOCK_THREAD_CPUTIME_ID on Linux), we would know how long the thread was scheduled by the OS. This may help developers to spot thread or process priority problems.

And coincidentally I've been thinking about this recently, and also for Windows (with e.g., https://docs.microsoft.com/en-au/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreadtimes ), so I'm reviving this bug here, I'm hoping I'll have time later this year -- patches always welcome before that, of course!

Priority: -- → P3
Type: defect → enhancement
See Also: → 1459668, 1462743
Blocks: 1646472
Blocks: 1659000
Depends on: 1670547
Depends on: 1679930
Assignee: nobody → gsquelart

The RunningTimes class stores CPU measurements. It may seem overkill for only one value, but in the future more measurements will be added.

During sampling, CPU measurements are collected by platform-specific code. This patch doesn't produce anything yet, see later patches.
These are stored with the samples.
Note that for duplicated samples (when a thread is known to be "asleep"), we still need to collect new measurements, because there could potentially be some activity happening, e.g. in system calls.
Finally the measurements are output as extra "samples" values.

Units for these values may platform-specific, so they are stored in the top-level JSON "meta" object.

We don't collect running times in the Base Profiler (yet), but we still need to add the appropriate field names in the samples' "schema", as expected by profiler.firefox.com.

Depends on D99054

ThreadCPUCycles are in nanoseconds, ThreadKernel/UserTimes in milliseconds with 10ms precision only.

Depends on D99415

Attachment #9192544 - Attachment description: Bug 1329600 - Scafolding to output CPU measurements in samples - r?canaltinova → Bug 1329600 - Scaffolding to output CPU measurements in samples - r?canaltinova
Pushed by gsquelart@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b9ff676042a8
Scaffolding to output CPU measurements in samples - r=canaltinova
https://hg.mozilla.org/integration/autoland/rev/6fc163c0f438
Capture CPU usage on Windows - r=canaltinova
https://hg.mozilla.org/integration/autoland/rev/86a42eeb5d85
Capture CPU usage on macos - r=canaltinova
https://hg.mozilla.org/integration/autoland/rev/c7e440ee02f8
Capture CPU usage on Linux - r=canaltinova,gcp
Blocks: 1397444
Blocks: 1685937
Blocks: 1685938
Blocks: 1687603
Blocks: 1687687
Blocks: 1687709
You need to log in before you can comment on or make changes to this bug.