diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-04-30 23:55:57 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-05 16:22:47 +0200 |
commit | 1ca194d352688224d26755a0edebbab6a1841ad9 (patch) | |
tree | 3bb83d7d6bc3cc9c117757431256a6e11976d180 | |
parent | c5eeda8be950fa638beb9eec196b6d1e8fec746a (diff) |
Use Nanosecond precision by default
This is the default precision returned by the kernel
when calling get_clocktime(), so this avoid useless
division to get a less precise time. Also signaling
event should have this kind of precision to be able
to correctly debugging system on signals heavy load.
Change-Id: I010b98305cff7387787fd8f8a1e8a0f9107a170a
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | signal-composer-binding/signal.cpp | 31 | ||||
-rw-r--r-- | signal-composer-binding/signal.hpp | 2 |
2 files changed, 21 insertions, 12 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp index 3643527..0b17091 100644 --- a/signal-composer-binding/signal.cpp +++ b/signal-composer-binding/signal.cpp @@ -281,16 +281,25 @@ void Signal::defaultReceivedCB(json_object *eventJ) if (key.find("value") != std::string::npos || key.find(id_) != std::string::npos) { - if(json_object_is_type(value, json_type_double)) - {sv = json_object_get_double(value);} - else if(json_object_is_type(value, json_type_boolean)) - {sv = json_object_get_int(value);} - else if(json_object_is_type(value, json_type_string)) - {sv = json_object_get_string(value);} + switch(json_object_get_type(value)) { + case json_type_double: { + sv = json_object_get_double(value); + break; + } + case json_type_boolean: { + sv = json_object_get_int(value); + break; + } + case json_type_string: { + sv = json_object_get_string(value); + break; + } + } } else if (key.find("timestamp") != std::string::npos) { ts = json_object_is_type(value, json_type_int) ? json_object_get_int64(value):ts; + ts = json_object_is_type(value, json_type_double) ? (uint64_t)json_object_get_double(value) * NANO : ts; } json_object_iter_next(&iter); } @@ -305,7 +314,7 @@ void Signal::defaultReceivedCB(json_object *eventJ) struct timespec t; if(!::clock_gettime(CLOCK_REALTIME, &t)) - ts = (uint64_t)(t.tv_sec) * (uint64_t)1000000 + ((uint64_t)(t.tv_nsec) / 1000); + ts = (uint64_t)(t.tv_sec) * (uint64_t)NANO + (uint64_t)(t.tv_nsec); } set(ts, sv); @@ -329,7 +338,7 @@ void Signal::onReceivedCB(json_object *eventJ) if(json_object_is_type(value, json_type_int)) { int64_t newVal = json_object_get_int64(value); - newVal = newVal > USEC_TIMESTAMP_FLAG ? newVal/MICRO:newVal; + newVal = newVal > USEC_TIMESTAMP_FLAG ? newVal/NANO:newVal; json_object_object_del(eventJ, name); json_object* luaVal = json_object_new_int64(newVal); json_object_object_add(eventJ, name, luaVal); @@ -378,7 +387,7 @@ double Signal::average(int seconds) const { uint64_t begin = history_.begin()->first; uint64_t end = seconds ? - begin+(seconds*MICRO) : + begin+(seconds*NANO) : history_.rbegin()->first; double total = 0.0; int nbElt = 0; @@ -415,7 +424,7 @@ double Signal::minimum(int seconds) const { uint64_t begin = history_.begin()->first; uint64_t end = seconds ? - begin+(seconds*MICRO) : + begin+(seconds*NANO) : history_.rbegin()->first; double min = DBL_MAX; @@ -447,7 +456,7 @@ double Signal::maximum(int seconds) const { uint64_t begin = history_.begin()->first; uint64_t end = seconds ? - begin+(seconds*MICRO) : + begin+(seconds*NANO) : history_.rbegin()->first; double max = 0.0; diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp index 815c7d9..091d060 100644 --- a/signal-composer-binding/signal.hpp +++ b/signal-composer-binding/signal.hpp @@ -24,7 +24,7 @@ #include "observer-pattern.hpp" -#define MICRO 1000000 +#define NANO 1000000000 class Composer; |