faster number parsing
Costa Tsaousis (ktsaou) committed
Jan 18, 2017 at 23:35 UTC
24f08563cf6392082c18a73e20f077bec3bdb92e
5 files changed
+198
-225
netdata-installer.sh
+3
-2
@@ -22,7 +22,8 @@ processors=$(cat /proc/cpuinfo | grep ^processor | wc -l)
22
[ $(( processors )) -lt 1 ] && processors=1
23
24
# you can set CFLAGS before running installer
25
-CFLAGS="${CFLAGS--O3}"
25
+CFLAGS="${CFLAGS--O2}"
26
+[ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
27
28
# keep a log of this command
29
printf "\n# " >>netdata-installer.log
@@ -112,7 +113,7 @@ Valid <installer options> are:
113
Use this option to allow it continue
114
without checking pkg-config.
115
115
-Netdata will by default be compiled with gcc optimization -O3
116
+Netdata will by default be compiled with gcc optimization -O2
117
If you need to pass different CFLAGS, use something like this:
118
119
CFLAGS="<gcc options>" ${ME} <installer options>
src/apps_plugin.c
+63
-63
@@ -609,85 +609,85 @@ static inline int read_proc_pid_stat(struct pid_stat *p) {
609
p->stat_collected_usec = now_realtime_usec();
610
file_counter++;
611
612
- // p->pid = atol(procfile_lineword(ff, 0, 0+i));
612
+ // p->pid = str2ul(procfile_lineword(ff, 0, 0+i));
613
614
strncpyz(p->comm, procfile_lineword(ff, 0, 1), MAX_COMPARE_NAME);
615
616
// p->state = *(procfile_lineword(ff, 0, 2));
617
- p->ppid = (int32_t) atol(procfile_lineword(ff, 0, 3));
618
- // p->pgrp = atol(procfile_lineword(ff, 0, 4));
619
- // p->session = atol(procfile_lineword(ff, 0, 5));
620
- // p->tty_nr = atol(procfile_lineword(ff, 0, 6));
621
- // p->tpgid = atol(procfile_lineword(ff, 0, 7));
622
- // p->flags = strtoull(procfile_lineword(ff, 0, 8), NULL, 10);
617
+ p->ppid = (int32_t)str2ul(procfile_lineword(ff, 0, 3));
618
+ // p->pgrp = str2ul(procfile_lineword(ff, 0, 4));
619
+ // p->session = str2ul(procfile_lineword(ff, 0, 5));
620
+ // p->tty_nr = str2ul(procfile_lineword(ff, 0, 6));
621
+ // p->tpgid = str2ul(procfile_lineword(ff, 0, 7));
622
+ // p->flags = str2ull(procfile_lineword(ff, 0, 8));
623
624
unsigned long long last;
625
626
last = p->minflt_raw;
627
- p->minflt_raw = strtoull(procfile_lineword(ff, 0, 9), NULL, 10);
627
+ p->minflt_raw = str2ull(procfile_lineword(ff, 0, 9));
628
p->minflt = (p->minflt_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
629
630
last = p->cminflt_raw;
631
- p->cminflt_raw = strtoull(procfile_lineword(ff, 0, 10), NULL, 10);
631
+ p->cminflt_raw = str2ull(procfile_lineword(ff, 0, 10));
632
p->cminflt = (p->cminflt_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
633
634
last = p->majflt_raw;
635
- p->majflt_raw = strtoull(procfile_lineword(ff, 0, 11), NULL, 10);
635
+ p->majflt_raw = str2ull(procfile_lineword(ff, 0, 11));
636
p->majflt = (p->majflt_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
637
638
last = p->cmajflt_raw;
639
- p->cmajflt_raw = strtoull(procfile_lineword(ff, 0, 12), NULL, 10);
639
+ p->cmajflt_raw = str2ull(procfile_lineword(ff, 0, 12));
640
p->cmajflt = (p->cmajflt_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
641
642
last = p->utime_raw;
643
- p->utime_raw = strtoull(procfile_lineword(ff, 0, 13), NULL, 10);
643
+ p->utime_raw = str2ull(procfile_lineword(ff, 0, 13));
644
p->utime = (p->utime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
645
646
last = p->stime_raw;
647
- p->stime_raw = strtoull(procfile_lineword(ff, 0, 14), NULL, 10);
647
+ p->stime_raw = str2ull(procfile_lineword(ff, 0, 14));
648
p->stime = (p->stime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
649
650
last = p->cutime_raw;
651
- p->cutime_raw = strtoull(procfile_lineword(ff, 0, 15), NULL, 10);
651
+ p->cutime_raw = str2ull(procfile_lineword(ff, 0, 15));
652
p->cutime = (p->cutime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
653
654
last = p->cstime_raw;
655
- p->cstime_raw = strtoull(procfile_lineword(ff, 0, 16), NULL, 10);
655
+ p->cstime_raw = str2ull(procfile_lineword(ff, 0, 16));
656
p->cstime = (p->cstime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
657
658
- // p->priority = strtoull(procfile_lineword(ff, 0, 17), NULL, 10);
659
- // p->nice = strtoull(procfile_lineword(ff, 0, 18), NULL, 10);
660
- p->num_threads = (int32_t) atol(procfile_lineword(ff, 0, 19));
661
- // p->itrealvalue = strtoull(procfile_lineword(ff, 0, 20), NULL, 10);
662
- // p->starttime = strtoull(procfile_lineword(ff, 0, 21), NULL, 10);
663
- // p->vsize = strtoull(procfile_lineword(ff, 0, 22), NULL, 10);
664
- // p->rss = strtoull(procfile_lineword(ff, 0, 23), NULL, 10);
665
- // p->rsslim = strtoull(procfile_lineword(ff, 0, 24), NULL, 10);
666
- // p->starcode = strtoull(procfile_lineword(ff, 0, 25), NULL, 10);
667
- // p->endcode = strtoull(procfile_lineword(ff, 0, 26), NULL, 10);
668
- // p->startstack = strtoull(procfile_lineword(ff, 0, 27), NULL, 10);
669
- // p->kstkesp = strtoull(procfile_lineword(ff, 0, 28), NULL, 10);
670
- // p->kstkeip = strtoull(procfile_lineword(ff, 0, 29), NULL, 10);
671
- // p->signal = strtoull(procfile_lineword(ff, 0, 30), NULL, 10);
672
- // p->blocked = strtoull(procfile_lineword(ff, 0, 31), NULL, 10);
673
- // p->sigignore = strtoull(procfile_lineword(ff, 0, 32), NULL, 10);
674
- // p->sigcatch = strtoull(procfile_lineword(ff, 0, 33), NULL, 10);
675
- // p->wchan = strtoull(procfile_lineword(ff, 0, 34), NULL, 10);
676
- // p->nswap = strtoull(procfile_lineword(ff, 0, 35), NULL, 10);
677
- // p->cnswap = strtoull(procfile_lineword(ff, 0, 36), NULL, 10);
678
- // p->exit_signal = atol(procfile_lineword(ff, 0, 37));
679
- // p->processor = atol(procfile_lineword(ff, 0, 38));
680
- // p->rt_priority = strtoul(procfile_lineword(ff, 0, 39), NULL, 10);
681
- // p->policy = strtoul(procfile_lineword(ff, 0, 40), NULL, 10);
682
- // p->delayacct_blkio_ticks = strtoull(procfile_lineword(ff, 0, 41), NULL, 10);
658
+ // p->priority = str2ull(procfile_lineword(ff, 0, 17));
659
+ // p->nice = str2ull(procfile_lineword(ff, 0, 18));
660
+ p->num_threads = (int32_t)str2ul(procfile_lineword(ff, 0, 19));
661
+ // p->itrealvalue = str2ull(procfile_lineword(ff, 0, 20));
662
+ // p->starttime = str2ull(procfile_lineword(ff, 0, 21));
663
+ // p->vsize = str2ull(procfile_lineword(ff, 0, 22));
664
+ // p->rss = str2ull(procfile_lineword(ff, 0, 23));
665
+ // p->rsslim = str2ull(procfile_lineword(ff, 0, 24));
666
+ // p->starcode = str2ull(procfile_lineword(ff, 0, 25));
667
+ // p->endcode = str2ull(procfile_lineword(ff, 0, 26));
668
+ // p->startstack = str2ull(procfile_lineword(ff, 0, 27));
669
+ // p->kstkesp = str2ull(procfile_lineword(ff, 0, 28));
670
+ // p->kstkeip = str2ull(procfile_lineword(ff, 0, 29));
671
+ // p->signal = str2ull(procfile_lineword(ff, 0, 30));
672
+ // p->blocked = str2ull(procfile_lineword(ff, 0, 31));
673
+ // p->sigignore = str2ull(procfile_lineword(ff, 0, 32));
674
+ // p->sigcatch = str2ull(procfile_lineword(ff, 0, 33));
675
+ // p->wchan = str2ull(procfile_lineword(ff, 0, 34));
676
+ // p->nswap = str2ull(procfile_lineword(ff, 0, 35));
677
+ // p->cnswap = str2ull(procfile_lineword(ff, 0, 36));
678
+ // p->exit_signal = str2ul(procfile_lineword(ff, 0, 37));
679
+ // p->processor = str2ul(procfile_lineword(ff, 0, 38));
680
+ // p->rt_priority = str2ul(procfile_lineword(ff, 0, 39));
681
+ // p->policy = str2ul(procfile_lineword(ff, 0, 40));
682
+ // p->delayacct_blkio_ticks = str2ull(procfile_lineword(ff, 0, 41));
683
684
if(enable_guest_charts) {
685
last = p->gtime_raw;
686
- p->gtime_raw = strtoull(procfile_lineword(ff, 0, 42), NULL, 10);
686
+ p->gtime_raw = str2ull(procfile_lineword(ff, 0, 42));
687
p->gtime = (p->gtime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
688
689
last = p->cgtime_raw;
690
- p->cgtime_raw = strtoull(procfile_lineword(ff, 0, 43), NULL, 10);
690
+ p->cgtime_raw = str2ull(procfile_lineword(ff, 0, 43));
691
p->cgtime = (p->cgtime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->stat_collected_usec - p->last_stat_collected_usec);
692
693
if (show_guest_time || p->gtime || p->cgtime) {
@@ -748,13 +748,13 @@ static inline int read_proc_pid_statm(struct pid_stat *p) {
748
749
file_counter++;
750
751
- p->statm_size = strtoull(procfile_lineword(ff, 0, 0), NULL, 10);
752
- p->statm_resident = strtoull(procfile_lineword(ff, 0, 1), NULL, 10);
753
- p->statm_share = strtoull(procfile_lineword(ff, 0, 2), NULL, 10);
754
- // p->statm_text = strtoull(procfile_lineword(ff, 0, 3), NULL, 10);
755
- // p->statm_lib = strtoull(procfile_lineword(ff, 0, 4), NULL, 10);
756
- // p->statm_data = strtoull(procfile_lineword(ff, 0, 5), NULL, 10);
757
- // p->statm_dirty = strtoull(procfile_lineword(ff, 0, 6), NULL, 10);
751
+ p->statm_size = str2ull(procfile_lineword(ff, 0, 0));
752
+ p->statm_resident = str2ull(procfile_lineword(ff, 0, 1));
753
+ p->statm_share = str2ull(procfile_lineword(ff, 0, 2));
754
+ // p->statm_text = str2ull(procfile_lineword(ff, 0, 3));
755
+ // p->statm_lib = str2ull(procfile_lineword(ff, 0, 4));
756
+ // p->statm_data = str2ull(procfile_lineword(ff, 0, 5));
757
+ // p->statm_dirty = str2ull(procfile_lineword(ff, 0, 6));
758
759
return 1;
760
@@ -793,31 +793,31 @@ static inline int read_proc_pid_io(struct pid_stat *p) {
793
unsigned long long last;
794
795
last = p->io_logical_bytes_read_raw;
796
- p->io_logical_bytes_read_raw = strtoull(procfile_lineword(ff, 0, 1), NULL, 10);
796
+ p->io_logical_bytes_read_raw = str2ull(procfile_lineword(ff, 0, 1));
797
p->io_logical_bytes_read = (p->io_logical_bytes_read_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->io_collected_usec - p->last_io_collected_usec);
798
799
last = p->io_logical_bytes_written_raw;
800
- p->io_logical_bytes_written_raw = strtoull(procfile_lineword(ff, 1, 1), NULL, 10);
800
+ p->io_logical_bytes_written_raw = str2ull(procfile_lineword(ff, 1, 1));
801
p->io_logical_bytes_written = (p->io_logical_bytes_written_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->io_collected_usec - p->last_io_collected_usec);
802
803
// last = p->io_read_calls_raw;
804
- // p->io_read_calls_raw = strtoull(procfile_lineword(ff, 2, 1), NULL, 10);
804
+ // p->io_read_calls_raw = str2ull(procfile_lineword(ff, 2, 1));
805
// p->io_read_calls = (p->io_read_calls_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->io_collected_usec - p->last_io_collected_usec);
806
807
// last = p->io_write_calls_raw;
808
- // p->io_write_calls_raw = strtoull(procfile_lineword(ff, 3, 1), NULL, 10);
808
+ // p->io_write_calls_raw = str2ull(procfile_lineword(ff, 3, 1));
809
// p->io_write_calls = (p->io_write_calls_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->io_collected_usec - p->last_io_collected_usec);
810
811
last = p->io_storage_bytes_read_raw;
812
- p->io_storage_bytes_read_raw = strtoull(procfile_lineword(ff, 4, 1), NULL, 10);
812
+ p->io_storage_bytes_read_raw = str2ull(procfile_lineword(ff, 4, 1));
813
p->io_storage_bytes_read = (p->io_storage_bytes_read_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->io_collected_usec - p->last_io_collected_usec);
814
815
last = p->io_storage_bytes_written_raw;
816
- p->io_storage_bytes_written_raw = strtoull(procfile_lineword(ff, 5, 1), NULL, 10);
816
+ p->io_storage_bytes_written_raw = str2ull(procfile_lineword(ff, 5, 1));
817
p->io_storage_bytes_written = (p->io_storage_bytes_written_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->io_collected_usec - p->last_io_collected_usec);
818
819
// last = p->io_cancelled_write_bytes_raw;
820
- // p->io_cancelled_write_bytes_raw = strtoull(procfile_lineword(ff, 6, 1), NULL, 10);
820
+ // p->io_cancelled_write_bytes_raw = str2ull(procfile_lineword(ff, 6, 1));
821
// p->io_cancelled_write_bytes = (p->io_cancelled_write_bytes_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (p->io_collected_usec - p->last_io_collected_usec);
822
823
if(unlikely(global_iterations_counter == 1)) {
@@ -870,26 +870,26 @@ static inline int read_proc_stat() {
870
unsigned long long last;
871
872
last = utime_raw;
873
- utime_raw = strtoull(procfile_lineword(ff, 0, 1), NULL, 10);
873
+ utime_raw = str2ull(procfile_lineword(ff, 0, 1));
874
global_utime = (utime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (collected_usec - last_collected_usec);
875
876
// nice time, on user time
877
last = ntime_raw;
878
- ntime_raw = strtoull(procfile_lineword(ff, 0, 2), NULL, 10);
878
+ ntime_raw = str2ull(procfile_lineword(ff, 0, 2));
879
global_utime += (ntime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (collected_usec - last_collected_usec);
880
881
last = stime_raw;
882
- stime_raw = strtoull(procfile_lineword(ff, 0, 3), NULL, 10);
882
+ stime_raw = str2ull(procfile_lineword(ff, 0, 3));
883
global_stime = (stime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (collected_usec - last_collected_usec);
884
885
last = gtime_raw;
886
- gtime_raw = strtoull(procfile_lineword(ff, 0, 10), NULL, 10);
886
+ gtime_raw = str2ull(procfile_lineword(ff, 0, 10));
887
global_gtime = (gtime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (collected_usec - last_collected_usec);
888
889
if(enable_guest_charts) {
890
// guest nice time, on guest time
891
last = gntime_raw;
892
- gntime_raw = strtoull(procfile_lineword(ff, 0, 11), NULL, 10);
892
+ gntime_raw = str2ull(procfile_lineword(ff, 0, 11));
893
global_gtime += (gntime_raw - last) * (USEC_PER_SEC * RATES_DETAIL) / (collected_usec - last_collected_usec);
894
895
// remove guest time from user time
@@ -1177,7 +1177,7 @@ static inline int read_pid_file_descriptors(struct pid_stat *p) {
1177
continue;
1178
1179
// check if the fds array is small
1180
- int fdid = atoi(de->d_name);
1180
+ int fdid = (int)str2l(de->d_name);
1181
if(fdid < 0) continue;
1182
if(fdid >= p->fds_size) {
1183
// it is small, extend it
@@ -2677,7 +2677,7 @@ static void parse_args(int argc, char **argv)
2677
2678
for(i = 1; i < argc; i++) {
2679
if(!freq) {
2680
- int n = atoi(argv[i]);
2680
+ int n = (int)str2l(argv[i]);
2681
if(n > 0) {
2682
freq = n;
2683
continue;
src/common.c
+15
@@ -1194,3 +1194,18 @@ void get_system_HZ(void) {
1194
1195
hz = (unsigned int) ticks;
1196
}
1197
+
1198
+/*
1199
+// poor man cycle counting
1200
+static unsigned long tsc;
1201
+void begin_tsc(void) {
1202
+ unsigned long a, d;
1203
+ asm volatile ("cpuid\nrdtsc" : "=a" (a), "=d" (d) : "0" (0) : "ebx", "ecx");
1204
+ tsc = ((unsigned long)d << 32) | (unsigned long)a;
1205
+}
1206
+unsigned long end_tsc(void) {
1207
+ unsigned long a, d;
1208
+ asm volatile ("rdtscp" : "=a" (a), "=d" (d) : : "ecx");
1209
+ return (((unsigned long)d << 32) | (unsigned long)a) - tsc;
1210
+}
1211
+*/
src/inlined.h
+36
-1
@@ -3,7 +3,7 @@
3
4
#include "common.h"
5
6
-#ifdef HAVE_STMT_EXPR
6
+#ifdef HAVE_STMT_EXPR_NON_EXISTING
7
// GCC extension to define a function as a preprocessor macro
8
9
#define simple_hash(name) ({ \
@@ -55,6 +55,41 @@ static inline uint32_t simple_uhash(const char *name) {
55
56
#endif /* HAVE_STMT_EXPR */
57
58
+static inline long str2l(const char *s) {
59
+ register long n = 0;
60
+ register char c, negative = (*s == '-');
61
+
62
+ for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) {
63
+ n *= 10;
64
+ n += c - '0';
65
+ }
66
+
67
+ if(unlikely(negative))
68
+ return -n;
69
+
70
+ return n;
71
+}
72
+
73
+static inline unsigned long str2ul(const char *s) {
74
+ register unsigned long n = 0;
75
+ register char c;
76
+ for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
77
+ n *= 10;
78
+ n += c - '0';
79
+ }
80
+ return n;
81
+}
82
+
83
+static inline unsigned long long str2ull(const char *s) {
84
+ register unsigned long long n = 0;
85
+ register char c;
86
+ for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
87
+ n *= 10;
88
+ n += c - '0';
89
+ }
90
+ return n;
91
+}
92
+
93
static inline int read_single_number_file(const char *filename, unsigned long long *result) {
94
char buffer[1024 + 1];
95
src/sys_fs_cgroup.c
+81
-159
@@ -494,15 +494,11 @@ static inline void cgroup_read_cpuacct_stat(struct cpuacct_stat *cp) {
494
char *s = procfile_lineword(ff, i, 0);
495
uint32_t hash = simple_hash(s);
496
497
- if(unlikely(hash == user_hash && !strcmp(s, "user"))) {
498
- cp->user = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
499
- continue;
500
- }
497
+ if(unlikely(hash == user_hash && !strcmp(s, "user")))
498
+ cp->user = str2ull(procfile_lineword(ff, i, 1));
499
502
- if(unlikely(hash == system_hash && !strcmp(s, "system"))) {
503
- cp->system = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
504
- continue;
505
- }
500
+ else if(unlikely(hash == system_hash && !strcmp(s, "system")))
501
+ cp->system = str2ull(procfile_lineword(ff, i, 1));
502
}
503
504
cp->updated = 1;
@@ -555,7 +551,7 @@ static inline void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) {
551
552
unsigned long long total = 0;
553
for(i = 0; i < ca->cpus ;i++) {
558
- unsigned long long n = strtoull(procfile_lineword(ff, 0, i), NULL, 10);
554
+ unsigned long long n = str2ull(procfile_lineword(ff, 0, i));
555
ca->cpu_percpu[i] = n;
556
total += n;
557
}
@@ -608,31 +604,21 @@ static inline void cgroup_read_blkio(struct blkio *io) {
604
char *s = procfile_lineword(ff, i, 1);
605
uint32_t hash = simple_hash(s);
606
611
- if(unlikely(hash == Read_hash && !strcmp(s, "Read"))) {
612
- io->Read += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
613
- continue;
614
- }
607
+ if(unlikely(hash == Read_hash && !strcmp(s, "Read")))
608
+ io->Read += str2ull(procfile_lineword(ff, i, 2));
609
616
- if(unlikely(hash == Write_hash && !strcmp(s, "Write"))) {
617
- io->Write += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
618
- continue;
619
- }
610
+ else if(unlikely(hash == Write_hash && !strcmp(s, "Write")))
611
+ io->Write += str2ull(procfile_lineword(ff, i, 2));
612
613
/*
622
- if(hash == Sync_hash && !strcmp(s, "Sync")) {
623
- io->Sync += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
624
- continue;
625
- }
614
+ else if(unlikely(hash == Sync_hash && !strcmp(s, "Sync")))
615
+ io->Sync += str2ull(procfile_lineword(ff, i, 2));
616
627
- if(hash == Async_hash && !strcmp(s, "Async")) {
628
- io->Async += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
629
- continue;
630
- }
617
+ else if(unlikely(hash == Async_hash && !strcmp(s, "Async")))
618
+ io->Async += str2ull(procfile_lineword(ff, i, 2));
619
632
- if(hash == Total_hash && !strcmp(s, "Total")) {
633
- io->Total += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
634
- continue;
635
- }
620
+ else if(unlikely(hash == Total_hash && !strcmp(s, "Total")))
621
+ io->Total += str2ull(procfile_lineword(ff, i, 2));
622
*/
623
}
624
@@ -681,173 +667,109 @@ static inline void cgroup_read_memory(struct memory *mem) {
667
char *s = procfile_lineword(ff, i, 0);
668
uint32_t hash = simple_hash(s);
669
684
- if(unlikely(hash == cache_hash && !strcmp(s, "cache"))) {
685
- mem->cache = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
686
- continue;
687
- }
670
+ if(unlikely(hash == cache_hash && !strcmp(s, "cache")))
671
+ mem->cache = str2ull(procfile_lineword(ff, i, 1));
672
689
- if(unlikely(hash == rss_hash && !strcmp(s, "rss"))) {
690
- mem->rss = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
691
- continue;
692
- }
673
+ else if(unlikely(hash == rss_hash && !strcmp(s, "rss")))
674
+ mem->rss = str2ull(procfile_lineword(ff, i, 1));
675
694
- if(unlikely(hash == rss_huge_hash && !strcmp(s, "rss_huge"))) {
695
- mem->rss_huge = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
696
- continue;
697
- }
676
+ else if(unlikely(hash == rss_huge_hash && !strcmp(s, "rss_huge")))
677
+ mem->rss_huge = str2ull(procfile_lineword(ff, i, 1));
678
699
- if(unlikely(hash == mapped_file_hash && !strcmp(s, "mapped_file"))) {
700
- mem->mapped_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
701
- continue;
702
- }
679
+ else if(unlikely(hash == mapped_file_hash && !strcmp(s, "mapped_file")))
680
+ mem->mapped_file = str2ull(procfile_lineword(ff, i, 1));
681
704
- if(unlikely(hash == writeback_hash && !strcmp(s, "writeback"))) {
705
- mem->writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
706
- continue;
707
- }
682
+ else if(unlikely(hash == writeback_hash && !strcmp(s, "writeback")))
683
+ mem->writeback = str2ull(procfile_lineword(ff, i, 1));
684
709
- if(unlikely(hash == dirty_hash && !strcmp(s, "dirty"))) {
710
- mem->dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
685
+ else if(unlikely(hash == dirty_hash && !strcmp(s, "dirty"))) {
686
+ mem->dirty = str2ull(procfile_lineword(ff, i, 1));
687
mem->detailed_has_dirty = 1;
712
- continue;
688
}
689
715
- if(unlikely(hash == swap_hash && !strcmp(s, "swap"))) {
716
- mem->swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
690
+ else if(unlikely(hash == swap_hash && !strcmp(s, "swap"))) {
691
+ mem->swap = str2ull(procfile_lineword(ff, i, 1));
692
mem->detailed_has_swap = 1;
718
- continue;
693
}
694
721
- if(unlikely(hash == pgpgin_hash && !strcmp(s, "pgpgin"))) {
722
- mem->pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
723
- continue;
724
- }
695
+ else if(unlikely(hash == pgpgin_hash && !strcmp(s, "pgpgin")))
696
+ mem->pgpgin = str2ull(procfile_lineword(ff, i, 1));
697
726
- if(unlikely(hash == pgpgout_hash && !strcmp(s, "pgpgout"))) {
727
- mem->pgpgout = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
728
- continue;
729
- }
698
+ else if(unlikely(hash == pgpgout_hash && !strcmp(s, "pgpgout")))
699
+ mem->pgpgout = str2ull(procfile_lineword(ff, i, 1));
700
731
- if(unlikely(hash == pgfault_hash && !strcmp(s, "pgfault"))) {
732
- mem->pgfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
733
- continue;
734
- }
701
+ else if(unlikely(hash == pgfault_hash && !strcmp(s, "pgfault")))
702
+ mem->pgfault = str2ull(procfile_lineword(ff, i, 1));
703
736
- if(unlikely(hash == pgmajfault_hash && !strcmp(s, "pgmajfault"))) {
737
- mem->pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
738
- continue;
739
- }
704
+ else if(unlikely(hash == pgmajfault_hash && !strcmp(s, "pgmajfault")))
705
+ mem->pgmajfault = str2ull(procfile_lineword(ff, i, 1));
706
707
/*
742
- if(unlikely(hash == inactive_anon_hash && !strcmp(s, "inactive_anon"))) {
743
- mem->inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
744
- continue;
745
- }
708
+ else if(unlikely(hash == inactive_anon_hash && !strcmp(s, "inactive_anon")))
709
+ mem->inactive_anon = str2ull(procfile_lineword(ff, i, 1));
710
747
- if(unlikely(hash == active_anon_hash && !strcmp(s, "active_anon"))) {
748
- mem->active_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
749
- continue;
750
- }
711
+ else if(unlikely(hash == active_anon_hash && !strcmp(s, "active_anon")))
712
+ mem->active_anon = str2ull(procfile_lineword(ff, i, 1));
713
752
- if(unlikely(hash == inactive_file_hash && !strcmp(s, "inactive_file"))) {
753
- mem->inactive_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
754
- continue;
755
- }
714
+ else if(unlikely(hash == inactive_file_hash && !strcmp(s, "inactive_file")))
715
+ mem->inactive_file = str2ull(procfile_lineword(ff, i, 1));
716
757
- if(unlikely(hash == active_file_hash && !strcmp(s, "active_file"))) {
758
- mem->active_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
759
- continue;
760
- }
717
+ else if(unlikely(hash == active_file_hash && !strcmp(s, "active_file")))
718
+ mem->active_file = str2ull(procfile_lineword(ff, i, 1));
719
762
- if(unlikely(hash == unevictable_hash && !strcmp(s, "unevictable"))) {
763
- mem->unevictable = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
764
- continue;
765
- }
720
+ else if(unlikely(hash == unevictable_hash && !strcmp(s, "unevictable")))
721
+ mem->unevictable = str2ull(procfile_lineword(ff, i, 1));
722
767
- if(unlikely(hash == hierarchical_memory_limit_hash && !strcmp(s, "hierarchical_memory_limit"))) {
768
- mem->hierarchical_memory_limit = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
769
- continue;
770
- }
723
+ else if(unlikely(hash == hierarchical_memory_limit_hash && !strcmp(s, "hierarchical_memory_limit")))
724
+ mem->hierarchical_memory_limit = str2ull(procfile_lineword(ff, i, 1));
725
772
- if(unlikely(hash == total_cache_hash && !strcmp(s, "total_cache"))) {
773
- mem->total_cache = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
774
- continue;
775
- }
726
+ else if(unlikely(hash == total_cache_hash && !strcmp(s, "total_cache")))
727
+ mem->total_cache = str2ull(procfile_lineword(ff, i, 1));
728
777
- if(unlikely(hash == total_rss_hash && !strcmp(s, "total_rss"))) {
778
- mem->total_rss = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
779
- continue;
780
- }
729
+ else if(unlikely(hash == total_rss_hash && !strcmp(s, "total_rss")))
730
+ mem->total_rss = str2ull(procfile_lineword(ff, i, 1));
731
782
- if(unlikely(hash == total_rss_huge_hash && !strcmp(s, "total_rss_huge"))) {
783
- mem->total_rss_huge = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
784
- continue;
785
- }
732
+ else if(unlikely(hash == total_rss_huge_hash && !strcmp(s, "total_rss_huge")))
733
+ mem->total_rss_huge = str2ull(procfile_lineword(ff, i, 1));
734
787
- if(unlikely(hash == total_mapped_file_hash && !strcmp(s, "total_mapped_file"))) {
788
- mem->total_mapped_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
789
- continue;
790
- }
735
+ else if(unlikely(hash == total_mapped_file_hash && !strcmp(s, "total_mapped_file")))
736
+ mem->total_mapped_file = str2ull(procfile_lineword(ff, i, 1));
737
792
- if(unlikely(hash == total_writeback_hash && !strcmp(s, "total_writeback"))) {
793
- mem->total_writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
794
- continue;
795
- }
738
+ else if(unlikely(hash == total_writeback_hash && !strcmp(s, "total_writeback")))
739
+ mem->total_writeback = str2ull(procfile_lineword(ff, i, 1));
740
797
- if(unlikely(hash == total_dirty_hash && !strcmp(s, "total_dirty"))) {
798
- mem->total_dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
799
- continue;
800
- }
741
+ else if(unlikely(hash == total_dirty_hash && !strcmp(s, "total_dirty")))
742
+ mem->total_dirty = str2ull(procfile_lineword(ff, i, 1));
743
802
- if(unlikely(hash == total_swap_hash && !strcmp(s, "total_swap"))) {
803
- mem->total_swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
804
- continue;
805
- }
744
+ else if(unlikely(hash == total_swap_hash && !strcmp(s, "total_swap")))
745
+ mem->total_swap = str2ull(procfile_lineword(ff, i, 1));
746
807
- if(unlikely(hash == total_pgpgin_hash && !strcmp(s, "total_pgpgin"))) {
808
- mem->total_pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
809
- continue;
810
- }
747
+ else if(unlikely(hash == total_pgpgin_hash && !strcmp(s, "total_pgpgin")))
748
+ mem->total_pgpgin = str2ull(procfile_lineword(ff, i, 1), NULL, 10);
749
812
- if(unlikely(hash == total_pgpgout_hash && !strcmp(s, "total_pgpgout"))) {
813
- mem->total_pgpgout = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
814
- continue;
815
- }
750
+ else if(unlikely(hash == total_pgpgout_hash && !strcmp(s, "total_pgpgout")))
751
+ mem->total_pgpgout = str2ull(procfile_lineword(ff, i, 1));
752
817
- if(unlikely(hash == total_pgfault_hash && !strcmp(s, "total_pgfault"))) {
818
- mem->total_pgfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
819
- continue;
820
- }
753
+ else if(unlikely(hash == total_pgfault_hash && !strcmp(s, "total_pgfault")))
754
+ mem->total_pgfault = str2ull(procfile_lineword(ff, i, 1));
755
822
- if(unlikely(hash == total_pgmajfault_hash && !strcmp(s, "total_pgmajfault"))) {
823
- mem->total_pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
824
- continue;
825
- }
756
+ else if(unlikely(hash == total_pgmajfault_hash && !strcmp(s, "total_pgmajfault")))
757
+ mem->total_pgmajfault = str2ull(procfile_lineword(ff, i, 1));
758
827
- if(unlikely(hash == total_inactive_anon_hash && !strcmp(s, "total_inactive_anon"))) {
828
- mem->total_inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
829
- continue;
830
- }
759
+ else if(unlikely(hash == total_inactive_anon_hash && !strcmp(s, "total_inactive_anon")))
760
+ mem->total_inactive_anon = str2ull(procfile_lineword(ff, i, 1));
761
832
- if(unlikely(hash == total_active_anon_hash && !strcmp(s, "total_active_anon"))) {
833
- mem->total_active_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
834
- continue;
835
- }
762
+ else if(unlikely(hash == total_active_anon_hash && !strcmp(s, "total_active_anon")))
763
+ mem->total_active_anon = str2ull(procfile_lineword(ff, i, 1));
764
837
- if(unlikely(hash == total_inactive_file_hash && !strcmp(s, "total_inactive_file"))) {
838
- mem->total_inactive_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
839
- continue;
840
- }
765
+ else if(unlikely(hash == total_inactive_file_hash && !strcmp(s, "total_inactive_file")))
766
+ mem->total_inactive_file = str2ull(procfile_lineword(ff, i, 1));
767
842
- if(unlikely(hash == total_active_file_hash && !strcmp(s, "total_active_file"))) {
843
- mem->total_active_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
844
- continue;
845
- }
768
+ else if(unlikely(hash == total_active_file_hash && !strcmp(s, "total_active_file")))
769
+ mem->total_active_file = str2ull(procfile_lineword(ff, i, 1));
770
847
- if(unlikely(hash == total_unevictable_hash && !strcmp(s, "total_unevictable"))) {
848
- mem->total_unevictable = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
849
- continue;
850
- }
771
+ else if(unlikely(hash == total_unevictable_hash && !strcmp(s, "total_unevictable")))
772
+ mem->total_unevictable = str2ull(procfile_lineword(ff, i, 1));
773
*/
774
}
775