Skip to content

Commit

Permalink
Capture the number of OS context switches
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Jun 27, 2020
1 parent d3e1886 commit 7dab89c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/apex/proc_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ namespace apex {
FILE *f = fopen("/proc/self/status", "r");
const std::string vm_prefix("Vm");
const std::string thread_prefix("Threads");
const std::string ctx_substr("ctxt_switches");
if (f) {
char line[4096] = {0};
while ( fgets( line, 4096, f)) {
Expand Down Expand Up @@ -821,6 +822,20 @@ namespace apex {
if (pEnd) { sample_value(mname, d1); }
}
}
if (tmp.find(ctx_substr) != tmp.npos) {
const REGEX_NAMESPACE::regex separator(":");
REGEX_NAMESPACE::sregex_token_iterator token(tmp.begin(),
tmp.end(), separator, -1);
REGEX_NAMESPACE::sregex_token_iterator end;
string name = *token++;
if (token != end) {
string value = *token;
char* pEnd;
double d1 = strtod (value.c_str(), &pEnd);
string mname("status:" + name);
if (pEnd) { sample_value(mname, d1); }
}
}
}
fclose(f);
} else {
Expand Down

0 comments on commit 7dab89c

Please sign in to comment.