2
# Print numa statistics for all nodes
3
# Copyright (C) 2003,2004 Andi Kleen, SuSE Labs.
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
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.
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 */
19
# Example: NUMASTAT_WIDTH=80 watch -n1 numastat
24
if (defined($ENV{'NUMASTAT_WIDTH'})) {
25
$WIDTH=$ENV{'NUMASTAT_WIDTH'};
28
if (POSIX::isatty(fileno(STDOUT))) {
29
if (open(R, "resize |")) {
31
$WIDTH=$1 if /COLUMNS=(\d+)/;
36
# don't split it up for easier parsing
40
$WIDTH = 32 if $WIDTH < 32;
42
if (! -d "/sys/devices/system/node" ) {
43
print STDERR "sysfs not mounted or system not NUMA aware\n";
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
58
#print "readdir(NODES) returns $nd\n";
59
if (!$title && $nd =~ /node0/) {
62
open(STAT, "/sys/devices/system/node/$nd/numastat") ||
63
die "cannot open $nd: $!\n";
65
$title = sprintf("%16s",$nd) . $title;
67
$title = $title . sprintf("%16s",$nd);
71
($name, $val) = split;
73
$stat{$name} = sprintf("%16u", $val) . $stat{$name};
75
$stat{$name} = $stat{$name} . sprintf("%16u", $val);
83
$numfields = int(($WIDTH - 16) / 16);
85
for ($i = 0; $i < length($title); $i += $l) {
87
printf "%16s%s\n","",substr($title,$i,$l);
89
printf "%-16s%s\n",$_,substr($stat{$_},$i,$l);