prevent apps.plugin normalization under freebsd
Costa Tsaousis (ktsaou) committed
Mar 31, 2017 at 01:11 UTC
14852db7bd2e218ddabdc84149c4721038636f92
1 file changed
+32
-41
src/apps_plugin.c
+32
-41
@@ -109,6 +109,7 @@ static size_t
109
// metric.
110
111
// the total system time, as reported by /proc/stat
112
+#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
113
static kernel_uint_t
114
global_utime = 0,
115
global_stime = 0,
@@ -126,7 +127,7 @@ double utime_fix_ratio = 1.0,
127
cgtime_fix_ratio = 1.0,
128
cminflt_fix_ratio = 1.0,
129
cmajflt_fix_ratio = 1.0;
129
-
130
+#endif
131
132
// ----------------------------------------------------------------------------
133
// target
@@ -1157,24 +1158,13 @@ cleanup:
1158
#endif
1159
}
1160
1161
+#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
1162
static inline int read_proc_stat() {
1161
-#ifdef __FreeBSD__
1162
- long cp_time[CPUSTATES];
1163
- static kernel_uint_t utime_raw = 0, stime_raw = 0, ntime_raw = 0;
1164
-
1165
- if (unlikely(CPUSTATES != 5)) {
1166
- error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES);
1167
- goto cleanup;
1168
- }
1169
- if (unlikely(GETSYSCTL_BY_NAME("kern.cp_time", cp_time))) goto cleanup;
1170
-#else
1163
static char filename[FILENAME_MAX + 1] = "";
1164
static procfile *ff = NULL;
1165
static kernel_uint_t utime_raw = 0, stime_raw = 0, gtime_raw = 0, gntime_raw = 0, ntime_raw = 0;
1174
-#endif
1166
static usec_t collected_usec = 0, last_collected_usec = 0;
1167
1177
-#ifndef __FreeBSD__
1168
if(unlikely(!ff)) {
1169
snprintfz(filename, FILENAME_MAX, "%s/proc/stat", netdata_configured_host_prefix);
1170
ff = procfile_open(filename, " \t:", PROCFILE_FLAG_DEFAULT);
@@ -1183,7 +1173,6 @@ static inline int read_proc_stat() {
1173
1174
ff = procfile_readall(ff);
1175
if(unlikely(!ff)) goto cleanup;
1186
-#endif
1176
1177
last_collected_usec = collected_usec;
1178
collected_usec = now_monotonic_usec();
@@ -1193,25 +1182,13 @@ static inline int read_proc_stat() {
1182
// temporary - it is added global_ntime;
1183
kernel_uint_t global_ntime = 0;
1184
1196
-#ifdef __FreeBSD__
1197
- incremental_rate(global_utime, utime_raw, cp_time[0], collected_usec, last_collected_usec);
1198
- incremental_rate(global_ntime, ntime_raw, cp_time[1], collected_usec, last_collected_usec);
1199
- incremental_rate(global_stime, stime_raw, cp_time[2], collected_usec, last_collected_usec);
1200
-#else
1185
incremental_rate(global_utime, utime_raw, str2kernel_uint_t(procfile_lineword(ff, 0, 1)), collected_usec, last_collected_usec);
1186
incremental_rate(global_ntime, ntime_raw, str2kernel_uint_t(procfile_lineword(ff, 0, 2)), collected_usec, last_collected_usec);
1187
incremental_rate(global_stime, stime_raw, str2kernel_uint_t(procfile_lineword(ff, 0, 3)), collected_usec, last_collected_usec);
1188
incremental_rate(global_gtime, gtime_raw, str2kernel_uint_t(procfile_lineword(ff, 0, 10)), collected_usec, last_collected_usec);
1205
-#endif
1189
1190
global_utime += global_ntime;
1191
1209
-#ifdef __FreeBSD__
1210
- if(enable_guest_charts) {
1211
- enable_guest_charts = 0;
1212
- info("Guest charts aren't supported by FreeBSD");
1213
- }
1214
-#else
1192
if(enable_guest_charts) {
1193
// temporary - it is added global_ntime;
1194
kernel_uint_t global_gntime = 0;
@@ -1224,7 +1201,6 @@ static inline int read_proc_stat() {
1201
// remove guest time from user time
1202
global_utime -= (global_utime > global_gtime) ? global_gtime : global_utime;
1203
}
1227
-#endif
1204
1205
if(unlikely(global_iterations_counter == 1)) {
1206
global_utime = 0;
@@ -1240,7 +1216,11 @@ cleanup:
1216
global_gtime = 0;
1217
return 0;
1218
}
1243
-
1219
+#else
1220
+static inline int read_proc_stat() {
1221
+ return 0;
1222
+}
1223
+#endif
1224
1225
// ----------------------------------------------------------------------------
1226
@@ -2705,13 +2685,6 @@ static usec_t send_resource_usage_to_netdata() {
2685
"SET targets = %zu\n"
2686
"SET new_pids = %zu\n"
2687
"END\n"
2708
- "BEGIN netdata.apps_fix %llu\n"
2709
- "SET utime = %u\n"
2710
- "SET stime = %u\n"
2711
- "SET gtime = %u\n"
2712
- "SET minflt = %u\n"
2713
- "SET majflt = %u\n"
2714
- "END\n"
2688
, usec
2689
, cpuuser
2690
, cpusyst
@@ -2722,14 +2695,25 @@ static usec_t send_resource_usage_to_netdata() {
2695
, all_files_len
2696
, apps_groups_targets_count
2697
, targets_assignment_counter
2725
- , usec
2726
- , (unsigned int)(utime_fix_ratio * 100 * RATES_DETAIL)
2727
- , (unsigned int)(stime_fix_ratio * 100 * RATES_DETAIL)
2728
- , (unsigned int)(gtime_fix_ratio * 100 * RATES_DETAIL)
2729
- , (unsigned int)(minflt_fix_ratio * 100 * RATES_DETAIL)
2730
- , (unsigned int)(majflt_fix_ratio * 100 * RATES_DETAIL)
2698
);
2699
2700
+#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
2701
+ fprintf(stdout,
2702
+ "BEGIN netdata.apps_fix %llu\n"
2703
+ "SET utime = %u\n"
2704
+ "SET stime = %u\n"
2705
+ "SET gtime = %u\n"
2706
+ "SET minflt = %u\n"
2707
+ "SET majflt = %u\n"
2708
+ "END\n"
2709
+ , usec
2710
+ , (unsigned int)(utime_fix_ratio * 100 * RATES_DETAIL)
2711
+ , (unsigned int)(stime_fix_ratio * 100 * RATES_DETAIL)
2712
+ , (unsigned int)(gtime_fix_ratio * 100 * RATES_DETAIL)
2713
+ , (unsigned int)(minflt_fix_ratio * 100 * RATES_DETAIL)
2714
+ , (unsigned int)(majflt_fix_ratio * 100 * RATES_DETAIL)
2715
+ );
2716
+
2717
if(include_exited_childs)
2718
fprintf(stdout,
2719
"BEGIN netdata.apps_children_fix %llu\n"
@@ -2746,10 +2730,12 @@ static usec_t send_resource_usage_to_netdata() {
2730
, (unsigned int)(cminflt_fix_ratio * 100 * RATES_DETAIL)
2731
, (unsigned int)(cmajflt_fix_ratio * 100 * RATES_DETAIL)
2732
);
2733
+#endif
2734
2735
return usec;
2736
}
2737
2738
+#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
2739
static void normalize_utilization(struct target *root) {
2740
struct target *w;
2741
@@ -2895,6 +2881,11 @@ static void normalize_utilization(struct target *root) {
2881
);
2882
}
2883
}
2884
+#else // ALL_PIDS_ARE_READ_INSTANTLY == 1
2885
+static void normalize_utilization(struct target *root) {
2886
+ (void)root;
2887
+}
2888
+#endif // ALL_PIDS_ARE_READ_INSTANTLY
2889
2890
static void send_collected_data_to_netdata(struct target *root, const char *type, usec_t usec) {
2891
struct target *w;