~ubuntu-branches/ubuntu/vivid/numactl/vivid

« back to all changes in this revision

Viewing changes to numastat

  • Committer: Package Import Robot
  • Author(s): Ian Wienand
  • Date: 2012-11-15 12:20:29 UTC
  • mfrom: (1.3.9)
  • Revision ID: package-import@ubuntu.com-20121115122029-df53pmew2v1ydcsg
Tags: 2.0.8-1
New upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
# Print numa statistics for all nodes
3
 
# Copyright (C) 2003,2004 Andi Kleen, SuSE Labs.
4
 
#
5
 
# numastat is free software; you can redistribute it and/or
6
 
# modify it under the terms of the GNU General Public
7
 
# License as published by the Free Software Foundation; version
8
 
# 2.
9
 
#
10
 
# numastat is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
# General Public License for more details.
14
 
 
15
 
# You should find a copy of v2 of the GNU General Public License somewhere
16
 
# on your Linux system; if not, write to the Free Software Foundation, 
17
 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
 
#
19
 
# Example: NUMASTAT_WIDTH=80 watch -n1 numastat
20
 
#
21
 
 
22
 
# output width
23
 
$WIDTH=80;
24
 
if (defined($ENV{'NUMASTAT_WIDTH'})) {
25
 
        $WIDTH=$ENV{'NUMASTAT_WIDTH'};
26
 
} else { 
27
 
        use POSIX; 
28
 
        if (POSIX::isatty(fileno(STDOUT))) { 
29
 
                if (open(R, "resize |")) { 
30
 
                        while (<R>) { 
31
 
                                $WIDTH=$1 if /COLUMNS=(\d+)/;
32
 
                        }       
33
 
                        close R;
34
 
                }
35
 
        } else { 
36
 
                # don't split it up for easier parsing
37
 
                $WIDTH=10000000;
38
 
        } 
39
 
40
 
$WIDTH = 32 if $WIDTH < 32; 
41
 
 
42
 
if (! -d "/sys/devices/system/node" ) { 
43
 
        print STDERR "sysfs not mounted or system not NUMA aware\n";
44
 
        exit 1;
45
 
46
 
 
47
 
%stat = (); 
48
 
$title = ""; 
49
 
$mode = 0;
50
 
opendir(NODES, "/sys/devices/system/node") || exit 1;
51
 
foreach $nd (readdir(NODES)) { 
52
 
        next unless $nd =~ /node(\d+)/; 
53
 
        # On newer kernels, readdir may enumerate the 'node(\d+) subdirs
54
 
        # in opposite order from older kernels--e.g., node{0,1,2,...}
55
 
        # as opposed to node{N,N-1,N-2,...}.  Accomodate this by
56
 
        # switching to new mode so that the stats get emitted in
57
 
        # the same order.
58
 
        #print "readdir(NODES) returns $nd\n";
59
 
        if (!$title && $nd =~ /node0/) {
60
 
                $mode = 1;
61
 
        }
62
 
        open(STAT, "/sys/devices/system/node/$nd/numastat") || 
63
 
                        die "cannot open $nd: $!\n"; 
64
 
        if (! $mode) {
65
 
                $title = sprintf("%16s",$nd) . $title;
66
 
        } else {
67
 
                $title = $title . sprintf("%16s",$nd);
68
 
        }
69
 
        @fields = ();
70
 
        while (<STAT>) { 
71
 
                ($name, $val) = split;
72
 
                if (! $mode) {
73
 
                        $stat{$name} = sprintf("%16u", $val) . $stat{$name};
74
 
                } else {
75
 
                        $stat{$name} = $stat{$name} . sprintf("%16u", $val);
76
 
                }
77
 
                push(@fields, $name); 
78
 
        } 
79
 
        close STAT; 
80
 
81
 
closedir NODES;
82
 
 
83
 
$numfields = int(($WIDTH - 16) / 16);
84
 
$l = 16 * $numfields;
85
 
for ($i = 0; $i < length($title); $i += $l) { 
86
 
        print "\n" if $i > 0; 
87
 
        printf "%16s%s\n","",substr($title,$i,$l); 
88
 
        foreach (@fields) { 
89
 
                printf "%-16s%s\n",$_,substr($stat{$_},$i,$l);
90
 
        }
91
 
}