aboutsummaryrefslogtreecommitdiff
path: root/fmdsp/fmdsp_platform_win.c
diff options
context:
space:
mode:
authorTakamichi Horikawa <takamichiho@gmail.com>2017-04-15 01:00:20 +0900
committerTakamichi Horikawa <takamichiho@gmail.com>2017-04-15 01:00:20 +0900
commit680ab52d9e151676b8f90d105b23d2d0d89b0471 (patch)
tree5a05e82900393d2e1ecdf034cf1735d4ebfaec98 /fmdsp/fmdsp_platform_win.c
parent428126ee4c8802a4b5f9c9ee491d54013857741b (diff)
add fmdsp fft analyzer
Diffstat (limited to 'fmdsp/fmdsp_platform_win.c')
-rw-r--r--fmdsp/fmdsp_platform_win.c57
1 files changed, 57 insertions, 0 deletions
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 <stdint.h>
+#include <limits.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+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;
+}