I am trying to get all the sensors that OpenHardwareMonitor can give.
But i get almost all load type sensors ando not many temperature sensors:
This is my code:
{
Computer myComputer = new Computer();
myComputer = new Computer()
{
CPUEnabled =
true
};
myComputer.Open();
Trace.WriteLine("");
foreach (var hardwareItem in myComputer.Hardware)
{
if (hardwareItem.HardwareType == HardwareType.CPU)
{
hardwareItem.Update();
foreach (IHardware subHardware in hardwareItem.SubHardware)
subHardware.Update();
foreach (var sensor in hardwareItem.Sensors)
{
Debug.WriteLine(sensor.Name + " " + sensor.SensorType + " " + sensor.SensorType);
}
}
}
}
This is the result i get:
CPU Core #1 Load Load
CPU Core #2 Load Load
CPU Core #3 Load Load
CPU Core #4 Load Load
CPU Core #5 Load Load
CPU Core #6 Load Load
CPU Core #7 Load Load
CPU Core #8 Load Load
CPU Core #9 Load Load
CPU Core #10 Load Load
CPU Core #11 Load Load
CPU Core #12 Load Load
CPU Core #13 Load Load
CPU Core #14 Load Load
CPU Core #15 Load Load
CPU Core #16 Load Load
CPU Total Load Load
But i would like to get the CPU Temp and Volt, but i cant figure out a way to get them, also just to mention that if i use open hardware monitor app i can see all the sensors correctly.
Thanks so much for the help!
I have tried lots of tutorials, done the same in a subhardware loop but nothing shows up
It might be that your hardware is not supported by OpenHardwareMonitor. There is a list of supported hardware on their page.
Also you might need to run your app as Administrator to get the required information. I was able to get the temperature sensors in the list, but without values. And I saw the values by running as administrator.
Ive managed to fix it.
I was not implementing Ivisitor and LibreHardwareMonitor seems to be the updated version of the dll (i had to got it via nuget as it has to update some independeces)
Here i found the example code with the Ivisitor implemented:
https://github.com/LibreHardwareMonitor/LibreHardwareMonitor
Related
I am trying to make a Unity game with their new MLAPI (Mid-level networking API). I've followed this tutorial exactly without changing anything, and the game is running fine on my local (Linux) PC.
I changed the connection IP and copied the build file over to a cloud server I rent (DigitalOcean Ubuntu 20.04), and used the flag -mlapi server, and the -batchmode -nographics options, but I still suspect it is trying to emulate graphics on the CPU.
The 100% CPU problem seems to be documented and the suggested solution is including the line Application.targetFrameRate = 30;. I tried doing the following (targetFrameRate is ignored if vSync is not disabled):
switch (mlapiValue)
{
case "server":
netManager.StartServer();
// https://docs-multiplayer.unity3d.com/docs/troubleshooting/troubleshooting
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 1;
break;
case "host":
netManager.StartHost();
break;
case "client":
netManager.StartClient();
break;
}
However, when I move the client, I still get 100% CPU (with of course the additional bonus of each action being executed instantly on the server(!?) but 1 second later on each client).
What is even going on here? Someone online suggested it might be related to socket polling, but when I start 2 instances one of them gets killed (out of CPU). Note that the single server still seems pretty responsive.
This issue only seems to occur on Linux machines with exactly 1 core. I tried reducing fps to 1 on a single-core, which did reduce CPU below 5%, but only if I start a single server (e.g. on port 7778). Once I start a second server on port 7779, we are back at 100% CPU. In summary:
Setup
Outcome
1 core, 60 fps, 1 instance
100% CPU (bad)
1 core, 1 fps, 1 instance
<5% CPU (OK)
1 core, 1 fps, 2 instances
100% CPU (bad)
2 cores, 60 fps, 10+ instances
<10% CPU (OK)
So my recommendation is to just rent a cloud instance with 2+ vCPUs.
When viewing the .Net performance counters using the Performance tool I can see the web process performance counters listed (w3wp, w3wp#1):
However when I run the following code as Administrator:
var instanceNames = new PerformanceCounterCategory(".NET CLR Memory")
.GetInstanceNames()
.OrderBy(x => x);
foreach (var name in instanceNames)
{
Console.WriteLine(name);
}
This is the output I see:
Notice the w3wp counters are not listed. Does anyone know why this is the case and how I can fix it?
The solution was you have to run the application in the same bitness as your website. As my website was 64 bit I needed to run the console application in 64 bit mode. To do this right click on the console application project, click properties in the Build tab untick the box that says "Prefer 32-bit".
Also when you collect the process id for the w3wp process by using the Process ID counter inside the .NET CLR Memory category it is zero to begin with. To get the process id you have to initialize the web site and make sure at least one garbage collection happens. As this was in my test code I could simply call GC.Collect in the Application_Start handler.
I am writing a piece of code whereby I am to iterate through the list of modules loaded by the System process (PID : 4). The following is the code I am using to achieve it.
Process process = Process.GetProcessById(4);
foreach (ProcessModule pMod in process.Modules)
{
Console.Write(pMod.FileName + " ");
}
Console.WriteLine();
This code is throwing an error of System.ComponentModel.Win32Exception, whenever it is trying to evaluate the list of Modules. In effect, any property read or method call is throwing the same error. Any other process is working fine and it is able to list all the modules correctly. Could anyone shed light on what might be causing this behavior.
The System "process" (with PID 4 on Windows machines) is actually not a process at all, it denotes a group of processes that have SYSTEM integrity.
Try to work with a real process PID (for instance, run Internet Explorer, and use it's PID) instead, see if you`ll get the exception.
The system process is not a real user mode process, it is the Windows kernel (for want of a better description). Therefore it cannot be examined as if it were a normal process.
I am having a task of scanning all the folders name start with "xyz" parallely. I meant if one folder getting scan same time other one should also getting scan. I don't want one by one scanning.
For that I used Parallel Foreach.
Question is?
Is it correct or not? and How to know is it running parallely(to put any message some where)?
Parallel.ForEach(path, currentPath =>
{
var output = programReader.GetData(currentPath, durReader.dirPattern);
foreach (var item in output)
{
foreach (var project in item.Name)
Console.WriteLine(item.serverName + " " + item.serverNumber + " " + fileName);
}
}
EDIT:
Is Parallel.Foreach only works on multicore systems or it could work on single core system also to perform show parallelism
Foirst - if you ask a question, make it a question. !! is a good indication it is not a question.
Second, your approach makes little sense. Parallel will go VERY parallel. Good. Bad: you still have only one disc. Result: tasks waiting. It makes no sense to paralellize IO operations over the degree supported by the hardware.
The Parallel extensions split the load per core - although I'm not sure if they take into account hyperthreaded cores.
But, to add another answer to steer you in the right direction:
Don't try and do this in parallel. The disk can only serve one request at a time, so you're likely to just slow everything down as the disk queue is just likely to get bigger.
The only scenario where you might be able to get increased performance is if the location you're scanning is actually a SAN where the storage is distributed and highly replicated.
You can print the Thread.ManagedThreadId value to see which threads are being used.
Parallel.ForEach or Parallel.Execute uses the cores of the processor. So if your processor is having more thn one core they will be used equally to run this thread. Here you are m
I am working on a background program that will be running for a long time, and I have a external logging program (SmartInspect) that I want to feed with some values periodically, to monitor it in realtime when debugging.
I know I can simply fire up multiple programs, like the Task Manager, or IARSN TaskInfo, but I'd like to keep everything in my own program for this, as I also wants to add some simple rules like if the program uses more than X% CPU, flag this in the log.
I have a background thread that periodically feeds some statistics to SmartInspect, like memory consumption, working set, etc.
Is it possible for this thread to get a reasonably accurate measure of how much of the computer's CPU resources it consumes? The main program is a single-threaded application (apart from the watchdog thread that logs statistics) so if a technique is limited to how much does a single thread use then that would be good too.
I found some entries related to something called rusage for Linux and C. Is there something similar I can use for this?
Edit: Ok, I tried the performance counter way, but it added quite a lot of GC-data each time called, so the graph for memory usage and garbage collection skyrocketed. I guess I'll just leave this part out for now.
You can also use System.Diagnostics.Process.TotalProcessorTime and System.Diagnostics.ProcessThread.TotalProcessorTime properties to calculate your processor usage as this article describes.
Have a look at System.Diagnostics.PerformanceCounter. If you run up perfmon.exe, you'll see the range of performance counters available to you (set the 'performance object' to 'Process'), one of which is '% Processor Time'.
You can through the System.Diagnostic.PerformanceCounter class. Here's an example of somebody monitoring CPU usage:
http://blogs.msdn.com/dotnetinterop/archive/2007/02/02/system-diagnostics-performancecounter-and-processor-time-on-multi-core-or-multi-cpu.aspx
Note that this does require elevated privileges. And there may be a performance hit using it.
It is good that you are logging to monitors like smartinspect. But windows itself gathers the data for each resource in this case your program (or process). WMI is the standard for Application monitoring. We can view the data captured by WMI. Many application management, health monitoring or applicaiton monitoring tools support WMI out of the box.
So I would not recommend you to log your CPU usage within the application to a log file.
If you think availablity and performance is critical then go for solutions like Microsoft Operations manager solution.
To get an idea about WMI and to get the list of process see below:
- Win32_PerfFormattedData_PerfProc_Process to get Cpu time, filter is processID
See this article
- You can get the processID from Win32_process class.
WMI Made Easy For C# by Kevin Matthew Goss
oConn.Username = "JohnDoe";
oConn.Password = "JohnsPass";
System.Management.ManagementScope oMs = new System.Management.ManagementScope("\\MachineX", oConn);
//get Fixed disk stats
System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3");
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs,oQuery);
//Get the results
ManagementObjectCollection oReturnCollection = oSearcher.Get();
//loop through found drives and write out info
foreach( ManagementObject oReturn in oReturnCollection )
{
// Disk name
Console.WriteLine("Name : " + oReturn["Name"].ToString());
// Free Space in bytes
Console.WriteLine("FreeSpace: " + oReturn["FreeSpace"].ToString());
// Size in bytes
Console.WriteLine("Size: " + oReturn["Size"].ToString());
}
You can monitor the process from Remote system as well.
This code project article describes how to use the high performance timer:
http://www.codeproject.com/KB/cs/highperformancetimercshar.aspx
You can use it to time the execution of your code.
Here you can find a number of open source C# profilers:
http://csharp-source.net/open-source/profile