parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BUG: swap_activity broken in v20120322


From: Benjamin R. Haskell
Subject: Re: BUG: swap_activity broken in v20120322
Date: Fri, 30 Mar 2012 10:24:16 -0400 (EDT)
User-agent: Alpine 2.01 (LNX 1266 2009-07-14)

On Fri, 30 Mar 2012, Thomas Sattler wrote:

vmstat 1 2 2>/dev/null | tail -n1 | awk '{print $7*$8}' ||
  vm_stat 1 | head -n 3 | tail -n1 | awk '{print $9*$10}'

Better `awk` usage:

vmstat 1 2 2>/dev/null | awk 'END {print $7*$8}' ||
vm_stat 1 | awk 'NR == 3 {print $9*$10 ; exit}'

Still the same problem: Whether 'vm_stat' is run depends on the success of 'awk', not 'vmstat'. (At least under bash.)

Right.  But at least we're not relying on `head` and `tail`.


If somebody would reply with the output of 'vm_stat', I'd offer a patch to fix the issue. (I don't have a MAC.)

osx-server$ vm_stat 1
Mach Virtual Memory Statistics: (page size of 4096 bytes, cache hits 0%)
   free active   spec inactive   wire   faults     copy    0fill reactive  
pageins  pageout
  70547 442624  29441    88468 415463   14321M  518664K 2448176K   683760  
1460755   367311
  70658 442657  29440    88468 415463      139        0      136        0       
 1        0
  70729 442660  29440    88468 415463      145        0       73        0       
 0        0
  70461 442660  29440    88468 415463      388       69      134        0       
 0        0
  70478 442649  29440    88468 415463       16        0        6        0       
 0        0
[...etc...]

This was the fourth reply with the output of 'vm_stat',

(Were any of those replies on-list? The Parallel mailing list is the only one I'm on where I feel as if I'm consistently missing messages, despite having a filter to keep them out of spam...)


so here is some code that should do the job:

  { vmstat 1 2> /dev/null || vm_stat 1; } | awk '
    NR!=4{next}
    NF==16{print $7*$8}
    NF==11{print $10*$11}
    {exit}
  '
I'm running 'vmstat' (and 'vm_stat' in case 'vmstat' failed) and pipe the output to 'awk' which knows where the relevant information is:

 vmstat  (16 fields per line):  field7  * field8
 vm_stat (11 fields per line):  field10 * field11

Looks good to me.


By the way: In all four replys I got, the relevant information ("pageins" and "pageout") was in field 10 / 11, never 9 / 10.

Also I had to use line number 4 as the output of 'vmstat' and 'vm_stat' both have two lines of headers and have non-zero values in their first data line. (see above)

Sounds reasonable. Presumably the first line is the total since boot time, which doesn't provide any useful information about the current state of the system.


Thomas

P.S.: Why do we use 'awk' within 'perl'?

Because it runs on the remote machine, and `awk` has less overhead than `perl`. (Though since it's waiting for at least 1 second to gather stats, it may not be a significant overhead.)

--
Best,
Ben



reply via email to

[Prev in Thread] Current Thread [Next in Thread]