Change in libosmocore[master]: vty: add "show uptime"

laforge gerrit-no-reply at lists.osmocom.org
Fri Jul 16 15:57:01 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/24924 )

Change subject: vty: add "show uptime"
......................................................................

vty: add "show uptime"

Related: OS#4609
Change-Id: Ic7d9d5d3c8a9abd06a7e626aed7679f68406040c
---
M src/vty/command.c
1 file changed, 27 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  dexter: Looks good to me, approved; Verified
  pespin: Looks good to me, but someone else must approve



diff --git a/src/vty/command.c b/src/vty/command.c
index de89337..67b4001 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -46,6 +46,7 @@
 #include <osmocom/vty/command.h>
 
 #include <osmocom/core/talloc.h>
+#include <osmocom/core/timer.h>
 #include <osmocom/core/utils.h>
 
 #ifndef MAXPATHLEN
@@ -63,6 +64,9 @@
 
 void *tall_vty_cmd_ctx;
 
+/* Set by on_dso_load_starttime() for "show uptime". */
+static struct timespec starttime;
+
 /* Command vector which includes some level of command lists. Normally
    each daemon maintains each own cmdvec. */
 vector cmdvec;
@@ -3037,6 +3041,23 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(show_uptime,
+      show_uptime_cmd, "show uptime", SHOW_STR "Displays how long the program has been running\n")
+{
+	struct timespec now;
+	osmo_clock_gettime(CLOCK_MONOTONIC, &now);
+
+	time_t uptime = now.tv_sec - starttime.tv_sec;
+	int d = uptime / (3600 * 24);
+	int h = uptime / 3600 % 24;
+	int m = uptime / 60 % 60;
+	int s = uptime % 60;
+
+	vty_out(vty, "%s has been running for %dd %dh %dm %ds%s", host.app_info->name, d, h, m, s, VTY_NEWLINE);
+
+	return CMD_SUCCESS;
+}
+
 /* Help display function for all node. */
 gDEFUN(config_help,
       config_help_cmd, "help", "Description of the interactive help system\n")
@@ -4346,6 +4367,7 @@
 	install_node(&config_node, config_write_host);
 
 	/* Each node's basic commands. */
+	install_lib_element(VIEW_NODE, &show_uptime_cmd);
 	install_lib_element(VIEW_NODE, &show_version_cmd);
 	install_lib_element(VIEW_NODE, &show_online_help_cmd);
 	if (terminal) {
@@ -4399,6 +4421,11 @@
 	srand(time(NULL));
 }
 
+static __attribute__((constructor)) void on_dso_load_starttime(void)
+{
+	osmo_clock_gettime(CLOCK_MONOTONIC, &starttime);
+}
+
 /* FIXME: execute this section in the unit test instead */
 static __attribute__((constructor)) void on_dso_load(void)
 {

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24924
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic7d9d5d3c8a9abd06a7e626aed7679f68406040c
Gerrit-Change-Number: 24924
Gerrit-PatchSet: 4
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210716/889c86b1/attachment.htm>


More information about the gerrit-log mailing list