MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / getTotalCpuTime

Method getTotalCpuTime

src/os_linux.cpp:363–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361}
362
363u64 OS::getTotalCpuTime(u64* utime, u64* stime) {
364 int fd = open("/proc/stat", O_RDONLY);
365 if (fd == -1) {
366 return (u64)-1;
367 }
368
369 u64 real = (u64)-1;
370 char buf[128] = {0};
371 if (read(fd, buf, sizeof(buf)) >= 12) {
372 u64 user, nice, system, idle;
373 if (sscanf(buf + 4, "%llu %llu %llu %llu", &user, &nice, &system, &idle) == 4) {
374 *utime = user + nice;
375 *stime = system;
376 real = user + nice + system + idle;
377 }
378 }
379
380 close(fd);
381 return real;
382}
383
384int OS::createMemoryFile(const char* name) {
385 return syscall(__NR_memfd_create, name, 0);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected