WMI query to find CPU usage for each core - powershell-2.0

Is there a WMI/Power-shell query for finding out CPU usage for each different core.
I had used "select LoadPercentage from Win32_Processor", but it gives only one value , say 65. But I wish to have Four different values, if My PC have four cores.
It seems I have got the solution
I just found "SELECT Name, percentprocessortime FROM Win32_PerfFormattedData_Counters_ProcessorInformation" this query, I think it will solve my issue. Please correct me If I am wrong..
Regards
Sebastian

Win32_PerfFormattedData_Counters_ProcessorInformation is better one. However still i have doubt on how it will behave in multiple physical processor environment. For more info on that, please check below thread.
CPU load percentage for individual processors

Related

Why is Application Insights Performance Counter Collection causing high CPU usage

Logging performed by our Performance Team has indicated that this line specifically, is killing our CPUs
Microsoft.AI.PerfCounterCollector!Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.Implementation.PerformanceCounterUtility.ExpandInstanceName()
One theory was the the regexes used to identify Perf Counters in the library are recursing
https://adtmag.com/blogs/dev-watch/2016/07/stack-overflow-crash.aspx
I've inspected the Perf Counter names and nothing looks particularly out of kilter regarding the names and the regexes should have no trouble chewing over them. Certainly for large periods of time there are no issues whatsoever.
I've now turned on Applications Insights Diagnostic Logging in an attempt to observe the issue (in a test environment)
Has anyone else observed this, how can we mitigate this?
We have ensured DeveloperMode is NOT set to on.
this answer most likely won`t be usable now as AppInsights 2 code is much improved, but in my case it was double call AddApplicationInsightsTelemetry(). It adds collector each time this method is called, and due to lack of synchronization inside perf counter collector code it creates CPU spikes.
So avoid calling multiple times AddApplicationInsightsTelemetry, or use AppInsights 2.x. (and the best thing is to do both).
Do the counters you're collecting utilize instance placeholders in their names? If the instance name is known at build time, getting rid of placeholders may significantly improve performance. For instance, instead of
\Process(??APP_WIN32_PROC??)\% Processor Time
try using
\Process(w3wp)\% Processor Time
Also, how many counters are you collecting overall?

Spreadsheet Gear -- Generating large report via copy and paste seems to use a lot of memory and processor

I am attempting to generate a large workbook based report with 3 supporting worksheets of 100,12000 and 12000 rows and a final output sheet all formula based that ends up representing about 120 entities at 100 rows a piece. I generate a template range and copy and paste it replacing the entity ID cell after pasting each new range. It is working fine but I noticed that memory usage in the IIS Express process is approx 500mb and it is taking 100% processor usage as well.
Are there any guidelines for generating workbooks in this manner?
At least in terms of memory utilization, it would help to have some comparison, maybe against Excel, in how much memory is utilized to simply have the resultant workbook opened. For instance, if you were to open the final report in both Excel and the "SpreadsheetGear 2012 for Windows" application (available in the SpreadsheetGear folder under the Start menu), what does the Task Manager measure for each of these applications in terms of memory consumption? This may provide some insight as to whether the memory utilization you are seeing in the actual report-building process is unusually high (is there a lot of extra overhead for your routine?), or just typical given the size of the workbook you are generating.
In terms of CPU utilization, this one is a bit more difficult to pinpoint and is certainly dependent on your hardware as well as implementation details in your code. Running a VS Profiler against your routine certainly would be interesting to look into, if you have this tool available to you. Generally speaking, the CPU time could potentially be broken up into a couple broad categories—CPU cycles used to "build" your workbook and CPU cycles to "calculate" it. It could be helpful to better determine which of these is dominating the CPU. One way to do this might be to, if possible, ensure that calculations don't occur until you are finished actually generating the workbook. In fact, avoiding any unnecessary calculations could potentially speed things up...it depends on the workbook, though. You could avoid calculations by setting IWorkbookSet.Calculation to Manual mode and not calling any of the IWorkbook’s "Calculate" methods (Calculate/CalculateFull/CalculateFullRebuild) until you are fished up with this process. If you don't have access to a Profiler too, maybe set some timers, Console.WriteLines and monitor the Task Manager to see how your CPU fluctuates during different parts of your routine. With any luck you might be able to better isolate what part of the routine is taking the most amount of time.

In iOS, how do I get the current CPU Utilization from inside an app that is running?

I'm looking for a way to get the CPU Utilization numbers like in Instruments and Activity Monitor with C/C++/Obj-C so I can do some automated testing with it. I'm looking for somewhere around a 1 second granularity, though 100 ms would be ideal. Another way to look at this question would be "How does Activity Monitor get the info it gets?".
Here's what I have found out so far:
Many of the *nix equivalents don't seem to work with iOS
sysctl
doesn't have KERN_CPTIME
iOS doesn't have the proc filesystem so I can't use
/proc/stat.
This eliminates a lot of programs like vmstat and iostat
MacOSX's
sample
doesn't exist in iOS.
I found out the answer. There is an undocumented API, host_processor_info() with the PROCESSOR_CPU_LOAD_INFO flavor, that can give you the number of system, user, nice, and idle ticks. You have to subtract the number of ticks from a previous call to it to get the current CPU utilization. Remember to call vm_deallocate on the array you get.
You cannot. The standard Un*x access to this information is not available within an iOS app.

How to profile an Erlang program in terms of memory usage?

I would like to further enhance the efficiency of an existing Erlang program. First I would like to identify bottlenecks and then decide on where to further optimize.
I have tryed fprof, but it only gives information on total and average runtime. I would most like to see a log similar to the output of fprof, but in terms of average and total memory usage with respect to functions and processes.
For starters it would be enough to profile a single module, that does not spawn processes, only it's functions would be called. This would already help, for I could separate the program to distinct modules for testing.
Typical suspicious points are, where bigger lists are being handled.
Here the usage of ++ has been resolved by lists:reverse([Head|Tail]) like syntax.
I am also considering using ETS tables instead of Lists for cases with more than a few hundred elements.
Thank You in advance!
Doing some advertising for my own sake: I wrote a little erlang gen_server a while ago, that records and logs system statistics, combined with a little perl script that parses them and outputs pretty charts.
I've found it pretty useful for doing memory watching etc. under load, as it allows you to continuously monitor a detailed view of the memory usage, while for instance testing different things.
The erlang part is fairly non-intrusive, a simple gen_server that you can start from anywhere, you can just put it under your supervision tree. You can configure the poll frequency etc, and it will write statistics to a file in a simple json format.
The perl script then runs over it, and aggregates the logs to draw charts. There are base-classes, and if you know a little perl, you can easily write a class to log and chart any custom parameter you want.
The script can be obtained from: https://github.com/Amadiro/erlang-statistics
Sample chart (Erlang node that leaks atoms): Sample Chart http://monoc.mo.funpic.de/ram-usage-vs-time.png
Hope this helps you :)
The perfect starting point is the Profiling section from the Erlang Efficiency Guide:
http://www.erlang.org/doc/efficiency_guide/profiling.html
#brainiac, I'm posting new url for erlang-statistics repo on github: https://github.com/Amadiro/erlang-statistics (found it by search ;-)).
As a more production-ready solution I can recommend collectd erlang client https://github.com/athoune/erlang-collectd if you really need some sort of total memory consumption graphs.
But for more granular memory information you can use process_info(Pid, [memory]) to get memory information for a specific Pid and shell command i() for list of all processes with memory and runtime information.
There is also such utilite as etop.
But there is no such profiler like fprof, but for memory usage.
Refer to http://www.erlang.org/faq/how_do_i.html#id52731 for details.

concurrent write to same memory address

If two threads try to write to the same address at the same time, is the value after the concurrent write guaranteed to be one of the values that the threads tried to write? or is it possible to get a combination of the bits?
Also, is it possible for another thread to read the memory address while the bits are in an unstable state?
I guess what the question boils down to is if a read or write to a single memory address is atomic at the hardware level.
I think this all depends on the "memory model" for your particular programming language or system.
These questions are fundamentals of a system or/and programming language memory model. Therefore, pick your own OS and a programming language, read the specs and you'll see.
In some cases the results may be just as unpredictable when the two threads are writing to different memory addresses - in particular think about C bitfield structures, as well as compiler optimisations when writing to adjacent addresses.
If you fancy a read, Boehm's paper "Threads cannot be implemented as a library" covers this and other quirks of concurrency.
One thing for sure, for a datatype of size equal to CPU Registers can never have bits in unstable state, it will be either of the two values
On a multi-processor computer, there may not be a single "value" that is read. The two threads, and the third one, may see inconsistent values. You'd need a memory barrier to ensure every thread sees the same value at this address.
Apart from that, writes are generally atomic, so it would be either one or the other of the values that have been written (or were there in the first place) that are read. You're not talking about an Alpha processor, are you?

Resources