Skip to content

Commit 673f557

Browse files
committed
Add pids graph.
1 parent 0ecceab commit 673f557

File tree

6 files changed

+130
-6
lines changed

6 files changed

+130
-6
lines changed

Changes

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Thu Jul 23 22:50:15 2015 fox
2+
3+
58* .gitignore
4+
common/commands.c
5+
linux/graphs.c
6+
linux/proc.c
7+
linux/sigdesc.h
8+
makefile
9+
scripts/stackmon.pl
10+
Add pids to graph. Attempt to fix infinite loop where we dont
11+
read kbd on ^B; add support for ^N/^P
12+
113
Sat Aug 30 19:35:23 2014 fox
214

315
57* .mk

common/commands.c

+1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ help_func(int argc, char **argv)
340340
}
341341
print("\n");
342342
print("Ctrl-B - page/back; Ctrl-F - page/fwd; Ctrl-R - reset paging\n");
343+
print("Ctrl-P - 1 min back; Ctrl-N - 1 min fwd\n");
343344
print("Ctrl-L - refresh screen.\n");
344345
print("\nPress any key to continue: ");
345346
refresh();

include/build.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# define MAJ_VERSION 2
22
# define MIN_VERSION 1
3-
int version_build_no = 57;
4-
# define VERSION_BUILD_NO 57
5-
char version_build_date[] = "Sat Aug 30 19:35:23 2014";
3+
int version_build_no = 58;
4+
# define VERSION_BUILD_NO 58
5+
char version_build_date[] = "Thu Jul 23 22:50:15 2015";
66

linux/graphs.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ display_graphs()
3535
draw_graph(g, 1, "loadavg", 0, 100, WIDTH, 50, 100., 0x00c080);
3636
draw_graph(g, 1, "meminfo.Dirty", 200, 100, WIDTH, 50, 1., 0x0080c0);
3737
draw_graph(g, 1, "meminfo.Cached", 400, 100, WIDTH, 50, 1., 0x40b090);
38+
3839
draw_graph(g, 1, "meminfo.MemFree", 0, 170, WIDTH, 50, 1., 0xc04090);
3940
draw_graph(g, 1, "stat.procs_running", 200, 170, WIDTH, 50, 1., 0x409080);
4041
draw_graph(g, 0x03, "stat.intr", 400, 170, WIDTH, 50, 1., 0x503090);
42+
4143
draw_graph(g, 0x03, "vmstat.pgfault", 0, 240, WIDTH, 50, 1., 0x508090);
44+
draw_graph(g, 0x03, "loadavg.06", 200, 240, WIDTH, 50, 1., 0x508090);
4245

4346
graph_free(g);
4447
}
@@ -65,13 +68,17 @@ draw_graph(graph_t *g, int flags, char *item, int x, int y,
6568
{ int i;
6669
char buf[BUFSIZ];
6770
unsigned long long v0 = 0;
71+
char *title = item;
72+
73+
if (strcmp(item, "loadavg.06") == 0)
74+
title = "pids";
6875

6976
graph_clear(g);
7077
graph_setfont(g, "6x9");
7178
graph_setforeground(g, 0xffffff);
7279
graph_setbackground(g, 0xffffff);
7380
if (flags & 0x01)
74-
graph_drawstring(g, x, y - 3, item);
81+
graph_drawstring(g, x, y - 3, title);
7582

7683
graph_set(g, "x", x);
7784
graph_set(g, "y", y);

linux/proc.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -1111,15 +1111,23 @@ main_loop(void)
11111111
}
11121112

11131113
/***********************************************/
1114-
/* Avoid refreshing if nothing changed. */
1114+
/* Avoid refreshing if nothing changed but */
1115+
/* avoid infinite loop where user loses */
1116+
/* control. */
11151117
/***********************************************/
11161118
mon_lock();
11171119
lt0 = lt;
11181120
lt = mon_get_time();
11191121
if (lt0 == lt) {
11201122
struct timeval tval = {0, 50 * 1000};
1123+
fd_set rbits;
1124+
int ret;
1125+
1126+
FD_ZERO(&rbits);
1127+
FD_SET(1, &rbits);
1128+
11211129
mon_unlock();
1122-
select(0, NULL, NULL, NULL, &tval);
1130+
ret = select(32, &rbits, NULL, NULL, &tval);
11231131
if (lt == (unsigned long long) -1) {
11241132
set_attribute(RED, YELLOW, 0);
11251133
mvprint(5, 0, "Status pmap is missing - will refresh when procmon restarts.");
@@ -1136,6 +1144,8 @@ main_loop(void)
11361144
refresh();
11371145
stale_displayed = FALSE;
11381146
}
1147+
else if (ret)
1148+
wait_for_command();
11391149
continue;
11401150
}
11411151

@@ -1981,6 +1991,12 @@ static int first_time = TRUE;
19811991
case 'f' & 0x1f:
19821992
mon_move(1);
19831993
return;
1994+
case 'p' & 0x1f:
1995+
mon_move(-60);
1996+
return;
1997+
case 'n' & 0x1f:
1998+
mon_move(60);
1999+
return;
19842000
case 'r' & 0x1f:
19852001
mon_move(0);
19862002
return;

scripts/stackmon.pl

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#! /usr/bin/perl
2+
3+
# $Header:$
4+
5+
use strict;
6+
use warnings;
7+
8+
use File::Basename;
9+
use FileHandle;
10+
use Getopt::Long;
11+
use IO::File;
12+
use POSIX;
13+
14+
#######################################################################
15+
# Command line switches. #
16+
#######################################################################
17+
my %opts = (
18+
sleep => 5,
19+
);
20+
21+
sub main
22+
{
23+
Getopt::Long::Configure('require_order');
24+
Getopt::Long::Configure('no_ignore_case');
25+
usage() unless GetOptions(\%opts,
26+
'a',
27+
'help',
28+
'sleep=s',
29+
);
30+
31+
usage() if $opts{help};
32+
33+
while (1) {
34+
print "\n";
35+
print strftime("%Y%m%d %H:%M:%S\n", localtime());
36+
foreach my $f (glob("/proc/*/stack")) {
37+
next if $f =~ /\/self\//;
38+
$f =~ /\/([0-9]*)\//;
39+
my $pid = $1;
40+
next if $pid == $$;
41+
42+
my $fh = new FileHandle($f);
43+
next if !$fh;
44+
my $s = '';
45+
while (<$fh>) {
46+
$s .= $_;
47+
}
48+
if (!$opts{a}) {
49+
next if $s =~ /do_signal_stop/;
50+
next if $s =~ /poll_schedule_timeout/;
51+
next if $s =~ /n_tty_read/;
52+
next if $s =~ /do_wait/;
53+
next if $s =~ /pipe_wait/;
54+
}
55+
56+
my $cmd = 'unknown';
57+
$fh = new FileHandle("/proc/$pid/cmdline");
58+
$cmd = <$fh> if $fh;
59+
$cmd =~ s/\0/ /g;
60+
print "$cmd:\n";
61+
print $s;
62+
}
63+
64+
sleep(5);
65+
}
66+
}
67+
#######################################################################
68+
# Print out command line usage. #
69+
#######################################################################
70+
sub usage
71+
{
72+
print <<EOF;
73+
stackmon.pl -- list out stacks of processes.
74+
Usage: stackmon.pl
75+
76+
Switches:
77+
78+
-a Show all procs - otherwise we will filter the boring ones.
79+
-sleep N Pause for N seconds before refresh. Default $opts{sleep}
80+
81+
EOF
82+
83+
exit(1);
84+
}
85+
86+
main();
87+
0;
88+

0 commit comments

Comments
 (0)