Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,865
    • Issues 4,865
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #21656
Closed
Open
Created May 26, 2022 by harendra@harendra

Inconsistent CPUTime reporting by getProcessCPUTime

Summary

Refer to the function getProcessCPUTime in https://gitlab.haskell.org/ghc/ghc/-/blob/master/rts/posix/GetTime.c .

When using clock_gettime it reports the total CPU time:

return getClockTime(CLOCK_PROCESS_CPUTIME_ID);

But when it defaults to getrusage it reports just the user time which is different from what we report in the case described above which is cpu time = user time + system time.

        getrusage(RUSAGE_SELF, &t);
        return SecondsToTime(t.ru_utime.tv_sec) + USToTime(t.ru_utime.tv_usec);

This leads to inconsistent interpretation of this stat depending on which implementation is used at runtime.

Steps to reproduce

I noticed this discrepancy when trying to match the ghc reported stats with the stats that I measured by some other means. Looking at the code I found that there are two different implementation and my system is picking up the getrusage implementation for some reason. We can reproduce it by changing the GHC code to force it to use one or the other implementation, not sure if there is a way to force it at runtime though.

Expected behavior

Irrespective of using clock_gettime or getrusage it should report the total cpu time.

Environment

  • GHC version used: 9.2 (the issue is present in all versions)

Optional:

  • Operating System: Linux
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking