#!/usr/bin/perl -w # # Copyright (C) 2006 Rodolphe Quiedeville # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2 dated June, # 1991. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # If you improve this script please send your version to my email address # with the copyright notice upgrade with your name. # # Wildcard-plugin to monitor the ccache stats. To monitor an # user cache, link ccache_ to this file. E.g. # # ln -s /usr/share/munin/plugins/ccache_ /etc/munin/plugins/ccache_loic # # ...will monitor loic ccache stats. # # $Log$ # Revision 1.1 2006/04/27 14:12:19 rodo # More stats # # Revision 1.0 2006/04/27 14:12:19 rodo # Created by Rodolphe Quiedeville # # Configurable variables # # ccache - Override default ccache command # ccache_dir - Override default cache dir # # Magic markers (optinal - used by munin-config and some installation # scripts): # #%# family=compilation #%# capabilities=autoconf use strict; $0 =~ /ccache_(.+)*$/; my $user = $1; exit 2 unless defined $user; $ENV{CCACHE_DIR} = exists $ENV{'ccache_dir'} ? $ENV{'ccache_dir'} : "/home/$user/.ccache"; my $CCACHE = exists $ENV{'ccache'} ? $ENV{'ccache'} : "/usr/bin/ccache"; (-d $ENV{CCACHE_DIR}) || die "Can't open $ENV{CCACHE_DIR}\n"; (-x $CCACHE) || die "Can't exec $CCACHE\n"; # cache directory /home/rodo/.ccache # cache hit 9 # cache miss 6 # called for link 11 # multiple source files 20 # compiler produced stdout 2 # compile failed 3 # ccache internal error 5 # preprocessor error 6 # couldn't find the compiler 7 # cache file missing 8 # bad compiler arguments 10 # not a C/C++ file 50 # autoconf compile/link 30 # unsupported compiler option 20 # output to stdout 30 # output to a non-regular file 20 # no input file 25 # files in cache 45 # cache size 20 Kbytes # max files 30 # max cache size 1024 Kbytes my %WANTED = ( "cache hit" => "hit", "cache miss" => "miss", "called for link" => "link", "multiple source files" => "multiple", "compiler produced stdout" => "prodoutput", "compile failed" => "failed", "ccache internal error" => "error", "preprocessor error" => "preperror", "couldn't find the compiler" => "compiler", "cache file missing" => "missing", "bad compiler arguments" => "badarg", "not a C/C++ file" => "noc", "autoconf compile/link" => "autoconf", "unsupported compiler option" => "unsup", "output to stdout" => "stdout", "output to a non-regular file" => "ononregf", "no input file" => "noinput", ); my $cache = "$CCACHE -s"; if ($ARGV[0] and $ARGV[0] eq "config" ){ print "graph_title ccache utilisation for $user\n"; print "graph_args --base 1000 -l 0\n"; print "graph_scale yes\n"; print "graph_vlabel files\n"; print "graph_category compilation\n"; print 'graph_info Plugin available at http://rodolphe.quiedeville.org/hack/munin/'."\n"; open(CCH, "$cache|") or exit 4; my ($num) = (0); while () { my ($k, $v) = (/(.*)\s+(\d+)$/); next unless ($k); $k =~ s/\s+$//; if (exists $WANTED{$k} ) { print("$WANTED{$k}.label $k\n"); print("$WANTED{$k}.type DERIVE\n"); ($num > 0) ? print("$WANTED{$k}.draw STACK\n") : print("$WANTED{$k}.draw AREA\n"); $num++; } } close(CCH); exit 0; } open(CCH, "$cache|") or exit 4; while () { my ($k, $v) = (/(.*)\s+(\d+)$/); next unless ($k); $k =~ s/\s+$//; print("$WANTED{$k}.value $v\n") if (exists $WANTED{$k}); } close(CCH);