cputime 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. .TH CPUTIME 2
  2. .SH NAME
  3. cputime, times, cycles \- cpu time in this process and children
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .ta \w'\fLdouble 'u
  10. .B
  11. long times(long t[4])
  12. .PP
  13. .B
  14. double cputime(void)
  15. .PP
  16. .B
  17. void cycles(uvlong *cyclep)
  18. .SH DESCRIPTION
  19. If
  20. .I t
  21. is non-null,
  22. .I times
  23. fills it in
  24. with the number of milliseconds spent in user code, system calls,
  25. child processes in user code, and child processes in system calls.
  26. .I Cputime
  27. returns the sum of those same times, converted to seconds.
  28. .I Times
  29. returns the elapsed real time, in milliseconds, that the process has been running.
  30. .PP
  31. These functions read
  32. .BR /dev/cputime ,
  33. opening that file when they are first called.
  34. .PP
  35. .I Cycles
  36. reads the processor's timestamp counter of cycles since reset,
  37. if any, and stores it via
  38. .IR cyclep .
  39. Currently supported architectures are
  40. .BR 386 ,
  41. .BR amd64 ,
  42. and
  43. .BR power ;
  44. on all others,
  45. .I cycles
  46. will store zero.
  47. .SH SOURCE
  48. .B /sys/src/libc/9sys
  49. .br
  50. .B /sys/src/libc/*/cycles.[cs]
  51. .SH SEE ALSO
  52. .IR exec (2),
  53. .IR cons (3)
  54. .SH BUGS
  55. Only
  56. .B 386
  57. processors starting with the Pentium have timestamp counters;
  58. calling
  59. .I cycles
  60. on earlier processors may execute an illegal instruction.