4 tickcount -- Display the kernel tick count (or any tick count passed as an
5 argument or as input) in human-readable format
7 This is public domain software
16 typedef __int64 int64_
;
17 typedef unsigned __int64 uint64_
;
19 #define TICKS_YEAR (TICKS_DAY * ((uint64_)365))
20 #define TICKS_MONTH (TICKS_DAY * ((uint64_)30))
21 #define TICKS_WEEK (TICKS_DAY * ((uint64_)7))
22 #define TICKS_DAY (TICKS_HOUR * ((uint64_)24))
23 #define TICKS_HOUR (TICKS_MINUTE * ((uint64_)60))
24 #define TICKS_MINUTE (TICKS_SECOND * ((uint64_)60))
25 #define TICKS_SECOND ((uint64_)1000)
27 #define SLICES_COUNT (sizeof(ticks_per_slice) / sizeof(ticks_per_slice[0]))
29 uint64_ ticks_per_slice
[] =
41 _TCHAR
* slice_names_singular
[SLICES_COUNT
] =
53 _TCHAR
* slice_names_plural
[SLICES_COUNT
] =
69 _TCHAR
* prevsliceunit
,
73 uint64_ tick_cur
= tickcount
/ ticks_per_slice
[curslice
];
74 uint64_ tick_residual
= tickcount
% ticks_per_slice
[curslice
];
76 assert(tick_cur
<= (~((uint64_
)0)));
78 if(tick_residual
== 0)
80 /* the current slice is the last */
84 /* the current slice is the only */
89 (tick_cur
== 1 ? slice_names_singular
: slice_names_plural
)[curslice
]
94 /* the current slice is the last, and there's a previous slice */
95 assert(prevsliceunit
);
97 /* print the previous and the current slice, and terminate */
100 _T("%u %s %s %u %s"),
101 (unsigned)prevsliceval
,
105 (tick_cur
== 1 ? slice_names_singular
: slice_names_plural
)[curslice
]
109 else if(tick_cur
!= 0)
111 /* the current slice is not the last, and non-zero */
113 if(prevsliceval
!= 0)
115 /* there's a previous slice: print it */
116 assert(prevsliceunit
);
117 _tprintf(_T("%u %s, "), (unsigned)prevsliceval
, prevsliceunit
);
120 /* recursion on the next slice size, storing the current slice */
125 (tick_cur
== 1 ? slice_names_singular
: slice_names_plural
)[curslice
],
132 the current slice is not the last, and zero: recursion, remembering the
133 previous non-zero slice
135 print_uptime(tick_residual
, prevsliceval
, prevsliceunit
, curslice
+ 1);
139 int parse_print(const _TCHAR
* str
)
143 tickcount
= _ttoi64(str
);
146 tickcount
= - tickcount
;
147 else if(tickcount
== 0)
150 print_uptime(tickcount
, 0, NULL
, 0);
151 _puttc(_T('\n'), stdout
);
156 int _tmain(int argc
, _TCHAR
* argv
[])
162 print_uptime((uint64_
)GetTickCount(), 0, NULL
, 0);
163 _puttc(_T('\n'), stdout
);
165 else if(argc
== 2 && argv
[1][0] == _T('-') && argv
[1][1] == 0)
172 str
= _fgetts(buf
, 22, stdin
);
177 if((r
= parse_print(str
)) != 0)
185 for(i
= 1; i
< argc
; ++ i
)
186 if((r
= parse_print(argv
[i
])) != 0)