Add some sanity checks in data source modules
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Tue, 25 Jun 2019 06:32:55 +0000 (08:32 +0200)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Thu, 27 Jun 2019 11:38:14 +0000 (13:38 +0200)
Change-Id: Idd6da9f0b1cdb9e6a81e75c397571fdbc3b26978

src/data_sources/tsm_cpu.c
src/data_sources/tsm_io.c

index 528a218..2e866fa 100644 (file)
@@ -62,6 +62,11 @@ static int update(struct data_source *ds,
         return 0;
     }
 
+    if (ced->cpu_time < ced->cpu_time_last) {
+        _D_PROC(ds->process, "cpu_time < cpu_time_last, ignoring sample");
+        return 0;
+    }
+
     cpu_usage = (double) (ced->cpu_time - ced->cpu_time_last) / (ced->measure_time - ced->measure_time_last);
 
     ret = data_source_add_sample(ds, ST_DOUBLE, &cpu_usage, rd_global->v[0]);
index 827add6..1f80786 100644 (file)
@@ -58,6 +58,11 @@ static int update(struct data_source *ds,
         return 0;
     }
 
+    if (ied->io_bytes < ied->io_bytes_last) {
+        _D_PROC(ds->process, "io_bytes < io_bytes_last, ignoring sample");
+        return 0;
+    }
+
     io_rate = (double) (ied->io_bytes - ied->io_bytes_last) /
               (ied->measure_time - ied->measure_time_last);