Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Memeory usage output KB to MB conversion

by tomasz (Acolyte)
on Jun 05, 2021 at 19:53 UTC ( #11133565=note: print w/replies, xml ) Need Help??


in reply to Memeory usage output KB to MB conversion

This should help you find a less chaotic direction. The code is not complete and some bits are not along your wish, but the code is plastic.

You need to improve the value transformation and commation-commification function (rc in the code). 1024 MB is 1073741824 bytes (1024 ** 3), not 1024 * 1000 * 1000.

As for the comma or commas, there might be such a printf option. I'm not sure, but wouldn't be surprised.

This function will also integrate nicely with translation to other measure bases (GB or whatever).
sub rc { my $n = int shift()/1024; $n =~ s/(\d+?)(\d{3})$/$1,$2/; return $n; } s/([^:]+:)\s+(\d+)\s+KB/ sprintf "%-14s%10s MB", $1, rc($2)/e; s/^\=+$/"=" x 68/e; my $IMCfmt = "%-17s%17s%17s%17s"; s/^(Name)\s+(Mem Used)\s+\(KB\)\s+(HWM Used)\s+\(KB\)\s+(Cached)\s+\(K +B\)/ sprintf $IMCfmt, $1, $2." (MB)", $3." (MB)", $4." (MB)"/e; s/^([APPL-|DBMS-|FMP_|PRIVATE|DB-]\S*)\s+(\d+)\s+(\d+)\s+(\d+)/ sprintf $IMCfmt, $1, rc($2), rc($3), rc($4)/e;
I FORGOT: I used the -p switch on the command line instead of the -n. (That's where all the prints are.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133565]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2022-09-30 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?