You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/05/19 22:00:23 UTC

[09/12] incubator-mynewt-core git commit: Making indices secondary keys for log entries

Making indices secondary keys for log entries

- Making indices secondary keys for log entries
- Resetting indices every millisecond since the last entry


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d3212db3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d3212db3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d3212db3

Branch: refs/heads/develop
Commit: d3212db3966612be725d1693014616e09ce5d00e
Parents: d890f70
Author: Vipul Rahane <vi...@runtime.io>
Authored: Mon May 9 16:28:28 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Tue May 17 12:31:54 2016 -0700

----------------------------------------------------------------------
 sys/log/include/log/log.h |  7 ++++++-
 sys/log/src/log.c         | 15 +++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d3212db3/sys/log/include/log/log.h
----------------------------------------------------------------------
diff --git a/sys/log/include/log/log.h b/sys/log/include/log/log.h
index 07c672c..33fcba3 100644
--- a/sys/log/include/log/log.h
+++ b/sys/log/include/log/log.h
@@ -24,6 +24,12 @@
 
 #include <os/queue.h>
 
+/* Global log info */
+struct log_info {
+    int64_t li_timestamp;
+    uint8_t li_index;
+}g_log_info;
+
 struct log;
 
 typedef int (*log_walk_func_t)(struct log *, void *arg, void *offset,
@@ -139,7 +145,6 @@ struct log_entry_hdr {
 struct log {
     char *l_name;
     struct log_handler *l_log;
-    uint8_t l_index;
     STAILQ_ENTRY(log) l_next;
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d3212db3/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log.c b/sys/log/src/log.c
index fe22fd6..484c8c8 100644
--- a/sys/log/src/log.c
+++ b/sys/log/src/log.c
@@ -103,10 +103,15 @@ log_append(struct log *log, uint16_t module, uint16_t level, void *data,
     int rc;
     struct os_timeval tv;
 
-    log->l_index++;
-
     ue = (struct log_entry_hdr *) data;
 
+    /* Resetting index every millisecond */
+    if (g_log_info.li_timestamp > ue->ue_ts + 1000) {
+        g_log_info.li_index = 0;
+    }
+
+    g_log_info.li_index++;
+
     /* Try to get UTC Time */
     rc = os_gettimeofday(&tv, NULL);
     if (rc || tv.tv_sec < UTC01_01_2016) {
@@ -114,9 +119,11 @@ log_append(struct log *log, uint16_t module, uint16_t level, void *data,
     } else {
         ue->ue_ts = tv.tv_sec * 1000000 + tv.tv_usec;
     }
+
+    g_log_info.li_timestamp = ue->ue_ts;
     ue->ue_level = level;
     ue->ue_module = module;
-    ue->ue_index = log->l_index;
+    ue->ue_index = g_log_info.li_index;
 
     rc = log->l_log->log_append(log, data, len + LOG_ENTRY_HDR_SIZE);
     if (rc != 0) {
@@ -182,7 +189,7 @@ log_flush(struct log *log)
         goto err;
     }
 
-    log->l_index = 0;
+    g_log_info.li_index = 0;
 
     return (0);
 err: