From bc3ba178e3652b29a07510fba11443084d4cf162 Mon Sep 17 00:00:00 2001 From: "KJK::Hyperion" Date: Sun, 9 Feb 2003 21:17:21 +0000 Subject: [PATCH] New utility tickcount: displays the kernel tick count in human readable format. Sample output: 3 days, 11 hours, 13 minutes, 27 seconds and 943 milliseconds svn path=/trunk/; revision=4131 --- reactos/apps/utils/Makefile | 2 +- reactos/apps/utils/tickcount/makefile | 19 +++ reactos/apps/utils/tickcount/tickcount.c | 142 +++++++++++++++++++++++ 3 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 reactos/apps/utils/tickcount/makefile create mode 100644 reactos/apps/utils/tickcount/tickcount.c diff --git a/reactos/apps/utils/Makefile b/reactos/apps/utils/Makefile index 2cd73483c21..a9b10338d9c 100644 --- a/reactos/apps/utils/Makefile +++ b/reactos/apps/utils/Makefile @@ -9,7 +9,7 @@ include $(PATH_TO_TOP)/rules.mak # Console system utilities # cabman cat net objdir partinfo pice ps sc stats -UTIL_APPS = cat objdir partinfo sc stats +UTIL_APPS = cat objdir partinfo sc stats tickcount UTIL_NET_APPS = diff --git a/reactos/apps/utils/tickcount/makefile b/reactos/apps/utils/tickcount/makefile new file mode 100644 index 00000000000..96791815a9d --- /dev/null +++ b/reactos/apps/utils/tickcount/makefile @@ -0,0 +1,19 @@ +PATH_TO_TOP = ../../.. + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = tickcount + +TARGET_SDKLIBS = kernel32.a + +TARGET_OBJECTS = tickcount.o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/reactos/apps/utils/tickcount/tickcount.c b/reactos/apps/utils/tickcount/tickcount.c new file mode 100644 index 00000000000..2cf4940d231 --- /dev/null +++ b/reactos/apps/utils/tickcount/tickcount.c @@ -0,0 +1,142 @@ +/* $Id: tickcount.c,v 1.1 2003/02/09 21:17:21 hyperion Exp $ +*/ +/* + tickcount -- Display the kernel tick count in human-readable format + + This is public domain software +*/ + +#include +#include +#include +#include + +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; + +#define TICKS_YEAR (TICKS_DAY * ((uint64_t)365)) +#define TICKS_MONTH (TICKS_DAY * ((uint64_t)30)) +#define TICKS_WEEK (TICKS_DAY * ((uint64_t)7)) +#define TICKS_DAY (TICKS_HOUR * ((uint64_t)24)) +#define TICKS_HOUR (TICKS_MINUTE * ((uint64_t)60)) +#define TICKS_MINUTE (TICKS_SECOND * ((uint64_t)60)) +#define TICKS_SECOND ((uint64_t)1000) + +#define SLICES_COUNT (sizeof(ticks_per_slice) / sizeof(ticks_per_slice[0])) + +uint64_t ticks_per_slice[] = +{ + TICKS_YEAR, + TICKS_MONTH, + TICKS_WEEK, + TICKS_DAY, + TICKS_HOUR, + TICKS_MINUTE, + TICKS_SECOND, + 1 +}; + +_TCHAR * slice_names_singular[] = +{ + _T("year"), + _T("month"), + _T("week"), + _T("day"), + _T("hour"), + _T("minute"), + _T("second"), + _T("millisecond") +}; + +_TCHAR * slice_names_plural[] = +{ + _T("years"), + _T("months"), + _T("weeks"), + _T("days"), + _T("hours"), + _T("minutes"), + _T("seconds"), + _T("milliseconds") +}; + +void print_uptime +( + uint64_t tickcount, + uint64_t prevsliceval, + _TCHAR * prevsliceunit, + int curslice +) +{ + uint64_t tick_cur = tickcount / ticks_per_slice[curslice]; + uint64_t tick_residual = tickcount % ticks_per_slice[curslice]; + + assert(tick_cur <= (~((unsigned)0))); + + if(tick_residual == 0) + { + /* the current slice is the last */ + + if(prevsliceval == 0) + { + /* the current slice is the only */ + _tprintf + ( + _T("%u %s"), + (unsigned)tick_cur, + (tick_cur == 1 ? slice_names_singular : slice_names_plural)[curslice] + ); + } + else + { + /* the current slice is the last, and there's a previous slice */ + assert(prevsliceunit); + + /* print the previous and the current slice, and terminate */ + _tprintf + ( + _T("%u %s %s %u %s"), + (unsigned)prevsliceval, + prevsliceunit, + _T("and"), + (unsigned)tick_cur, + (tick_cur == 1 ? slice_names_singular : slice_names_plural)[curslice] + ); + } + } + else if(tick_cur != 0) + { + /* the current slice is not the last, and non-zero */ + + if(prevsliceval != 0) + { + /* there's a previous slice: print it */ + assert(prevsliceunit); + _tprintf(_T("%u %s, "), (unsigned)prevsliceval, prevsliceunit); + } + + /* recursion on the next slice size, storing the current slice */ + print_uptime + ( + tick_residual, + tick_cur, + (tick_cur == 1 ? slice_names_singular : slice_names_plural)[curslice], + curslice + 1 + ); + } + else + { + /* + the current slice is not the last, and zero: recursion, remembering the + previous non-zero slice + */ + print_uptime(tick_residual, prevsliceval, prevsliceunit, curslice + 1); + } +} + +int _tmain() +{ + print_uptime((uint64_t)GetTickCount(), 0, NULL, 0); + _puttc(_T('\n'), stdout); + return 0; +}