Skip to content

Commit

Permalink
Merge pull request #106 from jeongarmy/kdbg_uptime
Browse files Browse the repository at this point in the history
Add uptime to TASH commands
  • Loading branch information
sunghan-chang authored May 19, 2017
2 parents 41007f4 + b095855 commit f99f71a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/system/utils/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 4 additions & 0 deletions apps/system/utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions apps/system/utils/kdbg_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
56 changes: 56 additions & 0 deletions apps/system/utils/kdbg_uptime.c
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions apps/system/utils/kernelcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const static tash_cmdlist_t kdbg_cmds[] = {
#endif
#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}
};
Expand Down

0 comments on commit f99f71a

Please sign in to comment.