Add 'xxx_reporting_period' config options 89/248589/3
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Mon, 30 Nov 2020 09:04:46 +0000 (10:04 +0100)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Mon, 30 Nov 2020 11:41:44 +0000 (12:41 +0100)
Added four new config options:
- cpu_reporting_period
- mem_reporting_period
- io_reporting_period
- fd_reporting_period

-1 means to report only once
value >= 0 denotes minimum period of time (seconds)
between reports

Change-Id: Ia63483bca90864ec5cc7f0c2295c4c8d60d991d8

config/default.conf
src/data_source.h
src/data_sources/tsm_cpu.c
src/data_sources/tsm_fd.c
src/data_sources/tsm_io.c
src/data_sources/tsm_mem.c
src/process.c

index 195a9df..a9b4d53 100644 (file)
@@ -9,16 +9,20 @@
         "cpu_limit_avg": 4,
         "cpu_avg_period": 10,
         "cpu_limit_peak": 4,
+        "cpu_reporting_period": 20,
 
         "mem_limit_avg": 1,
         "mem_avg_period": 10,
         "mem_limit_peak": 1,
+        "mem_reporting_period": 20,
 
         "io_limit_avg": 100.0,
         "io_avg_period": 10,
         "io_limit_peak": 100.0,
+        "io_reporting_period": 20,
 
         "fd_limit": 1000,
+        "fd_reporting_period": 60,
     },
 
 
index 69257e0..27809ee 100644 (file)
@@ -43,6 +43,8 @@ struct data_source {
     void                  *extra_data;
 
     int                   action_in_progress;
+    int                   reporting_period;     /* seconds */
+    unsigned long long    last_report_time;
 
     int (*update)(struct data_source *ds,
                   struct raw_data_item *rd_global,
index 3d972eb..92cac5e 100644 (file)
@@ -96,6 +96,11 @@ static int apply_config(struct data_source *ds, char *key, struct json_object *v
         return 0;
     }
 
+    if (strcmp(key, "cpu_reporting_period") == 0) {
+        ds->reporting_period = json_object_get_int(val);
+        return 0;
+    }
+
     return -1;
 }
 
index 665b587..9ba8417 100644 (file)
@@ -55,6 +55,11 @@ static int apply_config(struct data_source *ds, char *key, struct json_object *v
         return 0;
     }
 
+    if (strcmp(key, "fd_reporting_period") == 0) {
+        ds->reporting_period = json_object_get_int(val);
+        return 0;
+    }
+
     return -1;
 }
 
index f2e5819..40e2f7e 100644 (file)
@@ -93,6 +93,11 @@ static int apply_config(struct data_source *ds, char *key, struct json_object *v
         return 0;
     }
 
+    if (strcmp(key, "io_reporting_period") == 0) {
+        ds->reporting_period = json_object_get_int(val);
+        return 0;
+    }
+
     return -1;
 }
 
index 287d23f..7fbde5a 100644 (file)
@@ -68,6 +68,11 @@ static int apply_config(struct data_source *ds, char *key, struct json_object *v
         return 0;
     }
 
+    if (strcmp(key, "mem_reporting_period") == 0) {
+        ds->reporting_period = json_object_get_int(val);
+        return 0;
+    }
+
     return -1;
 }
 
index e6f9001..cf6b183 100644 (file)
@@ -392,6 +392,18 @@ const char *process_class_to_string(int class)
     }
 }
 
+static void _run_action(struct data_source *ds, enum limit_type lt)
+{
+    unsigned long long t = time_now();
+
+    if ((ds->reporting_period < 0 && ds->last_report_time == 0) ||
+        (ds->reporting_period >= 0 && t - ds->last_report_time > ds->reporting_period * USEC_PER_SEC)) {
+
+        ds->action(ds, lt);
+        ds->last_report_time = t;
+    }
+}
+
 void process_check_limits(struct proc_info *process)
 {
     struct data_source *ds;
@@ -411,16 +423,14 @@ void process_check_limits(struct proc_info *process)
         if (sample_is_greater(last_sample, &ds->limit.peak)) {
             _I_PROC(process, "%s: PEAK limit exceeded (%s)",
                              ds->name, smpl2str(last_sample));
-
-            ds->action(ds, LIMIT_TYPE_PEAK);
+            _run_action(ds, LIMIT_TYPE_PEAK);
         }
 
         /* Avg limit */
         if (sc->average > ds->limit.avg) {
             _I_PROC(process, "%s: AVG limit exceeded (%2.3lf)",
                              ds->name, sc->average);
-
-            ds->action(ds, LIMIT_TYPE_AVG);
+            _run_action(ds, LIMIT_TYPE_AVG);
         }
     }
 }