forked from steemit/steem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_dumper.cpp
More file actions
55 lines (42 loc) · 1.42 KB
/
Copy pathbenchmark_dumper.cpp
File metadata and controls
55 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <steem/utilities/benchmark_dumper.hpp>
namespace steem { namespace utilities {
#define PROC_STATUS_LINE_LENGTH 1028
typedef std::function<void(const char* key)> TScanErrorCallback;
unsigned long long read_u64_value_from(FILE* input, const char* key, unsigned key_length, TScanErrorCallback error_callback)
{
char line_buffer[PROC_STATUS_LINE_LENGTH];
while( fgets(line_buffer, PROC_STATUS_LINE_LENGTH, input) != nullptr )
{
const char* found_pos = strstr(line_buffer, key);
if( found_pos != nullptr )
{
unsigned long long result = 0;
if( sscanf(found_pos+key_length, "%llu", &result) != 1 )
{
error_callback(key);
}
return result;
}
}
error_callback(key);
return 0;
}
bool benchmark_dumper::read_mem(pid_t pid, uint64_t* current_virtual, uint64_t* peak_virtual)
{
const char* procPath = "/proc/self/status";
FILE* input = fopen(procPath, "r");
if(input == NULL)
{
elog( "cannot read: ${file} file.", ("file", procPath) );
return false;
}
TScanErrorCallback error_callback = [procPath](const char* key)
{
elog( "cannot read value of ${key} key in ${file}", ("key", key) ("file", procPath) );
};
*peak_virtual = read_u64_value_from( input, "VmPeak:", 7, error_callback );
*current_virtual = read_u64_value_from( input, "VmSize:", 7, error_callback );
fclose(input);
return true;
}
} }