You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/04/14 03:36:58 UTC

[1/2] incubator-mynewt-core git commit: Log changes

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop a04dba6a5 -> 226c23d1f


Log changes

- Adding/Changing fields(msg, ts, entries) to log entries
- Fixing json encode for 64 bit data types
- Adding os_time function to get uptime in microsenconds
- Changing json responses to contain multiple log entries
(Also addressing comments on github)
- Changing log_index to l_index and removing log_level from teh log
  structure since it's not needed.


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/4b19a7ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4b19a7ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4b19a7ac

Branch: refs/heads/develop
Commit: 4b19a7acef533d3f1c83a548eb6b7c12d446367f
Parents: a04dba6
Author: Vipul Rahane <vi...@runtime.io>
Authored: Wed Apr 13 12:16:10 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Wed Apr 13 17:52:57 2016 -0700

----------------------------------------------------------------------
 libs/baselibc/src/tinyprintf.c | 16 ++++++++--------
 libs/json/src/json_encode.c    |  8 ++++----
 libs/os/include/os/os_time.h   |  1 +
 libs/os/src/os_time.c          | 28 ++++++++++++++++++++++++----
 sys/log/include/log/log.h      | 10 +++++++---
 sys/log/src/log.c              | 36 +++++++++++++++++++++++++-----------
 sys/log/src/log_cbmem.c        | 25 ++++++++++++-------------
 sys/log/src/log_nmgr.c         | 29 +++++++++++++++++++++++++++--
 8 files changed, 108 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b19a7ac/libs/baselibc/src/tinyprintf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/tinyprintf.c b/libs/baselibc/src/tinyprintf.c
index 3ac333e..01fa4fb 100644
--- a/libs/baselibc/src/tinyprintf.c
+++ b/libs/baselibc/src/tinyprintf.c
@@ -103,15 +103,15 @@ static void li2a(long num, struct param *p)
 }
 #endif
 
-static void ui2a(unsigned int num, struct param *p)
+static void ui2a(unsigned long long int num, struct param *p)
 {
     int n = 0;
-    unsigned int d = 1;
+    unsigned long long int d = 1;
     char *bf = p->bf;
     while (num / d >= p->base)
         d *= p->base;
     while (d != 0) {
-        int dgt = num / d;
+        unsigned long long  dgt = num / d;
         num %= d;
         d /= p->base;
         if (n || dgt > 0 || d == 0) {
@@ -122,7 +122,7 @@ static void ui2a(unsigned int num, struct param *p)
     *bf = 0;
 }
 
-static void i2a(int num, struct param *p)
+static void i2a(long long int num, struct param *p)
 {
     if (num < 0) {
         num = -num;
@@ -282,7 +282,7 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va)
                     uli2a(va_arg(va, unsigned long int), &p);
                 else
 #endif
-                    ui2a(va_arg(va, unsigned int), &p);
+                    ui2a(va_arg(va, unsigned long long int), &p);
                 written += putchw(putp, &p);
                 break;
             case 'd':
@@ -293,7 +293,7 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va)
                     li2a(va_arg(va, unsigned long int), &p);
                 else
 #endif
-                    i2a(va_arg(va, int), &p);
+                    i2a(va_arg(va, long long int), &p);
                 written += putchw(putp, &p);
                 break;
             case 'x':
@@ -305,12 +305,12 @@ size_t tfp_format(FILE *putp, const char *fmt, va_list va)
                     uli2a(va_arg(va, unsigned long int), &p);
                 else
 #endif
-                    ui2a(va_arg(va, unsigned int), &p);
+                    ui2a(va_arg(va, unsigned long long int), &p);
                 written += putchw(putp, &p);
                 break;
             case 'o':
                 p.base = 8;
-                ui2a(va_arg(va, unsigned int), &p);
+                ui2a(va_arg(va, unsigned long long int), &p);
                 written += putchw(putp, &p);
                 break;
             case 'c':

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b19a7ac/libs/json/src/json_encode.c
----------------------------------------------------------------------
diff --git a/libs/json/src/json_encode.c b/libs/json/src/json_encode.c
index 5a16911..cddca31 100644
--- a/libs/json/src/json_encode.c
+++ b/libs/json/src/json_encode.c
@@ -62,13 +62,13 @@ json_encode_value(struct json_encoder *encoder, struct json_value *jv)
             encoder->je_write(encoder->je_arg, encoder->je_encode_buf, len);
             break;
         case JSON_VALUE_TYPE_UINT64:
-            len = sprintf(encoder->je_encode_buf, "%lu",
-                    (unsigned long)jv->jv_val.u);
+            len = sprintf(encoder->je_encode_buf, "%llu",
+                    jv->jv_val.u);
             encoder->je_write(encoder->je_arg, encoder->je_encode_buf, len);
             break;
         case JSON_VALUE_TYPE_INT64:
-            len = sprintf(encoder->je_encode_buf, "%ld",
-                    (long) jv->jv_val.u);
+            len = sprintf(encoder->je_encode_buf, "%lld",
+                    jv->jv_val.u);
             encoder->je_write(encoder->je_arg, encoder->je_encode_buf, len);
             break;
         case JSON_VALUE_TYPE_STRING:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b19a7ac/libs/os/include/os/os_time.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_time.h b/libs/os/include/os/os_time.h
index c187112..215d74c 100644
--- a/libs/os/include/os/os_time.h
+++ b/libs/os/include/os/os_time.h
@@ -104,5 +104,6 @@ struct os_timezone {
 
 int os_settimeofday(struct os_timeval *utctime, struct os_timezone *tz);
 int os_gettimeofday(struct os_timeval *utctime, struct os_timezone *tz);
+int64_t os_get_uptime_usec(void);
 
 #endif /* _OS_TIME_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b19a7ac/libs/os/src/os_time.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_time.c b/libs/os/src/os_time.c
index 7b2f310..a92e9a9 100644
--- a/libs/os/src/os_time.c
+++ b/libs/os/src/os_time.c
@@ -50,7 +50,7 @@ os_deltatime(os_time_t delta, const struct os_timeval *base,
     os_timeradd(base, &tvdelta, result);
 }
 
-os_time_t  
+os_time_t
 os_time_get(void)
 {
     return (g_os_time);
@@ -95,9 +95,9 @@ os_time_advance(int ticks)
 }
 
 /**
- * Puts the current task to sleep for the specified number of os ticks. There 
- * is no delay if ticks is <= 0. 
- * 
+ * Puts the current task to sleep for the specified number of os ticks. There
+ * is no delay if ticks is <= 0.
+ *
  * @param osticks Number of ticks to delay (<= 0 means no delay).
  */
 void
@@ -157,3 +157,23 @@ os_gettimeofday(struct os_timeval *tv, struct os_timezone *tz)
 
     return (0);
 }
+
+int64_t
+os_get_uptime_usec(void) 
+{
+  struct os_timeval tv;
+  os_time_t delta;
+  os_sr_t sr;
+  os_time_t ostime;
+
+
+  OS_ENTER_CRITICAL(sr);
+  tv = basetod.uptime;
+  ostime = basetod.ostime;
+  delta = os_time_get() - ostime;
+  OS_EXIT_CRITICAL(sr);
+
+  os_deltatime(delta, &tv, &tv);
+
+  return(tv.tv_sec * 1000000 + tv.tv_usec);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b19a7ac/sys/log/include/log/log.h
----------------------------------------------------------------------
diff --git a/sys/log/include/log/log.h b/sys/log/include/log/log.h
index df5ae90..6109477 100644
--- a/sys/log/include/log/log.h
+++ b/sys/log/include/log/log.h
@@ -51,9 +51,10 @@ struct log_handler {
 
 struct log_entry_hdr {
     int64_t ue_ts;
-    uint16_t ue_level;
     uint16_t ue_module;
-};
+    uint8_t ue_index;
+    uint8_t ue_level;
+}__attribute__((__packed__));
 #define LOG_ENTRY_HDR_SIZE (sizeof(struct log_entry_hdr))
 
 #define LOG_LEVEL_DEBUG    (0x01)
@@ -73,6 +74,9 @@ struct log_entry_hdr {
 #define LOG_MODULE_NFFS             (5)
 #define LOG_MODULE_PERUSER          (64)
 
+/* UTC Timestamnp for Jan 2016 00:00:00 */
+#define UTC01_01_2016    1451606400
+
 /* Compile in Log Debug by default */
 #ifndef LOG_LEVEL
 #define LOG_LEVEL LOG_LEVEL_DEBUG
@@ -116,7 +120,7 @@ struct log_entry_hdr {
 struct log {
     char *l_name;
     struct log_handler *l_log;
-    uint16_t log_level;
+    uint8_t l_index;
     STAILQ_ENTRY(log) l_next;
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b19a7ac/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log.c b/sys/log/src/log.c
index d957768..fe22fd6 100644
--- a/sys/log/src/log.c
+++ b/sys/log/src/log.c
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -18,6 +18,7 @@
  */
 
 #include <os/os.h>
+#include "os/os_time.h"
 
 #include <string.h>
 
@@ -83,7 +84,7 @@ log_list_get_next(struct log *log)
     return (next);
 }
 
-int 
+int
 log_register(char *name, struct log *log, struct log_handler *lh)
 {
     log->l_name = name;
@@ -95,16 +96,27 @@ log_register(char *name, struct log *log, struct log_handler *lh)
 }
 
 int
-log_append(struct log *log, uint16_t module, uint16_t level, void *data, 
+log_append(struct log *log, uint16_t module, uint16_t level, void *data,
         uint16_t len)
 {
     struct log_entry_hdr *ue;
     int rc;
+    struct os_timeval tv;
+
+    log->l_index++;
 
     ue = (struct log_entry_hdr *) data;
-    ue->ue_ts = (int64_t) os_time_get();
+
+    /* Try to get UTC Time */
+    rc = os_gettimeofday(&tv, NULL);
+    if (rc || tv.tv_sec < UTC01_01_2016) {
+        ue->ue_ts = os_get_uptime_usec();
+    } else {
+        ue->ue_ts = tv.tv_sec * 1000000 + tv.tv_usec;
+    }
     ue->ue_level = level;
     ue->ue_module = module;
+    ue->ue_index = log->l_index;
 
     rc = log->l_log->log_append(log, data, len + LOG_ENTRY_HDR_SIZE);
     if (rc != 0) {
@@ -116,7 +128,7 @@ err:
     return (rc);
 }
 
-void 
+void
 log_printf(struct log *log, uint16_t module, uint16_t level, char *msg,
         ...)
 {
@@ -125,7 +137,7 @@ log_printf(struct log *log, uint16_t module, uint16_t level, char *msg,
     int len;
 
     va_start(args, msg);
-    len = vsnprintf(&buf[LOG_ENTRY_HDR_SIZE], LOG_PRINTF_MAX_ENTRY_LEN, msg, 
+    len = vsnprintf(&buf[LOG_ENTRY_HDR_SIZE], LOG_PRINTF_MAX_ENTRY_LEN, msg,
             args);
     if (len >= LOG_PRINTF_MAX_ENTRY_LEN) {
         len = LOG_PRINTF_MAX_ENTRY_LEN-1;
@@ -134,7 +146,7 @@ log_printf(struct log *log, uint16_t module, uint16_t level, char *msg,
     log_append(log, module, level, (uint8_t *) buf, len);
 }
 
-int 
+int
 log_walk(struct log *log, log_walk_func_t walk_func, void *arg)
 {
     int rc;
@@ -149,8 +161,8 @@ err:
     return (rc);
 }
 
-int 
-log_read(struct log *log, void *dptr, void *buf, uint16_t off, 
+int
+log_read(struct log *log, void *dptr, void *buf, uint16_t off,
         uint16_t len)
 {
     int rc;
@@ -160,7 +172,7 @@ log_read(struct log *log, void *dptr, void *buf, uint16_t off,
     return (rc);
 }
 
-int 
+int
 log_flush(struct log *log)
 {
     int rc;
@@ -168,7 +180,9 @@ log_flush(struct log *log)
     rc = log->l_log->log_flush(log);
     if (rc != 0) {
         goto err;
-    } 
+    }
+
+    log->l_index = 0;
 
     return (0);
 err:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b19a7ac/sys/log/src/log_cbmem.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_cbmem.c b/sys/log/src/log_cbmem.c
index 8b732f3..da5d747 100644
--- a/sys/log/src/log_cbmem.c
+++ b/sys/log/src/log_cbmem.c
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -24,8 +24,8 @@
 #include "log/log.h"
 
 
-static int 
-log_cbmem_append(struct log *log, void *buf, int len) 
+static int
+log_cbmem_append(struct log *log, void *buf, int len)
 {
     struct cbmem *cbmem;
     int rc;
@@ -42,9 +42,9 @@ err:
     return (rc);
 }
 
-static int 
-log_cbmem_read(struct log *log, void *dptr, void *buf, uint16_t offset, 
-        uint16_t len) 
+static int
+log_cbmem_read(struct log *log, void *dptr, void *buf, uint16_t offset,
+        uint16_t len)
 {
     struct cbmem *cbmem;
     struct cbmem_entry_hdr *hdr;
@@ -58,7 +58,7 @@ log_cbmem_read(struct log *log, void *dptr, void *buf, uint16_t offset,
     return (rc);
 }
 
-static int 
+static int
 log_cbmem_walk(struct log *log, log_walk_func_t walk_func, void *arg)
 {
     struct cbmem *cbmem;
@@ -72,7 +72,7 @@ log_cbmem_walk(struct log *log, log_walk_func_t walk_func, void *arg)
     if (rc != 0) {
         goto err;
     }
-    
+
     cbmem_iter_start(cbmem, &iter);
     while (1) {
         hdr = cbmem_iter_next(cbmem, &iter);
@@ -80,7 +80,7 @@ log_cbmem_walk(struct log *log, log_walk_func_t walk_func, void *arg)
             break;
         }
 
-        rc = walk_func(log, arg, (void *) hdr, hdr->ceh_len);
+        rc = walk_func(log, arg, (void *)hdr, hdr->ceh_len);
         if (rc == 1) {
             break;
         }
@@ -96,14 +96,14 @@ err:
     return (rc);
 }
 
-static int 
+static int
 log_cbmem_flush(struct log *log)
 {
     struct cbmem *cbmem;
     int rc;
 
     cbmem = (struct cbmem *) log->l_log->log_arg;
-    
+
     rc = cbmem_flush(cbmem);
     if (rc != 0) {
         goto err;
@@ -114,7 +114,7 @@ err:
     return (rc);
 }
 
-int 
+int
 log_cbmem_handler_init(struct log_handler *handler, struct cbmem *cbmem)
 {
     handler->log_type = LOG_TYPE_MEMORY;
@@ -126,4 +126,3 @@ log_cbmem_handler_init(struct log_handler *handler, struct cbmem *cbmem)
 
     return (0);
 }
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4b19a7ac/sys/log/src/log_nmgr.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_nmgr.c b/sys/log/src/log_nmgr.c
index 39bde0d..03ad16a 100644
--- a/sys/log/src/log_nmgr.c
+++ b/sys/log/src/log_nmgr.c
@@ -76,17 +76,29 @@ log_nmgr_add_entry(struct log *log, void *arg, void *dptr, uint16_t len)
     json_encode_object_start(encoder);
 
     JSON_VALUE_STRINGN(&jv, data, rc);
-    rc = json_encode_object_entry(encoder, "log", &jv);
+    rc = json_encode_object_entry(encoder, "msg", &jv);
     if (rc != 0) {
         goto err;
     }
 
-    JSON_VALUE_UINT(&jv, *(uint64_t *) &ueh.ue_ts);
+    JSON_VALUE_INT(&jv, ueh.ue_ts);
     rc = json_encode_object_entry(encoder, "ts", &jv);
     if (rc != 0) {
         goto err;
     }
 
+    JSON_VALUE_UINT(&jv, ueh.ue_level);
+    rc = json_encode_object_entry(encoder, "level", &jv);
+    if (rc != 0) {
+        goto err;
+    }
+
+    JSON_VALUE_UINT(&jv, ueh.ue_index);
+    rc = json_encode_object_entry(encoder, "index", &jv);
+    if (rc != 0) {
+        goto err;
+    }
+
     json_encode_object_finish(encoder);
 
     return (0);
@@ -121,10 +133,23 @@ log_nmgr_read(struct nmgr_jbuf *njb)
             continue;
         }
 
+        json_encode_object_start(encoder);
+        JSON_VALUE_STRING(&jv, log->l_name);
+        json_encode_object_entry(encoder, "name", &jv);
+
+        JSON_VALUE_INT(&jv, log->l_log->log_type);
+        json_encode_object_entry(encoder, "type", &jv);
+
+        json_encode_array_name(encoder, "entries");
+        json_encode_array_start(encoder);
+
         rc = log_walk(log, log_nmgr_add_entry, encoder);
         if (rc != 0) {
             goto err;
         }
+
+        json_encode_array_finish(encoder);
+        json_encode_object_finish(encoder);
     }
 
     json_encode_array_finish(encoder);


[2/2] incubator-mynewt-core git commit: Merge remote-tracking branch 'vrahane/develop' into develop

Posted by cc...@apache.org.
Merge remote-tracking branch 'vrahane/develop' into develop

This closes #42.


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/226c23d1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/226c23d1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/226c23d1

Branch: refs/heads/develop
Commit: 226c23d1f06f443c731f9fe8cedab1abeb4a5169
Parents: a04dba6 4b19a7a
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Apr 13 18:34:18 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Apr 13 18:34:18 2016 -0700

----------------------------------------------------------------------
 libs/baselibc/src/tinyprintf.c | 16 ++++++++--------
 libs/json/src/json_encode.c    |  8 ++++----
 libs/os/include/os/os_time.h   |  1 +
 libs/os/src/os_time.c          | 28 ++++++++++++++++++++++++----
 sys/log/include/log/log.h      | 10 +++++++---
 sys/log/src/log.c              | 36 +++++++++++++++++++++++++-----------
 sys/log/src/log_cbmem.c        | 25 ++++++++++++-------------
 sys/log/src/log_nmgr.c         | 29 +++++++++++++++++++++++++++--
 8 files changed, 108 insertions(+), 45 deletions(-)
----------------------------------------------------------------------