Add uptime to TASH commands
authorAhreum Jeong <ahreum.jeong@samsung.com>
Tue, 4 Apr 2017 00:17:19 +0000 (09:17 +0900)
committerAhreum Jeong <ahreum.jeong@samsung.com>
Fri, 19 May 2017 04:20:01 +0000 (13:20 +0900)
uptime print how long the system has been running

apps/system/utils/Kconfig
apps/system/utils/Makefile
apps/system/utils/kdbg_commands.h
apps/system/utils/kdbg_uptime.c [new file with mode: 0644]
apps/system/utils/kernelcmd.c

index b5949bd..dade064 100644 (file)
@@ -130,3 +130,9 @@ config STACKMONITOR_INTERVAL
 
 endif #ENABLE_STACKMONITOR
 
+config ENABLE_UPTIME
+       bool "uptime"
+       default y
+       ---help---
+               print how long the system has been running
+
index e35186e..340ee5a 100644 (file)
@@ -128,6 +128,10 @@ ifeq ($(CONFIG_ENABLE_STACKMONITOR),y)
 CSRCS += kdbg_stackmonitor.c
 endif
 
+ifeq ($(CONFIG_ENABLE_UPTIME),y)
+CSRCS += kdbg_uptime.c
+endif
+
 AOBJS = $(ASRCS:.S=$(OBJEXT))
 COBJS = $(CSRCS:.c=$(OBJEXT))
 MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
index a6e639e..1885f98 100644 (file)
@@ -69,4 +69,8 @@ int kdbg_ps(int argc, char **args);
 int kdbg_stackmonitor(int argc, char **args);
 #endif
 
+#if defined(CONFIG_ENABLE_UPTIME)
+int kdbg_uptime(int argc, char **args);
+#endif
+
 #endif                                                 /* __APPS_SYSTEM_UTILS_KDBG_COMMANDS_H */
diff --git a/apps/system/utils/kdbg_uptime.c b/apps/system/utils/kdbg_uptime.c
new file mode 100644 (file)
index 0000000..f3d3b7c
--- /dev/null
@@ -0,0 +1,56 @@
+/****************************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ ****************************************************************************/
+#include <tinyara/config.h>
+#include <stdio.h>
+#include <time.h>
+#include <sys/types.h>
+#include <tinyara/clock.h>
+
+int kdbg_uptime(int argc, char **args)
+{
+       systime_t ticktime;
+#if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT)
+       double now;
+#else
+#ifdef CONFIG_SYSTIME_TIME64
+       uint64_t sec;
+#else
+       uint32_t sec;
+#endif
+       unsigned int csec;
+#endif
+
+       ticktime = clock_systimer();
+
+#if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT)
+       now = (double)ticktime / (double)CLOCKS_PER_SEC;
+       printf("Uptime : %.2f\n", now);
+#else
+       /* Convert the system up time to seconds + hundredths of seconds */
+       sec = ticktime / CLOCKS_PER_SEC;
+       csec = (100 * (ticktime % CLOCKS_PER_SEC) + (CLOCKS_PER_SEC / 2)) / CLOCKS_PER_SEC;
+
+       /* Make sure that rounding did not force the hundredths of a second above 99 */
+       if (csec > 99) {
+               sec++;
+               csec -= 100;
+       }
+       printf("Uptime : %u.%u\n", sec, csec);
+#endif
+       return OK;
+}
index 2fa6546..466bd3e 100644 (file)
@@ -58,6 +58,9 @@ const static tash_cmdlist_t kdbg_cmds[] = {
 #if defined(CONFIG_ENABLE_ENV_UNSET) && !defined(CONFIG_DISABLE_ENVIRON)
        {"unsetenv", kdbg_env_unset,    TASH_EXECMD_SYNC},
 #endif
+#if defined(CONFIG_ENABLE_UPTIME)
+       {"uptime",   kdbg_uptime,       TASH_EXECMD_SYNC},
+#endif
        {NULL,       NULL,              0}
 };