add plugins-extra
This commit is contained in:
100
plugins-extra/AvgCpuPlugin/AvgCpuPlugin.rc
Normal file
100
plugins-extra/AvgCpuPlugin/AvgCpuPlugin.rc
Normal file
@@ -0,0 +1,100 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (Australia) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENA)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_AUS
|
||||
#pragma code_page(1252)
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,1,0,0
|
||||
PRODUCTVERSION 1,1,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "0c0904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "wj32"
|
||||
VALUE "FileDescription", "Average CPU plugin for Process Hacker"
|
||||
VALUE "FileVersion", "1.1"
|
||||
VALUE "InternalName", "wj32.AvgCpuPlugin"
|
||||
VALUE "LegalCopyright", "Licensed under the GNU GPL, v3."
|
||||
VALUE "OriginalFilename", "AvgCpuPlugin.dll"
|
||||
VALUE "ProductName", "Average CPU plugin for Process Hacker"
|
||||
VALUE "ProductVersion", "1.1"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0xc09, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // English (Australia) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
108
plugins-extra/AvgCpuPlugin/AvgCpuPlugin.vcxproj
Normal file
108
plugins-extra/AvgCpuPlugin/AvgCpuPlugin.vcxproj
Normal file
@@ -0,0 +1,108 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{A68DC3E8-5E2E-4883-A2A4-81F921458A9C}</ProjectGuid>
|
||||
<RootNamespace>AvgCpuPlugin</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectName>AvgCpuPlugin</ProjectName>
|
||||
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ExtraPlugins.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ExtraPlugins.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ExtraPlugins.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ExtraPlugins.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;C:\Users\AirDog46\Downloads\processhacker-2.39-src\bin\Debug32</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;C:\Users\AirDog46\Downloads\processhacker-2.39-src\bin\Release64</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;C:\Users\AirDog46\Downloads\processhacker-2.39-src\bin\Release32</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<TreatWarningAsError>false</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="AvgCpuPlugin.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CHANGELOG.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</Project>
|
||||
35
plugins-extra/AvgCpuPlugin/AvgCpuPlugin.vcxproj.filters
Normal file
35
plugins-extra/AvgCpuPlugin/AvgCpuPlugin.vcxproj.filters
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="AvgCpuPlugin.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CHANGELOG.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
5
plugins-extra/AvgCpuPlugin/CHANGELOG.txt
Normal file
5
plugins-extra/AvgCpuPlugin/CHANGELOG.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
1.1
|
||||
* Fixed calculation bug
|
||||
|
||||
1.0
|
||||
* Initial release
|
||||
315
plugins-extra/AvgCpuPlugin/main.c
Normal file
315
plugins-extra/AvgCpuPlugin/main.c
Normal file
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
* Process Hacker Extra Plugins -
|
||||
* Average CPU Plugin
|
||||
*
|
||||
* Copyright (C) 2011 wj32
|
||||
*
|
||||
* This file is part of Process Hacker.
|
||||
*
|
||||
* Process Hacker is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Process Hacker is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <phdk.h>
|
||||
#include "resource.h"
|
||||
|
||||
#define COLUMN_ID_AVGCPU10 1
|
||||
#define COLUMN_ID_AVGCPU60 2
|
||||
#define HISTORY_SIZE 60
|
||||
|
||||
typedef struct _PROCESS_EXTENSION
|
||||
{
|
||||
LIST_ENTRY ListEntry;
|
||||
PPH_PROCESS_ITEM ProcessItem;
|
||||
|
||||
FLOAT CpuHistory[HISTORY_SIZE];
|
||||
ULONG CpuHistoryCount;
|
||||
ULONG CpuHistoryPosition;
|
||||
|
||||
FLOAT Avg10CpuUsage;
|
||||
FLOAT Avg60CpuUsage;
|
||||
WCHAR Avg10CpuUsageText[PH_INT32_STR_LEN_1];
|
||||
WCHAR Avg60CpuUsageText[PH_INT32_STR_LEN_1];
|
||||
} PROCESS_EXTENSION, *PPROCESS_EXTENSION;
|
||||
|
||||
PPH_PLUGIN PluginInstance;
|
||||
PH_CALLBACK_REGISTRATION TreeNewMessageCallbackRegistration;
|
||||
PH_CALLBACK_REGISTRATION ProcessTreeNewInitializingCallbackRegistration;
|
||||
PH_CALLBACK_REGISTRATION ProcessAddedCallbackRegistration;
|
||||
PH_CALLBACK_REGISTRATION ProcessRemovedCallbackRegistration;
|
||||
PH_CALLBACK_REGISTRATION ProcessesUpdatedCallbackRegistration;
|
||||
|
||||
LIST_ENTRY ProcessListHead = { &ProcessListHead, &ProcessListHead };
|
||||
|
||||
VOID TreeNewMessageCallback(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
PPH_PLUGIN_TREENEW_MESSAGE message = Parameter;
|
||||
|
||||
switch (message->Message)
|
||||
{
|
||||
case TreeNewGetCellText:
|
||||
{
|
||||
PPH_TREENEW_GET_CELL_TEXT getCellText = message->Parameter1;
|
||||
PPH_PROCESS_NODE node;
|
||||
PPROCESS_EXTENSION extension;
|
||||
|
||||
node = (PPH_PROCESS_NODE)getCellText->Node;
|
||||
extension = PhPluginGetObjectExtension(PluginInstance, node->ProcessItem, EmProcessItemType);
|
||||
|
||||
switch (message->SubId)
|
||||
{
|
||||
case COLUMN_ID_AVGCPU10:
|
||||
case COLUMN_ID_AVGCPU60:
|
||||
{
|
||||
FLOAT cpuUsage;
|
||||
PWCHAR buffer;
|
||||
|
||||
if (message->SubId == COLUMN_ID_AVGCPU10)
|
||||
{
|
||||
cpuUsage = extension->Avg10CpuUsage * 100;
|
||||
buffer = extension->Avg10CpuUsageText;
|
||||
}
|
||||
else
|
||||
{
|
||||
cpuUsage = extension->Avg60CpuUsage * 100;
|
||||
buffer = extension->Avg60CpuUsageText;
|
||||
}
|
||||
|
||||
if (cpuUsage >= 0.01)
|
||||
{
|
||||
PH_FORMAT format;
|
||||
SIZE_T returnLength;
|
||||
|
||||
PhInitFormatF(&format, cpuUsage, 2);
|
||||
|
||||
if (PhFormatToBuffer(&format, 1, buffer, PH_INT32_STR_LEN_1 * sizeof(WCHAR), &returnLength))
|
||||
{
|
||||
getCellText->Text.Buffer = buffer;
|
||||
getCellText->Text.Length = (USHORT)(returnLength - sizeof(WCHAR)); // minus null terminator
|
||||
}
|
||||
}
|
||||
else if (cpuUsage != 0 && PhGetIntegerSetting(L"ShowCpuBelow001"))
|
||||
{
|
||||
PhInitializeStringRef(&getCellText->Text, L"< 0.01");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LONG NTAPI AvgCpuSortFunction(
|
||||
_In_ PVOID Node1,
|
||||
_In_ PVOID Node2,
|
||||
_In_ ULONG SubId,
|
||||
_In_ PVOID Context
|
||||
)
|
||||
{
|
||||
PPH_PROCESS_NODE node1 = Node1;
|
||||
PPH_PROCESS_NODE node2 = Node2;
|
||||
PPROCESS_EXTENSION extension1 = PhPluginGetObjectExtension(PluginInstance, node1->ProcessItem, EmProcessItemType);
|
||||
PPROCESS_EXTENSION extension2 = PhPluginGetObjectExtension(PluginInstance, node2->ProcessItem, EmProcessItemType);
|
||||
|
||||
switch (SubId)
|
||||
{
|
||||
case COLUMN_ID_AVGCPU10:
|
||||
return singlecmp(extension1->Avg10CpuUsage, extension2->Avg10CpuUsage);
|
||||
case COLUMN_ID_AVGCPU60:
|
||||
return singlecmp(extension1->Avg60CpuUsage, extension2->Avg60CpuUsage);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VOID ProcessTreeNewInitializingCallback(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
PPH_PLUGIN_TREENEW_INFORMATION info = Parameter;
|
||||
PH_TREENEW_COLUMN column;
|
||||
|
||||
memset(&column, 0, sizeof(PH_TREENEW_COLUMN));
|
||||
column.SortDescending = TRUE;
|
||||
column.Text = L"CPU Average (10)";
|
||||
column.Width = 45;
|
||||
column.Alignment = PH_ALIGN_RIGHT;
|
||||
column.TextFlags = DT_RIGHT;
|
||||
PhPluginAddTreeNewColumn(PluginInstance, info->CmData, &column, COLUMN_ID_AVGCPU10, NULL, AvgCpuSortFunction);
|
||||
|
||||
column.Text = L"CPU Average (60)";
|
||||
PhPluginAddTreeNewColumn(PluginInstance, info->CmData, &column, COLUMN_ID_AVGCPU60, NULL, AvgCpuSortFunction);
|
||||
}
|
||||
|
||||
VOID ProcessItemCreateCallback(
|
||||
_In_ PVOID Object,
|
||||
_In_ PH_EM_OBJECT_TYPE ObjectType,
|
||||
_In_ PVOID Extension
|
||||
)
|
||||
{
|
||||
PPH_PROCESS_ITEM processItem = Object;
|
||||
PPROCESS_EXTENSION extension = Extension;
|
||||
|
||||
memset(extension, 0, sizeof(PROCESS_EXTENSION));
|
||||
extension->ProcessItem = processItem;
|
||||
}
|
||||
|
||||
VOID ProcessAddedHandler(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
PPH_PROCESS_ITEM processItem = Parameter;
|
||||
PPROCESS_EXTENSION extension = PhPluginGetObjectExtension(PluginInstance, processItem, EmProcessItemType);
|
||||
|
||||
InsertTailList(&ProcessListHead, &extension->ListEntry);
|
||||
}
|
||||
|
||||
VOID ProcessRemovedHandler(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
PPH_PROCESS_ITEM processItem = Parameter;
|
||||
PPROCESS_EXTENSION extension = PhPluginGetObjectExtension(PluginInstance, processItem, EmProcessItemType);
|
||||
|
||||
RemoveEntryList(&extension->ListEntry);
|
||||
}
|
||||
|
||||
VOID ProcessesUpdatedHandler(
|
||||
_In_opt_ PVOID Parameter,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
static ULONG runCount = 0;
|
||||
|
||||
if (runCount != 0)
|
||||
{
|
||||
PLIST_ENTRY listEntry;
|
||||
|
||||
listEntry = ProcessListHead.Flink;
|
||||
|
||||
while (listEntry != &ProcessListHead)
|
||||
{
|
||||
PPROCESS_EXTENSION extension = CONTAINING_RECORD(listEntry, PROCESS_EXTENSION, ListEntry);
|
||||
PPH_PROCESS_ITEM processItem = extension->ProcessItem;
|
||||
FLOAT sum;
|
||||
ULONG i;
|
||||
ULONG total;
|
||||
ULONG count;
|
||||
|
||||
if (extension->CpuHistoryPosition != 0)
|
||||
extension->CpuHistoryPosition--;
|
||||
else
|
||||
extension->CpuHistoryPosition = HISTORY_SIZE - 1;
|
||||
|
||||
extension->CpuHistory[extension->CpuHistoryPosition] = processItem->CpuUsage;
|
||||
|
||||
if (extension->CpuHistoryCount < HISTORY_SIZE)
|
||||
extension->CpuHistoryCount++;
|
||||
|
||||
// Calculate the 10 interval average.
|
||||
|
||||
sum = 0;
|
||||
i = extension->CpuHistoryPosition;
|
||||
total = 10;
|
||||
|
||||
if (total > extension->CpuHistoryCount)
|
||||
total = extension->CpuHistoryCount;
|
||||
|
||||
count = total;
|
||||
|
||||
do
|
||||
{
|
||||
sum += extension->CpuHistory[i];
|
||||
i++;
|
||||
|
||||
if (i == HISTORY_SIZE)
|
||||
i = 0;
|
||||
} while (--count != 0);
|
||||
|
||||
extension->Avg10CpuUsage = sum / total;
|
||||
|
||||
// Calculate the 60 interval average.
|
||||
|
||||
if (extension->CpuHistoryCount > 10)
|
||||
{
|
||||
total = 50;
|
||||
|
||||
if (total > extension->CpuHistoryCount - 10)
|
||||
total = extension->CpuHistoryCount - 10;
|
||||
|
||||
count = total;
|
||||
|
||||
do
|
||||
{
|
||||
sum += extension->CpuHistory[i];
|
||||
i++;
|
||||
|
||||
if (i == HISTORY_SIZE)
|
||||
i = 0;
|
||||
} while (--count != 0);
|
||||
|
||||
extension->Avg60CpuUsage = sum / (total + 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not enough samples.
|
||||
extension->Avg60CpuUsage = extension->Avg10CpuUsage;
|
||||
}
|
||||
|
||||
listEntry = listEntry->Flink;
|
||||
}
|
||||
}
|
||||
|
||||
runCount++;
|
||||
}
|
||||
|
||||
LOGICAL DllMain(
|
||||
_In_ HINSTANCE Instance,
|
||||
_In_ ULONG Reason,
|
||||
_Reserved_ PVOID Reserved
|
||||
)
|
||||
{
|
||||
if (Reason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
PPH_PLUGIN_INFORMATION info;
|
||||
|
||||
PluginInstance = PhRegisterPlugin(L"wj32.AvgCpuPlugin", Instance, &info);
|
||||
|
||||
if (!PluginInstance)
|
||||
return FALSE;
|
||||
|
||||
info->DisplayName = L"Average CPU";
|
||||
info->Description = L"Adds a column to display average CPU times.";
|
||||
info->Author = L"wj32";
|
||||
|
||||
PhRegisterCallback(PhGetPluginCallback(PluginInstance, PluginCallbackTreeNewMessage),
|
||||
TreeNewMessageCallback, NULL, &TreeNewMessageCallbackRegistration);
|
||||
PhRegisterCallback(PhGetGeneralCallback(GeneralCallbackProcessTreeNewInitializing),
|
||||
ProcessTreeNewInitializingCallback, NULL, &ProcessTreeNewInitializingCallbackRegistration);
|
||||
PhRegisterCallback(&PhProcessAddedEvent, ProcessAddedHandler, NULL, &ProcessAddedCallbackRegistration);
|
||||
PhRegisterCallback(&PhProcessRemovedEvent, ProcessRemovedHandler, NULL, &ProcessRemovedCallbackRegistration);
|
||||
PhRegisterCallback(&PhProcessesUpdatedEvent, ProcessesUpdatedHandler, NULL, &ProcessesUpdatedCallbackRegistration);
|
||||
|
||||
PhPluginSetObjectExtension(PluginInstance, EmProcessItemType, sizeof(PROCESS_EXTENSION),
|
||||
ProcessItemCreateCallback, NULL);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
15
plugins-extra/AvgCpuPlugin/resource.h
Normal file
15
plugins-extra/AvgCpuPlugin/resource.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by AvgCpuPlugin.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user