Skip to content

Commit

Permalink
Merge pull request #32 from OudomMunint/feature
Browse files Browse the repository at this point in the history
PR: feature => master
  • Loading branch information
OudomMunint authored Feb 24, 2024
2 parents 2a508db + 6ee62d0 commit 5215566
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
if: matrix.os == 'windows-latest'
uses: ncipollo/[email protected]
with:
tag: v1.4.7.1
tag: v1.4.8
193 changes: 106 additions & 87 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{

var startInfo = new ProcessStartInfo
{
FileName = "/usr/sbin/system_profiler",
Arguments = " sudo SPHardwareDataType SPDisplaysDataType",
Arguments = "SPHardwareDataType SPDisplaysDataType",
RedirectStandardOutput = true,
UseShellExecute = false
};
Expand All @@ -30,11 +29,13 @@
while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();

Check warning on line 31 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 31 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 31 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Converting null literal or possible null value to non-nullable type.
Console.WriteLine(line);
if (!line.Contains("Serial Number (system):") && !line.Contains("Hardware UUID:") && !line.Contains("Provisioning UDID:"))

Check warning on line 32 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Dereference of a possibly null reference.

Check warning on line 32 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 32 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Dereference of a possibly null reference.
{
Console.WriteLine(line);
}
}

process.WaitForExit();

}

else
Expand All @@ -45,121 +46,139 @@
{
foreach (var item in searcher.Get())
{
Console.WriteLine("[CPU information]");
Console.WriteLine("Processor Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", item["Manufacturer"]);
Console.WriteLine("Core: {0}", item["NumberOfCores"]);
Console.WriteLine("Threads: {0}", item["NumberOfLogicalProcessors"]);
Console.WriteLine("Clock Speed: {0}MHz", item["MaxClockSpeed"]);
Console.WriteLine("L3 Cache: {0}MB", (Convert.ToInt64(item["L3CacheSize"]) / 1024));
Console.WriteLine("Voltage: {0}V", item["CurrentVoltage"]);
Console.WriteLine("-----------------------------------------------------------");
try
{
Console.WriteLine("[CPU information]");
Console.WriteLine("Processor Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", item["Manufacturer"]);
Console.WriteLine("Core: {0}", item["NumberOfCores"]);
Console.WriteLine("Threads: {0}", item["NumberOfLogicalProcessors"]);
Console.WriteLine("Clock Speed: {0}MHz", item["MaxClockSpeed"]);
Console.WriteLine("L2 Cache: {0}MB", (Convert.ToInt64(item["L2CacheSize"]) / 1024));
Console.WriteLine("L3 Cache: {0}MB", (Convert.ToInt64(item["L3CacheSize"]) / 1024));

Check warning on line 58 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
Console.WriteLine("Voltage: {0}V", item["CurrentVoltage"]);
Console.WriteLine("-----------------------------------------------------------");
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while retrieving CPU information: " + ex.Message);
}
}
}

// GET RAM info
// Windows only
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"))
{
// GET total MEM
long totalCapacity = 0;
string manufacturer = null;
foreach (ManagementObject item in searcher.Get())
try
{
totalCapacity += Convert.ToInt64(item["Capacity"]);
manufacturer = item["Manufacturer"].ToString().Trim();
}
// GET total MEM
long totalCapacity = 0;
string manufacturer = null;

Check warning on line 77 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 77 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 77 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Converting null literal or possible null value to non-nullable type.
foreach (ManagementObject item in searcher.Get())
{
totalCapacity += Convert.ToInt64(item["Capacity"]);
manufacturer = item["Manufacturer"].ToString().Trim();

Check warning on line 81 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Dereference of a possibly null reference.

Check warning on line 81 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 81 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Dereference of a possibly null reference.
}

Console.WriteLine("[Memory Information]");
Console.WriteLine("Total Capacity: {0} GB", totalCapacity / (1024 * 1024 * 1024));
Console.WriteLine("Manufacturer: {0}", manufacturer);
Console.WriteLine("[Memory Information]");
Console.WriteLine("Total Capacity: {0} GB", totalCapacity / (1024 * 1024 * 1024));
Console.WriteLine("Manufacturer: {0}", manufacturer);

// GET Capacity per stick
searcher.Query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");
int slotNumber = 1;
foreach (ManagementObject item in searcher.Get())
// GET Capacity per stick
searcher.Query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");
int slotNumber = 1;
foreach (ManagementObject item in searcher.Get())
{
Console.WriteLine();
Console.WriteLine("(Slot {0})", slotNumber++);
Console.WriteLine("Speed: {0} MHz", item["Speed"]);

Check warning on line 95 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 95 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
Console.WriteLine("Capacity: {0} GB", Convert.ToInt64(item["Capacity"]) / (1024 * 1024 * 1024));
}
Console.WriteLine("-----------------------------------------------------------");
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine("(Slot {0})", slotNumber++);
Console.WriteLine("Speed: {0} MHz", item["Speed"]);
Console.WriteLine("Capacity: {0} GB", Convert.ToInt64(item["Capacity"]) / (1024 * 1024 * 1024));
Console.WriteLine("An error occurred while retrieving memory information: " + ex.Message);
}
Console.WriteLine("-----------------------------------------------------------");
}

// Windows specific
// Retrieve GPU information
// iGPU + dGPU
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"))
try
{
foreach (var item in searcher.Get())
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"))
{
var manufacturer = item["AdapterCompatibility"].ToString();
var VideoMemoryType = item["VideoMemoryType"].ToString();
if (manufacturer.ToLower().Contains("intel") || manufacturer.ToLower().Contains("amd"))
{
Console.WriteLine("[Integrated GPU]");
Console.WriteLine("Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", manufacturer);
Console.WriteLine("Driver Version: {0}", item["DriverVersion"]);
Console.WriteLine("VRAM: {0}MB", Convert.ToUInt64(item["AdapterRAM"]) / (1024 * 1024));
Console.WriteLine("-----------------------------------------------------------");
}
else
foreach (var item in searcher.Get())
{
Console.WriteLine("[Dedicated GPU]");
Console.WriteLine("Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", manufacturer);
Console.WriteLine("Driver Version: {0}", item["DriverVersion"]);
var manufacturer = item["AdapterCompatibility"].ToString();
var VideoMemoryType = item["VideoMemoryType"].ToString();
if (manufacturer.ToLower().Contains("intel") || manufacturer.ToLower().Contains("amd"))

Check warning on line 117 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Dereference of a possibly null reference.

Check warning on line 117 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 117 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Dereference of a possibly null reference.
{
Console.WriteLine("[Integrated GPU]");
Console.WriteLine("Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", manufacturer);
Console.WriteLine("Driver Version: {0}", item["DriverVersion"]);
Console.WriteLine("VRAM: {0}MB", Convert.ToUInt64(item["AdapterRAM"]) / (1024 * 1024));
Console.WriteLine("-----------------------------------------------------------");
}
else
{
Console.WriteLine("[Dedicated GPU]");
Console.WriteLine("Number of GPUs: {0}", searcher.Get().Count);
Console.WriteLine("Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", manufacturer);
Console.WriteLine("Driver Version: {0}", item["DriverVersion"]);
}
}
}
}

using (var factory = new Factory1())
{
using (var adapter = factory.GetAdapter(0))
using (var factory = new Factory1())
{
var desc = adapter.Description;
Console.WriteLine("Total VRAM: {0}MB", desc.DedicatedVideoMemory / (1024 * 1024));
using (var adapter = factory.GetAdapter(0))
{
var desc = adapter.Description;
Console.WriteLine("Dedicated GPU Memory", desc.DedicatedVideoMemory / (1024 * 1024));
Console.WriteLine("Shared GPU Memory: {0}MB", desc.SharedSystemMemory / (1024 * 1024));
Console.WriteLine("-----------------------------------------------------------");
}
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while retrieving GPU information: " + ex.Message);
}

Console.Write("Continue to benchmark? (y/n): ");
var input = Console.ReadLine();
if (string.Equals("y", "Y"))
{

Console.WriteLine("Choose a benchmark to run:");
Console.WriteLine("1. Hashing Benchmark");
Console.WriteLine("2. Encryption Benchmark");
Console.WriteLine("3. Multithreading Benchmark");
Console.WriteLine("4. Run all benchmarks");
Console.Write("Enter the number of your choice: ");

string choice = Console.ReadLine();

switch (choice)
{
case "1":
var hashingSummary = BenchmarkRunner.Run<HashingBenchmark>();
break;

case "2":
var encryptionSummary = BenchmarkRunner.Run<EncryptionBenchmark>();
break;
if (string.Equals(input, "y", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Choose a benchmark to run:");
Console.WriteLine("1. Hashing Benchmark");
Console.WriteLine("2. Encryption Benchmark");
Console.WriteLine("3. Multithreading Benchmark");
Console.WriteLine("4. Run all benchmarks");
Console.Write("Enter the number of your choice: ");

case "3":
var multithreadingSummary = BenchmarkRunner.Run<MultithreadingBenchmark>();
break;
string choice = Console.ReadLine();

Check warning on line 165 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 165 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 165 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Converting null literal or possible null value to non-nullable type.

case "4":
var runAll = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAllJoined();
break;
var benchmarkActions = new Dictionary<string, Action>
{
["1"] = () => BenchmarkRunner.Run<HashingBenchmark>(),
["2"] = () => BenchmarkRunner.Run<EncryptionBenchmark>(),
["3"] = () => BenchmarkRunner.Run<MultithreadingBenchmark>(),
["4"] = () => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAllJoined()
};

default:
Console.WriteLine("Invalid choice.");
break;
}
}
if (benchmarkActions.TryGetValue(choice, out Action benchmarkAction))

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Possible null reference argument for parameter 'key' in 'bool Dictionary<string, Action>.TryGetValue(string key, out Action value)'.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Possible null reference argument for parameter 'key' in 'bool Dictionary<string, Action>.TryGetValue(string key, out Action value)'.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Possible null reference argument for parameter 'key' in 'bool Dictionary<string, Action>.TryGetValue(string key, out Action value)'.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Converting null literal or possible null value to non-nullable type.
{
benchmarkAction.Invoke();
}
else
{
Console.WriteLine("Invalid choice.");
}
}
}
Loading

0 comments on commit 5215566

Please sign in to comment.