Skip to content

Commit

Permalink
feat(server): Add support for CPU to Info family of commands (fixes #18
Browse files Browse the repository at this point in the history
…) (#143)

Signed-off-by: Acheev Bhagat <[email protected]>
  • Loading branch information
acheevbhagat authored Jun 12, 2022
1 parent d5cd317 commit 8809713
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/server/server_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,20 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
}
}

if (should_enter("CPU")) {
ADD_HEADER("# CPU");
struct rusage ru, cu, tu;
getrusage(RUSAGE_SELF, &ru);
getrusage(RUSAGE_CHILDREN, &cu);
getrusage(RUSAGE_THREAD, &tu);
append("used_cpu_sys", StrCat(ru.ru_stime.tv_sec, ".", ru.ru_stime.tv_usec));
append("used_cpu_user", StrCat(ru.ru_utime.tv_sec, ".", ru.ru_utime.tv_usec));
append("used_cpu_sys_children", StrCat(cu.ru_stime.tv_sec, ".", cu.ru_stime.tv_usec));
append("used_cpu_user_children", StrCat(cu.ru_utime.tv_sec, ".", cu.ru_utime.tv_usec));
append("used_cpu_sys_main_thread", StrCat(tu.ru_stime.tv_sec, ".", tu.ru_stime.tv_usec));
append("used_cpu_user_main_thread", StrCat(tu.ru_utime.tv_sec, ".", tu.ru_utime.tv_usec));
}

(*cntx)->SendBulkString(info);
}

Expand Down

0 comments on commit 8809713

Please sign in to comment.