From: uriel@cat-v.org
To: 9fans@cse.psu.edu
Subject: Re: [9fans] Re: patch/list sorry/proc-mtime
Date: Thu, 30 Mar 2006 19:32:30 +0200 [thread overview]
Message-ID: <182d0fe6c1a48fc89b095d00ccfcfb07@cat-v.org> (raw)
In-Reply-To: <1de2c7c96eb8168c5d4c800fb3dba008@vitanuova.com>
There is also /n/sources/contrib/uriel/scripts/atop, a graphical top
in C by 20h and a version by f2f in perl, the existence of the perl
version pissed me off so much that I had to rewrite it in awk and IIRC
halve the line count in the process. We all love to duplicate work.
Anyway, it is usually a good idea to dig around the [contrib index] wiki
page, often one finds useful things. I'm still wondering why g " and "' are
not part of the standard distribution.
uriel
> i was about to say that i'd find it useful if the atime of /proc/n
> reflected the last run time of a process, to make it easier to find
> cpu hogs, but russ's point about ls -lt /proc's uselessness is bang
> on.
>
> so, by way of a little script to help with the above problem, which
> bugs me every so often, here's "hogs", a poor man's replacement for
> unix's "top" - it's like ps except that it sorts the processes by the
> amount of time they've used over the last t (default 1) seconds.
>
> it displays percentage of time used over the sample time (this might
> be >100% with multiple cpus), and combines user, syscall and child
> time into the second time column (to make it easier to find processes
> that spawn lots of transient cpu-eating processes but don't do much
> themselves); otherwise the output format is the same as for ps(1).
>
> YMMV - i imagine others have similar scripts.
>
> cat >$home/bin/rc/hogs <<'EOF'
> #!/bin/rc
> # usage: hogs [sampletime]
> t=1
> if(! ~ $#* 0){
> t = $1
> }
> {
> cd /proc
> for(i in [0-9]*){
> cat $i/status && echo $i
> }
> echo
> sleep $t
> for(i in [0-9]*){
> cat $i/status && echo $i
> }
> } | awk '
> phase == 0 && /./ {
> t0[$13] = $4+$5+$7+$8;
> rt0[$13] = $6
> next
> }
> phase == 0 && /^$/ {
> phase = 1;
> next
> }
> phase != 0 {
> t1[$13] = $4+$5+$7+$8
> rt1[$13] = $6
> line[$13] = $0
> }
> END {
> for(i in line){
> n = split(line[i], p, " ");
> dt = ((t1[i] - t0[i] + 0.0) / (rt1[i] - rt0[i])) * 100
> utime = (p[4]+p[4]+p[7]+p[8]) / 1000;
> size = p[9];
> if(dt >= 1 || utime >= 1){
> printf("%-10s %8s %3d%% %4d.%.2d %7dK %-8.8s %s\n",
> p[2],
> i,
> dt,
> utime/60, utime%60,
> size,
> p[3],
> p[1]);
> }
> }
> }' |
> sort +2rn -3rn +3rn |
> sed 's/(^[^ ]+ +[0-9]+ +[0-9]+% +[0-9]+)\./\1:/'
> EOF
next prev parent reply other threads:[~2006-03-30 17:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <dfb566242e58a31d6d4f97b379b4f487@plan9.bell-labs.com>
2006-03-29 23:07 ` uriel
2006-03-29 23:34 ` Russ Cox
2006-03-30 0:13 ` quanstro
2006-03-29 23:34 ` Federico G. Benavento
2006-03-30 8:31 ` Charles Forsyth
2006-03-30 10:09 ` lucio
2006-03-30 11:33 ` Gabriel Diaz
2006-03-30 13:42 ` Anthony Sorace
2006-03-30 14:17 ` Russ Cox
2006-03-30 14:52 ` Gorka guardiola
2006-03-30 16:22 ` uriel
2006-03-30 16:50 ` matt
2006-03-30 17:19 ` Russ Cox
2006-03-31 10:52 ` matt
2006-03-30 17:24 ` rog
2006-03-30 17:32 ` uriel [this message]
2006-03-30 16:37 Fco. J. Ballesteros
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=182d0fe6c1a48fc89b095d00ccfcfb07@cat-v.org \
--to=uriel@cat-v.org \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).