summaryrefslogtreecommitdiffstats
path: root/src/proc_stat.c
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2017-01-24 15:21:09 +0000
committerLennart Weller <lhw@ring0.de>2017-01-24 15:21:09 +0000
commit3ed3b02ed96ddab1c084811f3579b3a2aec83e04 (patch)
tree7a61ab288ae47800c4f11be5677d6ad8288dcd98 /src/proc_stat.c
parentNew upstream version 1.4.0+dfsg (diff)
downloadnetdata-3ed3b02ed96ddab1c084811f3579b3a2aec83e04.tar.xz
netdata-3ed3b02ed96ddab1c084811f3579b3a2aec83e04.zip
New upstream version 1.5.0+dfsgupstream/1.5.0+dfsg
Diffstat (limited to 'src/proc_stat.c')
-rw-r--r--src/proc_stat.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/proc_stat.c b/src/proc_stat.c
index 88cb820b..f7e6d5bc 100644
--- a/src/proc_stat.c
+++ b/src/proc_stat.c
@@ -1,6 +1,6 @@
#include "common.h"
-int do_proc_stat(int update_every, unsigned long long dt) {
+int do_proc_stat(int update_every, usec_t dt) {
(void)dt;
static procfile *ff = NULL;
@@ -32,8 +32,8 @@ int do_proc_stat(int update_every, unsigned long long dt) {
ff = procfile_readall(ff);
if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
- uint32_t lines = procfile_lines(ff), l;
- uint32_t words;
+ size_t lines = procfile_lines(ff), l;
+ size_t words;
unsigned long long processes = 0, running = 0 , blocked = 0;
RRDSET *st;
@@ -46,7 +46,7 @@ int do_proc_stat(int update_every, unsigned long long dt) {
if(likely(row_key[0] == 'c' && row_key[1] == 'p' && row_key[2] == 'u')) {
words = procfile_linewords(ff, l);
if(unlikely(words < 9)) {
- error("Cannot read /proc/stat cpu line. Expected 9 params, read %u.", words);
+ error("Cannot read /proc/stat cpu line. Expected 9 params, read %zu.", words);
continue;
}
@@ -54,19 +54,19 @@ int do_proc_stat(int update_every, unsigned long long dt) {
unsigned long long user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0, softirq = 0, steal = 0, guest = 0, guest_nice = 0;
id = row_key;
- user = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
- nice = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
- system = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
- idle = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
- iowait = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
- irq = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
- softirq = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
- steal = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
-
- guest = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
+ user = str2ull(procfile_lineword(ff, l, 1));
+ nice = str2ull(procfile_lineword(ff, l, 2));
+ system = str2ull(procfile_lineword(ff, l, 3));
+ idle = str2ull(procfile_lineword(ff, l, 4));
+ iowait = str2ull(procfile_lineword(ff, l, 5));
+ irq = str2ull(procfile_lineword(ff, l, 6));
+ softirq = str2ull(procfile_lineword(ff, l, 7));
+ steal = str2ull(procfile_lineword(ff, l, 8));
+
+ guest = str2ull(procfile_lineword(ff, l, 9));
user -= guest;
- guest_nice = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
+ guest_nice = str2ull(procfile_lineword(ff, l, 10));
nice -= guest_nice;
char *title, *type, *context, *family;
@@ -126,8 +126,8 @@ int do_proc_stat(int update_every, unsigned long long dt) {
rrdset_done(st);
}
}
- else if(hash == hash_intr && strcmp(row_key, "intr") == 0) {
- unsigned long long value = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
+ else if(unlikely(hash == hash_intr && strcmp(row_key, "intr") == 0)) {
+ unsigned long long value = str2ull(procfile_lineword(ff, l, 1));
// --------------------------------------------------------------------
@@ -145,8 +145,8 @@ int do_proc_stat(int update_every, unsigned long long dt) {
rrdset_done(st);
}
}
- else if(hash == hash_ctxt && strcmp(row_key, "ctxt") == 0) {
- unsigned long long value = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
+ else if(unlikely(hash == hash_ctxt && strcmp(row_key, "ctxt") == 0)) {
+ unsigned long long value = str2ull(procfile_lineword(ff, l, 1));
// --------------------------------------------------------------------
@@ -163,14 +163,14 @@ int do_proc_stat(int update_every, unsigned long long dt) {
rrdset_done(st);
}
}
- else if(hash == hash_processes && !processes && strcmp(row_key, "processes") == 0) {
- processes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
+ else if(unlikely(hash == hash_processes && !processes && strcmp(row_key, "processes") == 0)) {
+ processes = str2ull(procfile_lineword(ff, l, 1));
}
- else if(hash == hash_procs_running && !running && strcmp(row_key, "procs_running") == 0) {
- running = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
+ else if(unlikely(hash == hash_procs_running && !running && strcmp(row_key, "procs_running") == 0)) {
+ running = str2ull(procfile_lineword(ff, l, 1));
}
- else if(hash == hash_procs_blocked && !blocked && strcmp(row_key, "procs_blocked") == 0) {
- blocked = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
+ else if(unlikely(hash == hash_procs_blocked && !blocked && strcmp(row_key, "procs_blocked") == 0)) {
+ blocked = str2ull(procfile_lineword(ff, l, 1));
}
}