From 680ab52d9e151676b8f90d105b23d2d0d89b0471 Mon Sep 17 00:00:00 2001 From: Takamichi Horikawa Date: Sat, 15 Apr 2017 01:00:20 +0900 Subject: add fmdsp fft analyzer --- fmdsp/fmdsp_platform_win.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 fmdsp/fmdsp_platform_win.c (limited to 'fmdsp/fmdsp_platform_win.c') diff --git a/fmdsp/fmdsp_platform_win.c b/fmdsp/fmdsp_platform_win.c new file mode 100644 index 0000000..3dc4074 --- /dev/null +++ b/fmdsp/fmdsp_platform_win.c @@ -0,0 +1,57 @@ +#include "fmdsp_platform_info.h" +#include +#include +#define WIN32_LEAN_AND_MEAN +#include + +static struct { + HANDLE currproc; + uint64_t lastall; + uint64_t lastcpu; + uint64_t lastfpstime; +} g; + +int fmdsp_cpu_usage(void) { + if (!g.currproc) g.currproc = GetCurrentProcess(); + FILETIME ft_sys, ft_creat, ft_exit, ft_kern, ft_user; + GetSystemTimeAsFileTime(&ft_sys); + GetProcessTimes(g.currproc, &ft_creat, &ft_exit, &ft_kern, &ft_user); + uint64_t all = ft_sys.dwHighDateTime; + all <<= 32; + all |= ft_sys.dwLowDateTime; + uint64_t kern = ft_kern.dwHighDateTime; + kern <<= 32; + kern |= ft_kern.dwLowDateTime; + uint64_t user = ft_user.dwHighDateTime; + user <<= 32; + user |= ft_user.dwLowDateTime; + uint64_t cpu = kern + user; + uint64_t alld = all - g.lastall; + uint64_t cpud = cpu - g.lastcpu; + int percentage = 0; + if (alld) percentage = cpud * 100 / alld; + g.lastall = all; + g.lastcpu = cpu; + if (!g.lastall) return 0; + if (percentage > INT_MAX) percentage = INT_MAX; + if (percentage < 0) percentage = 0; + return percentage; +} + +int fmdsp_fps_30(void) { + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + uint64_t time = ft.dwHighDateTime; + time <<= 32; + time |= ft.dwLowDateTime; + uint64_t fps = 0; + if (g.lastfpstime) { + uint64_t diff = time - g.lastfpstime; + if (diff) { + fps = 30ull * 10000000ull / diff; + } + } + g.lastfpstime = time; + if (fps > INT_MAX) fps = INT_MAX; + return fps; +} -- cgit v1.2.3