In the following code I am printing all processes's CPU and RAM usage, however I only want this data for a certain few processes. For example instead of seeing in my output:
__DATA__ Name => ---- SymSPort.exe WorkingSetSize => -------------- 348160 KernelModeTime => -------------- 0.0625 UserModeTime => ------------ 0.046875 Name => ---- uphclean.exe WorkingSetSize => -------------- 155648 KernelModeTime => -------------- 0.03125 UserModeTime => ------------ 0.03125 ... ... ... and another proccess name and another process name....
I only want to see this data for a selected few process names; can we say grep? Tried an HoA, but the output was all garbbled together. Any ideas? thank you
use strict; use warnings; use Win32::Process::Info; use Data::Dumper; my $pio_2 = Win32::Process::Info->new (); my @pids = $pio_2->ListPids (); my @proc_info; for my $pid (@pids) { @proc_info = $pio_2->GetProcInfo($pid); for my $info (@proc_info) { for my $key (keys %{$info}) { if ($key eq 'Name' or $key eq 'WorkingSetSize' or $key eq 'UserModeTime' or $key eq 'KernelModeTime') { my $value = ${$info}{$key}; print qq(\n$key => \n), q(-) x length $key, qq(\n$value \n); } ## END IF } } }

In reply to Win32... CPU/RAM usage by mikejones

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.