File: globalswin32.cpp

package info (click to toggle)
libmuscle 3.7%2B4565-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,912 kB
  • sloc: cpp: 27,959; makefile: 58; sh: 26
file content (106 lines) | stat: -rw-r--r-- 2,504 bytes parent folder | download | duplicates (5)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "libMUSCLE/muscle.h"
#include "libMUSCLE/threadstorage.h"

#if	WIN32
#include <windows.h>
#include <crtdbg.h>
#include <psapi.h>
#include <float.h>
#include <stdio.h>

namespace muscle {

void DebugPrintf(const char *szFormat, ...)
	{
	va_list ArgList;
	char szStr[4096];

	va_start(ArgList, szFormat);
	vsprintf(szStr, szFormat, ArgList);

	OutputDebugString(szStr);
	}

double GetNAN()
	{
	static const unsigned long nan[2]={0xffffffff, 0x7fffffff};
	double dNAN = *( double* )nan;
	assert(_isnan(dNAN));
	return dNAN;
	}

TLS<double> g_dNAN(GetNAN());

void chkmem(const char szMsg[])
	{
	if (!_CrtCheckMemory())
		Quit("chkmem(%s)", szMsg);
	}

void Break()
	{
	if (IsDebuggerPresent())
		DebugBreak();
	}

const char *GetCmdLine()
	{
	return GetCommandLine();
	}

static TLS<unsigned> uPeakMemUseBytes;

double GetRAMSizeMB()
	{
	MEMORYSTATUS MS;
	GlobalMemoryStatus(&MS);
	return MS.dwAvailPhys/1e6;
	}

double GetMemUseMB()
	{
	HANDLE hProc = GetCurrentProcess();
	PROCESS_MEMORY_COUNTERS PMC;
	BOOL bOk = GetProcessMemoryInfo(hProc, &PMC, sizeof(PMC));
	assert(bOk);
	//printf("GetMemUseMB()\n");
	//printf("%12u  PageFaultCount\n", (unsigned) PMC.PageFaultCount);
	//printf("%12u  PagefileUsage\n", (unsigned) PMC.PagefileUsage);
	//printf("%12u  PeakPagefileUsage\n", (unsigned) PMC.PeakPagefileUsage);
	//printf("%12u  WorkingSetSize\n", (unsigned) PMC.WorkingSetSize);
	//printf("%12u  PeakWorkingSetSize\n", (unsigned) PMC.PeakWorkingSetSize);
	//printf("%12u  QuotaPagedPoolUsage\n", (unsigned) PMC.QuotaPagedPoolUsage);
	//printf("%12u  QuotaPeakPagedPoolUsage\n", (unsigned) PMC.QuotaPeakPagedPoolUsage);
	//printf("%12u  QuotaNonPagedPoolUsage\n", (unsigned) PMC.QuotaNonPagedPoolUsage);
	//printf("%12u  QuotaPeakNonPagedPoolUsage\n", (unsigned) PMC.QuotaPeakNonPagedPoolUsage);
	unsigned uBytes = (unsigned) PMC.WorkingSetSize;
	if (uBytes > uPeakMemUseBytes.get())
		uPeakMemUseBytes.get() = uBytes;
	return (uBytes + 500000.0)/1000000.0;
	}

double GetPeakMemUseMB()
	{
	return (uPeakMemUseBytes.get() + 500000.0)/1000000.0;
	}

void CheckMemUse()
	{
// Side-effect: sets peak usage in uPeakMemUseBytes
	GetMemUseMB();
	}

double GetCPUGHz()
	{
	double dGHz = 2.5;
	const char *e = getenv("CPUGHZ");
	if (0 != e)
		dGHz = atof(e);
	if (dGHz < 0.1 || dGHz > 1000.0)
		Quit("Invalid value '%s' for environment variable CPUGHZ", e);
	return dGHz;
	}

} 

#endif	// WIN32