Skip to content

Commit 764d2e6

Browse files
Initial Release
Initial Release
1 parent a5e5809 commit 764d2e6

18 files changed

+1988
-0
lines changed

Preview/CpuStress-Example.png

17.2 KB
Loading

Preview/DiskStress-Example.png

29.2 KB
Loading

Preview/MemoryStress-Example.png

20.1 KB
Loading

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,95 @@
11
# HardwareStress
2+
3+
**HardwareStress** is a .NET library that provides a mechanism to stress hardware resources, such as CPU, Disk or RAM.
4+
5+
<u>**As any other software focused to stress hardware resources, you must use it at your own risk. I don't take any responsability of a hardware fail.**</u>
6+
7+
## Donations
8+
9+
Any code within the namespace "DevCase" is freely distributed as part of "DevCase for .NET Framework" commercial source-code.
10+
11+
Maybe you would like to consider to buy this powerful set of libraries to support me. You can do loads of things with my libraries for a big amount of diverse thematics, not only related to devices and so.
12+
13+
Here is a link to the purchase page:
14+
15+
- https://codecanyon.net/item/elektrokit-class-library-for-net/19260282
16+
17+
Thank you.
18+
19+
## Usage
20+
21+
Usage is very simple, there are 3 classes: **CpuStress**, **DiskStress** and **MemoryStress**, which provides an **Allocate()** method to start stressing resources, and a **Deallocate()** method to stop it.
22+
23+
## Usage Examples
24+
25+
##### CPU Stress
26+
27+
```vbnet
28+
Using cpuStress As New CpuStress()
29+
Dim percentage As Single = 20.5F 20.50%
30+
31+
Console.WriteLine("Allocating CPU usage percentage...")
32+
cpuStress.Allocate(percentage)
33+
Thread.Sleep(TimeSpan.FromSeconds(5))
34+
Console.WriteLine("Instance CPU average usage percentage: {0:F2}%", cpuStress.InstanceCpuPercentage)
35+
Console.WriteLine("Process CPU average usage percentage: {0:F2}%", cpuStress.ProcessCpuPercentage)
36+
Console.WriteLine()
37+
38+
Console.WriteLine("Deallocating CPU usage percentage...")
39+
cpuStress.Deallocate()
40+
Thread.Sleep(TimeSpan.FromSeconds(5))
41+
Console.WriteLine("Instance CPU average usage percentage: {0:F2}%", cpuStress.InstanceCpuPercentage)
42+
Console.WriteLine("Process CPU average usage percentage: {0:F2}%", cpuStress.ProcessCpuPercentage)
43+
End Using
44+
```
45+
46+
![](Preview/CpuStress-Example.png)
47+
48+
##### Disk Stress
49+
50+
```vbnet
51+
Using diskStress As New DiskStress()
52+
Console.WriteLine("Allocating disk I/O read and write operations...")
53+
diskStress.Allocate(fileSize:=1048576) 1 MB
54+
55+
Thread.Sleep(TimeSpan.FromSeconds(10))
56+
57+
Console.WriteLine("Stopping disk I/O read and write operations...")
58+
diskStress.Deallocate()
59+
60+
Console.WriteLine()
61+
Console.WriteLine("Instance disk I/O read operations count: {0} (total of files read)", diskStress.InstanceReadCount)
62+
Console.WriteLine("Process disk I/O read operations count: {0}", diskStress.ProcessReadCount)
63+
Console.WriteLine()
64+
Console.WriteLine("Instance disk I/O read data (in bytes): {0} ({1:F2} GB)", diskStress.InstanceReadBytes, (diskStress.InstanceReadBytes / 1024.0F ^ 3))
65+
Console.WriteLine("Process disk I/O read data (in bytes): {0} ({1:F2} GB)", diskStress.ProcessReadBytes, (diskStress.ProcessReadBytes / 1024.0F ^ 3))
66+
Console.WriteLine()
67+
Console.WriteLine("Instance disk I/O write operations count: {0} (total of files written)", diskStress.InstanceWriteCount)
68+
Console.WriteLine("Process disk I/O write operations count: {0}", diskStress.ProcessWriteCount)
69+
Console.WriteLine()
70+
Console.WriteLine("Instance disk I/O written data (in bytes): {0} ({1:F2} GB)", diskStress.InstanceWriteBytes, (diskStress.InstanceWriteBytes / 1024.0F ^ 3))
71+
Console.WriteLine("Process disk I/O written data (in bytes): {0} ({1:F2} GB)", diskStress.ProcessWriteBytes, (diskStress.ProcessWriteBytes / 1024.0F ^ 3))
72+
End Using
73+
```
74+
75+
![](Preview/DiskStress-Example.png)
76+
77+
##### Memory Stress
78+
79+
```vbnet
80+
Using memStress As New MemoryStress()
81+
Dim memorySize As Long = 1073741824 1 GB
82+
83+
Console.WriteLine("Allocating physical memory size...")
84+
memStress.Allocate(memorySize)
85+
Console.WriteLine("Instance Physical Memory Size (in bytes): {0} ({1:F2} GB)", memStress.InstancePhysicalMemorySize, (memStress.InstancePhysicalMemorySize / 1024.0F ^ 3))
86+
Console.WriteLine("Process Physical Memory Size (in bytes): {0} ({1:F2} GB)", memStress.ProcessPhysicalMemorySize, (memStress.ProcessPhysicalMemorySize / 1024.0F ^ 3))
87+
Console.WriteLine()
88+
Console.WriteLine("Deallocating physical memory size...")
89+
memStress.Deallocate()
90+
Console.WriteLine("Instance Physical Memory Size (in bytes): {0}", memStress.InstancePhysicalMemorySize)
91+
Console.WriteLine("Process Physical Memory Size (in bytes): {0} ({1:F2} MB)", memStress.ProcessPhysicalMemorySize, (memStress.ProcessPhysicalMemorySize / 1024.0F ^ 2))
92+
End Using
93+
```
94+
95+
![](Preview/MemoryStress-Example.png)

Solution/HardwareStress.sln

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2050
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "HardwareStress", "HardwareStress\HardwareStress.vbproj", "{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Debug|x64.ActiveCfg = Debug|x64
21+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Debug|x64.Build.0 = Debug|x64
22+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Debug|x86.ActiveCfg = Debug|x86
23+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Debug|x86.Build.0 = Debug|x86
24+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Release|x64.ActiveCfg = Release|x64
27+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Release|x64.Build.0 = Release|x64
28+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Release|x86.ActiveCfg = Release|x86
29+
{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}.Release|x86.Build.0 = Release|x86
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {B9080CE2-5A3D-4B8D-8160-A52759238D68}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{4DC15B6C-41EF-4B72-96F2-CBE6F647DD4B}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>
10+
</RootNamespace>
11+
<AssemblyName>HardwareStress</AssemblyName>
12+
<FileAlignment>512</FileAlignment>
13+
<MyType>Windows</MyType>
14+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
<PropertyGroup>
17+
<OptionExplicit>On</OptionExplicit>
18+
</PropertyGroup>
19+
<PropertyGroup>
20+
<OptionCompare>Binary</OptionCompare>
21+
</PropertyGroup>
22+
<PropertyGroup>
23+
<OptionStrict>On</OptionStrict>
24+
</PropertyGroup>
25+
<PropertyGroup>
26+
<OptionInfer>Off</OptionInfer>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugSymbols>true</DebugSymbols>
31+
<DebugType>full</DebugType>
32+
<DefineDebug>true</DefineDebug>
33+
<DefineTrace>true</DefineTrace>
34+
<OutputPath>bin\AnyCPU\Debug\</OutputPath>
35+
<DocumentationFile>HardwareStress.xml</DocumentationFile>
36+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
37+
</PropertyGroup>
38+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
39+
<PlatformTarget>AnyCPU</PlatformTarget>
40+
<DebugType>pdbonly</DebugType>
41+
<DefineDebug>false</DefineDebug>
42+
<DefineTrace>true</DefineTrace>
43+
<Optimize>true</Optimize>
44+
<OutputPath>bin\AnyCPU\Release\</OutputPath>
45+
<DocumentationFile>HardwareStress.xml</DocumentationFile>
46+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
47+
</PropertyGroup>
48+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
49+
<PlatformTarget>x64</PlatformTarget>
50+
<DebugSymbols>true</DebugSymbols>
51+
<DebugType>full</DebugType>
52+
<DefineDebug>true</DefineDebug>
53+
<DefineTrace>true</DefineTrace>
54+
<OutputPath>bin\x64\Debug\</OutputPath>
55+
<DocumentationFile>HardwareStress.xml</DocumentationFile>
56+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
57+
</PropertyGroup>
58+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
59+
<PlatformTarget>x64</PlatformTarget>
60+
<DebugType>pdbonly</DebugType>
61+
<DefineDebug>false</DefineDebug>
62+
<DefineTrace>true</DefineTrace>
63+
<Optimize>true</Optimize>
64+
<OutputPath>bin\x64\Release\</OutputPath>
65+
<DocumentationFile>HardwareStress.xml</DocumentationFile>
66+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
67+
</PropertyGroup>
68+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
69+
<PlatformTarget>x86</PlatformTarget>
70+
<DebugSymbols>true</DebugSymbols>
71+
<DebugType>full</DebugType>
72+
<DefineDebug>true</DefineDebug>
73+
<DefineTrace>true</DefineTrace>
74+
<OutputPath>bin\x86\Debug\</OutputPath>
75+
<DocumentationFile>HardwareStress.xml</DocumentationFile>
76+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
77+
</PropertyGroup>
78+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
79+
<PlatformTarget>x86</PlatformTarget>
80+
<DebugType>pdbonly</DebugType>
81+
<DefineDebug>false</DefineDebug>
82+
<DefineTrace>true</DefineTrace>
83+
<Optimize>true</Optimize>
84+
<OutputPath>bin\x86\Release\</OutputPath>
85+
<DocumentationFile>HardwareStress.xml</DocumentationFile>
86+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
87+
</PropertyGroup>
88+
<ItemGroup>
89+
<Reference Include="System" />
90+
<Reference Include="System.Core" />
91+
</ItemGroup>
92+
<ItemGroup>
93+
<Import Include="Microsoft.VisualBasic" />
94+
<Import Include="System" />
95+
<Import Include="System.Collections" />
96+
<Import Include="System.Collections.Generic" />
97+
<Import Include="System.Collections.ObjectModel" />
98+
<Import Include="System.ComponentModel" />
99+
<Import Include="System.Diagnostics" />
100+
<Import Include="System.Drawing" />
101+
<Import Include="System.Globalization" />
102+
<Import Include="System.IO" />
103+
<Import Include="System.Runtime.CompilerServices" />
104+
<Import Include="System.Runtime.InteropServices" />
105+
<Import Include="System.Security.Permissions" />
106+
<Import Include="System.Text" />
107+
<Import Include="System.Threading" />
108+
<Import Include="System.Linq" />
109+
<Import Include="System.Xml.Linq" />
110+
<Import Include="System.Threading.Tasks" />
111+
</ItemGroup>
112+
<ItemGroup>
113+
<Compile Include="Interop\IoCounters.vb" />
114+
<Compile Include="Stress\DiskStress.vb" />
115+
<Compile Include="Stress\CpuStress.vb" />
116+
<Compile Include="Stress\MemoryStress.vb" />
117+
<Compile Include="My Project\AssemblyInfo.vb" />
118+
<Compile Include="My Project\Application.Designer.vb">
119+
<AutoGen>True</AutoGen>
120+
<DependentUpon>Application.myapp</DependentUpon>
121+
</Compile>
122+
<Compile Include="My Project\Resources.Designer.vb">
123+
<AutoGen>True</AutoGen>
124+
<DesignTime>True</DesignTime>
125+
<DependentUpon>Resources.resx</DependentUpon>
126+
</Compile>
127+
<Compile Include="My Project\Settings.Designer.vb">
128+
<AutoGen>True</AutoGen>
129+
<DependentUpon>Settings.settings</DependentUpon>
130+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
131+
</Compile>
132+
<Compile Include="Interop\NativeMethods.vb" />
133+
</ItemGroup>
134+
<ItemGroup>
135+
<EmbeddedResource Include="My Project\Resources.resx">
136+
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
137+
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
138+
<CustomToolNamespace>My.Resources</CustomToolNamespace>
139+
<SubType>Designer</SubType>
140+
</EmbeddedResource>
141+
</ItemGroup>
142+
<ItemGroup>
143+
<None Include="My Project\Application.myapp">
144+
<Generator>MyApplicationCodeGenerator</Generator>
145+
<LastGenOutput>Application.Designer.vb</LastGenOutput>
146+
</None>
147+
<None Include="My Project\Settings.settings">
148+
<Generator>SettingsSingleFileGenerator</Generator>
149+
<CustomToolNamespace>My</CustomToolNamespace>
150+
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
151+
</None>
152+
</ItemGroup>
153+
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
154+
</Project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
' This source-code is freely distributed as part of "DevCase for .NET Framework".
2+
'
3+
' Maybe you would like to consider to buy this powerful set of libraries to support me.
4+
' You can do loads of things with my apis for a big amount of diverse thematics.
5+
'
6+
' Here is a link to the purchase page:
7+
' https://codecanyon.net/item/elektrokit-class-library-for-net/19260282
8+
'
9+
' Thank you.
10+
11+
#Region " Option Statements "
12+
13+
Option Strict On
14+
Option Explicit On
15+
Option Infer Off
16+
17+
#End Region
18+
19+
#Region " IoCounters "
20+
21+
Namespace DevCase.Interop.Unmanaged.Win32.Structures
22+
23+
''' ----------------------------------------------------------------------------------------------------
24+
''' <summary>
25+
''' Contains I/O accounting information for a process or a job object.
26+
''' <para></para>
27+
''' For a job object, the counters include all operations performed by
28+
''' all processes that have ever been associated with the job,
29+
''' in addition to all processes currently associated with the job.
30+
''' </summary>
31+
''' ----------------------------------------------------------------------------------------------------
32+
''' <remarks>
33+
''' <see href="https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_io_counters"/>
34+
''' </remarks>
35+
''' ----------------------------------------------------------------------------------------------------
36+
<DebuggerStepThrough>
37+
<StructLayout(LayoutKind.Sequential)>
38+
Public Structure IoCounters
39+
40+
''' <summary>
41+
''' The number of read operations performed.
42+
''' </summary>
43+
Public ReadOperationCount As Long
44+
45+
''' <summary>
46+
''' The number of write operations performed.
47+
''' </summary>
48+
Public WriteOperationCount As Long
49+
50+
''' <summary>
51+
''' The number of I/O operations performed, other than read and write operations.
52+
''' </summary>
53+
Public OtherOperationCount As Long
54+
55+
''' <summary>
56+
''' The number of bytes read.
57+
''' </summary>
58+
Public ReadTransferCount As Long
59+
60+
''' <summary>
61+
''' The number of bytes written.
62+
''' </summary>
63+
Public WriteTransferCount As Long
64+
65+
''' <summary>
66+
''' The number of bytes transferred during operations other than read and write operations.
67+
''' </summary>
68+
Public OtherTransferCount As Long
69+
70+
End Structure
71+
72+
End Namespace
73+
74+
#End Region

0 commit comments

Comments
 (0)