1 | #include "muscle.h" |
---|
2 | |
---|
3 | #if WIN32 |
---|
4 | #include <windows.h> |
---|
5 | #include <crtdbg.h> |
---|
6 | #include <psapi.h> |
---|
7 | #include <float.h> |
---|
8 | #include <stdio.h> |
---|
9 | |
---|
10 | void DebugPrintf(const char *szFormat, ...) |
---|
11 | { |
---|
12 | va_list ArgList; |
---|
13 | char szStr[4096]; |
---|
14 | |
---|
15 | va_start(ArgList, szFormat); |
---|
16 | vsprintf(szStr, szFormat, ArgList); |
---|
17 | |
---|
18 | OutputDebugString(szStr); |
---|
19 | } |
---|
20 | |
---|
21 | double GetNAN() |
---|
22 | { |
---|
23 | static unsigned long nan[2]={0xffffffff, 0x7fffffff}; |
---|
24 | double dNAN = *( double* )nan; |
---|
25 | assert(_isnan(dNAN)); |
---|
26 | return dNAN; |
---|
27 | } |
---|
28 | |
---|
29 | double g_dNAN = GetNAN(); |
---|
30 | |
---|
31 | void chkmem(const char szMsg[]) |
---|
32 | { |
---|
33 | if (!_CrtCheckMemory()) |
---|
34 | Quit("chkmem(%s)", szMsg); |
---|
35 | } |
---|
36 | |
---|
37 | void Break() |
---|
38 | { |
---|
39 | if (IsDebuggerPresent()) |
---|
40 | DebugBreak(); |
---|
41 | } |
---|
42 | |
---|
43 | const char *GetCmdLine() |
---|
44 | { |
---|
45 | return GetCommandLine(); |
---|
46 | } |
---|
47 | |
---|
48 | static unsigned uPeakMemUseBytes; |
---|
49 | |
---|
50 | double GetRAMSizeMB() |
---|
51 | { |
---|
52 | MEMORYSTATUS MS; |
---|
53 | GlobalMemoryStatus(&MS); |
---|
54 | return MS.dwAvailPhys/1e6; |
---|
55 | } |
---|
56 | |
---|
57 | double GetMemUseMB() |
---|
58 | { |
---|
59 | HANDLE hProc = GetCurrentProcess(); |
---|
60 | PROCESS_MEMORY_COUNTERS PMC; |
---|
61 | BOOL bOk = GetProcessMemoryInfo(hProc, &PMC, sizeof(PMC)); |
---|
62 | assert(bOk); |
---|
63 | //printf("GetMemUseMB()\n"); |
---|
64 | //printf("%12u PageFaultCount\n", (unsigned) PMC.PageFaultCount); |
---|
65 | //printf("%12u PagefileUsage\n", (unsigned) PMC.PagefileUsage); |
---|
66 | //printf("%12u PeakPagefileUsage\n", (unsigned) PMC.PeakPagefileUsage); |
---|
67 | //printf("%12u WorkingSetSize\n", (unsigned) PMC.WorkingSetSize); |
---|
68 | //printf("%12u PeakWorkingSetSize\n", (unsigned) PMC.PeakWorkingSetSize); |
---|
69 | //printf("%12u QuotaPagedPoolUsage\n", (unsigned) PMC.QuotaPagedPoolUsage); |
---|
70 | //printf("%12u QuotaPeakPagedPoolUsage\n", (unsigned) PMC.QuotaPeakPagedPoolUsage); |
---|
71 | //printf("%12u QuotaNonPagedPoolUsage\n", (unsigned) PMC.QuotaNonPagedPoolUsage); |
---|
72 | //printf("%12u QuotaPeakNonPagedPoolUsage\n", (unsigned) PMC.QuotaPeakNonPagedPoolUsage); |
---|
73 | unsigned uBytes = (unsigned) PMC.WorkingSetSize; |
---|
74 | if (uBytes > uPeakMemUseBytes) |
---|
75 | uPeakMemUseBytes = uBytes; |
---|
76 | return (uBytes + 500000.0)/1000000.0; |
---|
77 | } |
---|
78 | |
---|
79 | double GetPeakMemUseMB() |
---|
80 | { |
---|
81 | return (uPeakMemUseBytes + 500000.0)/1000000.0; |
---|
82 | } |
---|
83 | |
---|
84 | void CheckMemUse() |
---|
85 | { |
---|
86 | // Side-effect: sets peak usage in uPeakMemUseBytes |
---|
87 | GetMemUseMB(); |
---|
88 | } |
---|
89 | |
---|
90 | double GetCPUGHz() |
---|
91 | { |
---|
92 | double dGHz = 2.5; |
---|
93 | const char *e = getenv("CPUGHZ"); |
---|
94 | if (0 != e) |
---|
95 | dGHz = atof(e); |
---|
96 | if (dGHz < 0.1 || dGHz > 1000.0) |
---|
97 | Quit("Invalid value '%s' for environment variable CPUGHZ", e); |
---|
98 | return dGHz; |
---|
99 | } |
---|
100 | #endif // WIN32 |
---|