Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Professional System Library: Introduction

, 22 Nov 2010
A simplified and unified way for accessing most frequently used information about Process, System, and Environment.
ProcessViewer32_bin.zip
SimpleProcessViewer.exe
Interop.ProSysLib.dll
ProSysLib.dll
ProcessViewer64_bin.zip
SimpleProcessViewer.exe
Interop.ProSysLib.dll
ProSysLib.dll
ProcessViewer_bin.zip
PSL64v0.9.dll
Interop.ProSysLib.dll
ProcessViewer.exe
PSL32v0.9.dll
ProSysLib_v0.9.zip
ProSysLib_v0.9
Bin
PSL32v0.9.dll
PSL64v0.9.dll
Help
Samples
C#2008
ProcessInfo
Properties
Settings.settings
ProcessViewer
Properties
Settings.settings
VB6
CPUInfo.exe
CPUInfo.frm
CPUInfo.frx
CPUInfo.vbp
CPUInfo.vbw
VC2008
Deployment
Src
mssccprj.scc
ProSysLib.def
ProSysLib.rgs
ProSysLib.vcproj.vspscc
ProSysLib.vssscc
PSLSystem.rgs
PSLv0.3Setup.zip
PSLv0.3Setup.exe
PSLv0.4Setup.zip
PSLv0.4Setup.exe
PSLv0.7Setup.zip
PSLv0.7Setup.exe
SimpleProcessViewer_src.zip
SimpleProcessViewer
Properties
Settings.settings
#pragma once


////////////////////////////////////////
// class CProcessorUsage;
//
// Calculates overal processor usage at
// any given time.
//
// The usage value is updated every 200
// milliseconds;
//
// The class is fully thread-safe;
//
class CProcessorUsage
{
	typedef BOOL (WINAPI * pfnGetSystemTimes)(LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime );
	typedef LONG (WINAPI * pfnNtQuerySystemInformation)(ULONG SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength);

	struct PROC_PERF_INFO
	{
		LARGE_INTEGER IdleTime;
		LARGE_INTEGER KernelTime;
		LARGE_INTEGER UserTime;
		LARGE_INTEGER Reserved1[2];
		ULONG Reserved2;
	};

public:

    CProcessorUsage();
    ~CProcessorUsage();

    short GetUsage();

private:

	void GetSysTimes(__int64 & idleTime, __int64 & kernelTime, __int64 & userTime);

	////////////////////////////////////////////////
	// Set of static variables to be accessed from
	// within critical section by multiple threads:
	//
	static DWORD s_TickMark;
	static __int64 s_time;
	static __int64 s_idleTime;
	static __int64 s_kernelTime;
	static __int64 s_userTime;
	static int s_lastCpu;
	static int s_cpu[5];
	static __int64 s_kernelTimeProcess;
	static __int64 s_userTimeProcess;
	static int s_cpuProcess[5];
    static int s_count;
    static int s_index;
	//
	/////////////////////////////////////////////////

	pfnGetSystemTimes s_pfnGetSystemTimes;
	pfnNtQuerySystemInformation s_pfnNtQuerySystemInformation;
	CRITICAL_SECTION m_cs;
	PROC_PERF_INFO * m_pInfo;
	ULONG m_uInfoLength;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Vitaly Tomilov
Software Developer (Senior) Sibedge IT
Ireland Ireland
My online CV: cv.vitalytomilov.com

| Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 22 Nov 2010
Article Copyright 2008 by Vitaly Tomilov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid