summaryrefslogtreecommitdiff
path: root/apps/apps_win.c
blob: 496ac0369a5240cb1422fe0f9a2cd18ef05f73f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Public domain
 *
 * Dongsheng Song <dongsheng.song@gmail.com>
 * Brent Cook <bcook@openbsd.org>
 */

#include <windows.h>

#include "apps.h"

double
app_tminterval(int stop, int usertime)
{
	static unsigned __int64 tmstart;
	union {
		unsigned __int64 u64;
		FILETIME ft;
	} ct, et, kt, ut;

	GetProcessTimes(GetCurrentProcess(), &ct.ft, &et.ft, &kt.ft, &ut.ft);

	if (stop == TM_START) {
		tmstart = ut.u64 + kt.u64;
	} else {
		return (ut.u64 + kt.u64 - tmstart) / (double) 10000000;
	}
	return 0;
}