Skip to content

Commit

Permalink
Adding /proc/loadavg and changing to /proc/self/net
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Aug 8, 2019
1 parent 8e95669 commit 9aad70d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/apex/apex_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ inline unsigned int sc_nprocessors_onln()
macro (APEX_CSV_OUTPUT, use_csv_output, int, false) \
macro (APEX_TASKGRAPH_OUTPUT, use_taskgraph_output, bool, false) \
macro (APEX_PROC_CPUINFO, use_proc_cpuinfo, bool, false) \
macro (APEX_PROC_LOADAVG, use_proc_loadavg, bool, true) \
macro (APEX_PROC_MEMINFO, use_proc_meminfo, bool, false) \
macro (APEX_PROC_NET_DEV, use_proc_net_dev, bool, false) \
macro (APEX_PROC_SELF_STATUS, use_proc_self_status, bool, false) \
Expand Down
36 changes: 34 additions & 2 deletions src/apex/proc_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <atomic>
#include <unordered_set>
#include <string>
#include <cctype>
#ifdef __MIC__
#include "boost/regex.hpp"
#define REGEX_NAMESPACE boost
Expand Down Expand Up @@ -548,6 +549,7 @@ bool parse_proc_cpuinfo() {
string value = *token;
// check for no value
if (value.size() == 0) continue;
if (!isdigit(trim(value)[0])) continue;
name = trim(name);
char* pEnd;
double d1 = strtod (value.c_str(), &pEnd);
Expand All @@ -564,6 +566,35 @@ bool parse_proc_cpuinfo() {
return true;
}

bool parse_proc_loadavg() {
if (!apex_options::use_proc_loadavg()) return false;

FILE *f = fopen("/proc/loadavg", "r");
if (f) {
char line[4096] = {0};
while ( fgets( line, 4096, f)) {
string tmp(line);
tmp = trim(tmp);
// check for empty line
if (tmp.size() == 0) continue;
const REGEX_NAMESPACE::regex separator("0");
REGEX_NAMESPACE::sregex_token_iterator token(tmp.begin(), tmp.end(),
separator, -1);
REGEX_NAMESPACE::sregex_token_iterator end;
string value = *token;
if (value.size() == 0) continue;
char* pEnd;
double d1 = strtod (value.c_str(), &pEnd);
string cname("1 Minute Load average");
if (pEnd) { sample_value(cname, d1); }
}
fclose(f);
} else {
return false;
}
return true;
}

bool parse_proc_meminfo() {
if (!apex_options::use_proc_meminfo()) return false;
FILE *f = fopen("/proc/meminfo", "r");
Expand Down Expand Up @@ -650,7 +681,7 @@ bool parse_proc_self_io() {

bool parse_proc_netdev() {
if (!apex_options::use_proc_net_dev()) return false;
FILE *f = fopen("/proc/net/dev", "r");
FILE *f = fopen("/proc/self/net/dev", "r");
if (f) {
char line[4096] = {0};
char * rc = fgets(line, 4096, f); // skip this line
Expand Down Expand Up @@ -809,6 +840,7 @@ void* proc_data_reader::read_proc(void * _ptw) {
parse_proc_meminfo(); // some things change, others don't...
parse_proc_self_status(); // some things change, others don't...
parse_proc_self_io(); // some things change, others don't...
parse_proc_loadavg(); // this will change
parse_proc_netdev();
#ifdef APEX_HAVE_LM_SENSORS
mysensors->read_sensors();
Expand All @@ -833,7 +865,7 @@ void* proc_data_reader::read_proc(void * _ptw) {
delete(periodData);
oldData = newData;
}
if (done) break;
parse_proc_loadavg();
parse_proc_meminfo(); // some things change, others don't...
parse_proc_self_status();
parse_proc_self_io();
Expand Down
21 changes: 9 additions & 12 deletions src/examples/OpenMPOverhead/openmp_overhead.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string.h>
#include "apex.h"

#define MAX_ITERATIONS 500
#define MAX_ITERATIONS 10
#define N 4096*4096
#define MAX_THREADS 256

Expand Down Expand Up @@ -88,29 +88,26 @@ int main(int argc, char** argv)
static double x[N];
static double y[N];
apex_init("openmp test", 0, 1);
printf("Initializing...\n"); fflush(stdout);
printf("Initializing x...\n"); fflush(stdout);
my_init(x);
printf("Initializing...\n"); fflush(stdout);
printf("Initializing y...\n"); fflush(stdout);
my_init(y);

double result = 0.0;
int i = 0;

for (i = 0 ; i < MAX_ITERATIONS ; i++) {
//printf("Reduction sharing... "); fflush(stdout);
printf("%d Reduction sharing... ", i); fflush(stdout);
result = openmp_reduction(x, y);
//printf("Result: %f\n", result);
printf("%d Result: %f\n", i, result);

//printf("False sharing... "); fflush(stdout);
printf("%d False sharing... ", i); fflush(stdout);
result = false_sharing(x, y);
//printf("Result: %f\n", result);
printf("%d Result: %f\n", i, result);

//printf("No Sharing... "); fflush(stdout);
printf("%d No Sharing... ", i); fflush(stdout);
result = no_sharing(x, y);
//printf("Result: %f\n", result);
if (i % 50 == 0) {
printf("%d Result: %f\n", i, result);
}
printf("%d Result: %f\n", i, result); fflush(stdout);
}

apex_finalize();
Expand Down

0 comments on commit 9aad70d

Please sign in to comment.