I am trying to create a program which displays the current CPU % Usage data you would see in task manager. I am using the command from this question:
#for /f "skip=1" %p in ('wmic cpu get loadpercentage') do #echo %p%
Specifically I am running this command through a C# .NET program but I get the same results either way.
My problem is that, while the numbers occasionally make sense, they are generally wrong when compared side by side with Task Manager.
e.g. Task Manager displays 54% usage while my code displays 21% or something like that.
Can anyone explain this? I have tried using the System.Diagnostics PerformanceCounters in C# but it doesn't give my the data I want. Thanks in advance
Related
I have this problem:
I run some large calculations before going to sleep (or work).
When I return sometimes RAM is already filled and the program starts writing to Disk, which is a problem since then computer becomes almost non responsive, also the button "Interrupt the current operation" doesn't stop mserver.exe from executing a task.
This is what I saw 10 mins after I pressed the button "Interrupt the current operation":
Not to mention that calculations are probably like 100 or even 1000 times slower when it starts using Disk instead of RAM (so it's pointless anyway).
Another problem is that I was unable to save some variables to file since in Maple I couldn't type anything while mserver.exe was executing a task and after I killed the process mserver.exe I was still unable to save those variables since Maple commands don't work when connection to kernel is lost.
So, my question: can I make it so that mserver.exe won't use Disk at all (I mean from Maple alone, not by disabling page file in Windows) and just stop execution automatically when RAM is full (just like Classic Maple does when it hits 2GB limit)?
Also it would be nice to be able to limit Maple from using processor too much, for example up to 75% or so, so that I could work on that computer without problems.
You might experiment with a few of the options available for specifying limits on the Maple (kernel, mserver) engine.
In particular,
--init-reserve-mem=memorysize
(or, possible, the -T option). See here for some more detail:
https://www.maplesoft.com/support/help/MapleSim/view.aspx?path=maple
On Linux/OSX you could pass that in a call to the maple script that launches Maple. On MS-Windows you could add that to the command string/Property in the launcher (icon).
You might try setting it to a fraction of your total RAM, eg. 50-75%, and see how it goes. Presumably you'll have some other processes running.
As far as restricting the CPU use goes, that's more of a OS issue. On Linux/OSX you could use the system's nice facility. I don't know what's avaliable on MS-Windows (built-in or 3rd party). You might be able to set the Priority of the running mserver process from the Task Manager. Or you might look at something like the START facility:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/start
I installed NYTProf and ran my code using it. Trying to get a simple listing of lines and time spent on them. Good Lord, all this profiler has is html file reports or data dumps designed for import into data analysis tools. I'm working on a remote system and firing up a browser to load file:/// URLs requires setting up tunnels and remote (slow) x-servers etc. it's is a pain in the butt. All's I want is a simple:
Function:Line percentage-time-spent (sorted with longest time spent lines at the top)
openlogs:27 40%
readlogs:124 30%
closelogs:1243 20%
profile:67 10%
You know, a profiler.
This is perl. It's not UX demonstration time. I'm not preparing a report for a Congressional sub-committee.
The documentation doesn't seem to show a way to get a simple report designed for developers to show which slowness to attack in their code. Am I missing something here? Anyone know a way to do this quickly?
The way to get a simple profiler output is to use Devel::Profile
$ perl -d:Profile my_script.pl
$ cat prof.out
As the title says, how can we see the memory that was used on a .m file(including functions) on MATLAB? Is there some command or something?
I would like to use it as a metric in my algorithm.
Thank you
At the command line, execute
profile -memory on;
and start the Matlab profiler as normal to see memory usage. However, you may need to copy information manually
There may be some alternatives, such as mtic and mtoc, depending on your Matlab version, which may allow feeding the data directly to a non-GUI output.
You can also start the profiler from the Editor Menu (at the top task bar of MATLAB GUI).
When you start the profiler, the codes executes normarly but when it exits/ends then the MATLAB displays all sorts of information that you want.
Including (but not limited to):
execution time
calls made
memory (I think! :P )
Got stuck with one problem in our live server.
Have script (perl) which runs almost 15 to 18 hrs a day. it creates 100+ sub process every day . One place it has command (product command which we run in command line solaris box) which is being triggerred with back ticks inside perl code.
It looks like the back ticks command gets skipped or failed randomly.
for eg. if i need to run for 50 customers 2 or 3 gets failed randomly.
I do not see the evidence that the command has been triggerred in anywhere.
since its live server we can't even try making much in code change until we are sure about the problem.
here is the code..
my $comm = "inventory -noX customer1"; #sample command i have given here
my $newLogFile = "To capture command output here we have path whre the file gets created");
my $piddy = `$comm 2>&1 > $newLogFile`;
Is it because of the back ticks it happens I am really not sure :(.
Also tried various analysis like memory/CPU/diskspace/Adding librtld_db.so in LD_LIBRARY_PATH etc....but no luck...Also the perl is in 64 bit ...what else Can i? :(
I suspect you are not checking for errors (and perl doesn't make that easy to do correctly for backticks).
Consider using IPC::System::Simple's capture in place of your backticks/qx.
As its doc says, "If there's an error, it will die with a detailed description of what went wrong."
It shouldn't fail just because of backticks, however because it is spawning a new process, that process may be periodically subject to failure due to system conditions (eg. sysLoad). Backticks are really a "fire and forget" method and should never be used for anything critical in a production environment. As previously suggested, there are far more detailed ways to manage spawning external processes.
If the command's output is being lost due to buffering, you might try turning off buffering, but keep an eye on it for performance degradation (it's usually not significant).
Buffering can be turned off for an entire script by adding this near the top:
$|=1;
When calling external commands, I'm using system of IPC::System::Simple or open3 of IPC::Open3.
I'm trying to find a way to start a perl process up under the debugger, but have in just start running automatically without stopping at the first statement and having me enter 'c' to start it. This module is run by a larger system and I need to be able to periodically (based on external conditions) interrupt the program via interrupt signal, examine some data structures and have it continue.
Obviously, I can have the supervising program start my process using "perl -d myProcess", but how to get it to just run without the initial break. Anybody know how to get this to happen?
Much Thanks.
Thanks. That was a big hint. I see several options including "NonStop".
It looks like using the line PERLDB_OPTS="NonStop" perl -d myprog.pl & does the trick. Then I just kill -INT <pid> and fg it to get it up in the debugger. After I 'c' to continue executing and bg it so it will continue.
You can also add this config option to the .perldb file. The format of the config file is a bit unusual and not so well documented, so here goes
DB::parse_options("NonStop=1");
Other useful options:
DB::parse_options("dumpDepth=3");
DB::parse_options("PrintRet=0");
$DB::deep = 1000;