Do not change the order of invoking system calls. We want to make CPU/Wall time correct as much as possible. Calling functions to get CPU/Wall time must closely surround the target code of measuring.
| 41 | // time correct as much as possible. Calling functions to get CPU/Wall time must |
| 42 | // closely surround the target code of measuring. |
| 43 | void Timer::Start() { |
| 44 | if (report_stream_) { |
| 45 | if (getrusage(RUSAGE_SELF, &usage_before_) == -1) |
| 46 | usage_status_ |= kGetrusageFailed; |
| 47 | if (clock_gettime(CLOCK_MONOTONIC, &wall_before_) == -1) |
| 48 | usage_status_ |= kClockGettimeWalltimeFailed; |
| 49 | if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &cpu_before_) == -1) |
| 50 | usage_status_ |= kClockGettimeCPUtimeFailed; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // The order of invoking system calls is important with the same reason as |
| 55 | // Timer::Start(). |
no outgoing calls