diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
commit | 47e6e7c84f008a53061e661f31ae96629bc694ef (patch) | |
tree | 648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /src/perl/LogSummary | |
download | pcp-debian/3.9.10.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'src/perl/LogSummary')
24 files changed, 434 insertions, 0 deletions
diff --git a/src/perl/LogSummary/Changes b/src/perl/LogSummary/Changes new file mode 100644 index 0000000..e2c8ffe --- /dev/null +++ b/src/perl/LogSummary/Changes @@ -0,0 +1,8 @@ +Revision history for Perl extension PCP::LogSummary. + +1.01 Web Mar 4 10:48:37 2009 + - updated excel-export demo to remove unwanted dependency + +1.00 Fri Nov 28 09:20:55 2008 + - original version created + diff --git a/src/perl/LogSummary/GNUmakefile b/src/perl/LogSummary/GNUmakefile new file mode 100644 index 0000000..3411826 --- /dev/null +++ b/src/perl/LogSummary/GNUmakefile @@ -0,0 +1,62 @@ +#!gmake +# +# Copyright (c) 2008 Aconex. All Rights Reserved. +# +# 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; either version 2 of the License, or (at your +# option) any later version. +# +# 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. +# + +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +PERLMOD = LogSummary.pm +PERLDOCS = Changes MANIFEST README +PERLCODE = extract.pl exceldemo.pl +LSRCFILES = Makefile.PL $(PERLDOCS) $(PERLMOD) $(PERLCODE) +SUBDIRS = t + +LPKGDIRT = PCP-LogSummary-* MYMETA.yml MYMETA.json +LDIRT = Makefile COPYING pm_to_blib blib Makefile.old $(LPKGDIRT) *.xls + +default: dist + +MAKEMAKER_OPTIONS = INSTALLDIRS=$(PERL_INSTALLDIRS) INSTALLVENDORMAN3DIR=$(PCP_MAN_DIR)/man3 +INSTALLER_OPTIONS = DESTDIR=$$DIST_ROOT + +ifeq ($(TARGET_OS),mingw) +PERLMAKE = dmake.exe +else +PERLMAKE = $(MAKE) +endif + +Makefile: COPYING Makefile.PL + $(call PERL_MAKE_MAKEFILE) + +COPYING: + $(LN_S) $(TOPDIR)/COPYING COPYING + +test dist: Makefile + rm -f $(LPKGDIRT) + $(PERLMAKE) -f Makefile $@ + +include $(BUILDRULES) + +install: default +ifneq "$(PACKAGE_DISTRIBUTION)" "debian" + $(call PERL_GET_FILELIST,$(TOPDIR)/perl-pcp-logsummary.list,LogSummary) +endif + +install_perl: + $(PERLMAKE) -f Makefile pure_install $(INSTALLER_OPTIONS) + +default_pcp: default + +install_pcp: install + diff --git a/src/perl/LogSummary/LogSummary.pm b/src/perl/LogSummary/LogSummary.pm new file mode 100644 index 0000000..a5f2c36 --- /dev/null +++ b/src/perl/LogSummary/LogSummary.pm @@ -0,0 +1,117 @@ +package PCP::LogSummary; + +use strict; +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); + +require Exporter; + +@ISA = qw(Exporter); +@EXPORT = qw(new metric_instance); +@EXPORT_OK = qw( ); +$VERSION = '1.01'; + +sub new +{ + my ( $self, $archive, $metricsref, $start, $finish ) = @_; + my $opts = '-F -N -z -biImMy -p6'; + my @metrica = @{$metricsref}; + my $metrics = ' '; + my %results; + + foreach my $m (@metrica) { $metrics .= $m . ' '; } + if (defined($start)) { $opts .= " -S'$start'"; } + if (defined($finish)) { $opts .= " -T'$finish'"; } + + open SUMMARY, "pmlogsummary $opts $archive $metrics |" + || die "pmlogsummary: $!\n"; + + # metric,[inst],stocavg,timeavg,minimum,mintime,maximum,maxtime,count,units + LINE: while (<SUMMARY>) { + # print "Input line: $_\n"; + m/^(\S.+),(.*),(\S+),(\S+),(\S+),(.+),(\S+),(.+),(\S+),(.*)$/ + || next LINE; + + # If counter metric doesn't cover 90% of archive, metric name + # is preceded by an asterix. Chop this off and set a flag. + my $metric = $1; + $metric =~ s/^\*//; + my $asterix = ($metric ne $1); + + my %result; + $result{'average'} = $3; + $result{'timeavg'} = $4; + $result{'minimum'} = $5; + $result{'mintime'} = $6; + $result{'maximum'} = $7; + $result{'maxtime'} = $8; + $result{'samples'} = $9; + $result{'units'} = $10; + $result{'ninety%'} = $asterix; + + my $key = $1; + if ($2 ne "") { $key .= $2; } + $results{$key} = \%result; + + # print "key=", $key, " average=$3\n"; + } + close SUMMARY; + return \%results; +} + +sub metric_instance +{ + my ( $metric, $instance ) = @_; + return "$metric\[\"$instance\"\]"; +} + +1; +__END__ + +=head1 NAME + +PCP::LogSummary - Perl interface for pmlogsummary(1) + +=head1 SYNOPSIS + + use PCP::LogSummary; + + my $summary = new PCP::LogSummary($log, \@metrics, $start, $end); + +=head1 DESCRIPTION + +The PCP::LogSummary module is a wrapper around the Performance Co-Pilot +pmlogsummary(1) command. +Its primary purpose is to automate the production of post-processed +pmlogsummary data, in particular to automate the step where the +summarised data is imported into a spreadsheet for further anaylsis. +This has proven to often be an iterative process - done manually it +involves much cutting+pasting, and can be a significant time waster. + +=head2 EXPORT + +new + +metric_instance + +=head1 SEE ALSO + +pmlogsummary(1). + +The PCP mailing list pcp@mail.performancecopilot.org can be used for +questions about this module. + +Further details can be found at http://www.performancecopilot.org + +=head1 AUTHOR + +Nathan Scott, E<lt>nathans@debian.orgE<gt> + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2008 by Aconex + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2 (see +the "COPYING" file in the PCP source tree for further details). + +=cut diff --git a/src/perl/LogSummary/MANIFEST b/src/perl/LogSummary/MANIFEST new file mode 100644 index 0000000..df94fca --- /dev/null +++ b/src/perl/LogSummary/MANIFEST @@ -0,0 +1,20 @@ +Changes +Makefile.PL +MANIFEST +README +LogSummary.pm +extract.pl +exceldemo.pl +t/test.t +t/app/20081125.index +t/app/20081125.meta +t/app/20081125.0 +t/app/20081126.index +t/app/20081126.meta +t/app/20081126.0 +t/db/20081125.index +t/db/20081125.meta +t/db/20081125.0 +t/db/20081126.index +t/db/20081126.meta +t/db/20081126.0 diff --git a/src/perl/LogSummary/Makefile.PL b/src/perl/LogSummary/Makefile.PL new file mode 100644 index 0000000..89f0436 --- /dev/null +++ b/src/perl/LogSummary/Makefile.PL @@ -0,0 +1,9 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + NAME => 'PCP::LogSummary', + AUTHOR => 'Nathan Scott <nathans@debian.org>', + VERSION_FROM => 'LogSummary.pm', # finds $VERSION + ABSTRACT_FROM => 'LogSummary.pm', # retrieve abstract from module +); diff --git a/src/perl/LogSummary/README b/src/perl/LogSummary/README new file mode 100644 index 0000000..dd11f5f --- /dev/null +++ b/src/perl/LogSummary/README @@ -0,0 +1,32 @@ +PCP-LogSummary version 1.00 +=========================== + +The PCP::LogSummary module is a wrapper around the PCP pmlogsummary(1) +command. Its primary purpose is to automate the production of post- +processed pmlogsummary data, in particular to automate the step where +the summarised data is imported into a spreadsheet for further anaylsis. +This has proven to often be an iterative process - when done manually +it involves much cutting+pasting and can be a significant time waster. + +INSTALLATION + +To install this module type the following: + + perl Makefile.PL + make + make test + make install + +DEPENDENCIES + +This module requires no other Perl modules and libraries, but does +obviously require a working Performance Co-Pilot installation. + +COPYRIGHT AND LICENCE + +Copyright (C) 2008 by Aconex + +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2 (see +the "COPYING" file in the PCP source tree for further details). + diff --git a/src/perl/LogSummary/exceldemo.pl b/src/perl/LogSummary/exceldemo.pl new file mode 100644 index 0000000..1aed252 --- /dev/null +++ b/src/perl/LogSummary/exceldemo.pl @@ -0,0 +1,89 @@ +# A demo script which interfaces the LogSummary Perl module to the +# WriteExcel module, with some real data, to show what it can do. +# Author: Nathan Scott <nathans@debian.org> +# Note: No #! line, as this pulls in an external dependency that +# we really don't want in packaging tools like rpm. + +use strict; +use warnings; +use PCP::LogSummary; +use Spreadsheet::WriteExcel; + +my @app = ('aconex.response_time.samples', 'aconex.response_time.adjavg'); +my @db = ('kernel.all.cpu.user', 'kernel.all.cpu.sys', 'kernel.all.cpu.intr'); +my @dbdisk = ('disk.dev.idle', 'disk.dev.read_bytes'); + +my ( $dblog1, $dblog2 ) = ('t/db/20081125', 't/db/20081126'); +my $dbdisk_before = PCP::LogSummary->new($dblog1, \@dbdisk); +my $dbdisk_after = PCP::LogSummary->new($dblog2, \@dbdisk); +my $dbcpu_before = PCP::LogSummary->new($dblog1, \@db); +my $dbcpu_after = PCP::LogSummary->new($dblog2, \@db); + +my ( $applog1, $applog2 ) = ('t/app/20081125', 't/app/20081126'); +my $app_before = PCP::LogSummary->new($applog1, \@app); +my $app_after = PCP::LogSummary->new($applog2, \@app); + +my $workbook = Spreadsheet::WriteExcel->new('new-dxb-dbserver.xls'); + +my $heading = $workbook->add_format(); +$heading->set_bold(); +$heading->set_italic(); +my $subheading = $workbook->add_format(); +$subheading->set_italic(); +$subheading->set_bg_color('silver'); +my $unitscolumn = $workbook->add_format(); +$unitscolumn->set_align('center'); + +my $sheet = $workbook->add_worksheet(); +my ( $precol, $postcol, $units ) = ( 1, 2, 3 ); +$sheet->set_column('A:A', 32); # metric names column +$sheet->set_column('B:B', 14); # column for "Before" values +$sheet->set_column('C:C', 14); # column for "After" values +$sheet->set_column('D:D', 12); # metrics units column + +my $row = 0; +$sheet->write($row, 0, 'Dubai Database Storage Upgrade', $heading); +$row = 2; +$sheet->write($row, 0, 'Metrics', $subheading); +$sheet->write($row, $precol, 'Before', $subheading); +$sheet->write($row, $postcol, 'After', $subheading); +$sheet->write($row, $units, 'Units', $subheading); + +foreach my $m ( @app ) { + my $metric = metric_instance($m, 'dxb'); + $row++; + $sheet->write($row, 0, $metric); + $sheet->write($row, $precol, $$app_before{$metric}{'average'}); + $sheet->write($row, $postcol, $$app_after{$metric}{'average'}); + $sheet->write($row, $units, $$app_after{$metric}{'units'}, $unitscolumn); +} +foreach my $m ( @dbdisk ) { + my $metric = metric_instance($m, 'G:'); # Windows drive letter + $row++; + $sheet->write($row, 0, $metric); + $sheet->write($row, $precol, $$dbdisk_before{$metric}{'average'}); + $sheet->write($row, $postcol, $$dbdisk_after{$metric}{'average'}); + $sheet->write($row, $units, $$dbdisk_after{$metric}{'units'}, $unitscolumn); +} + +# Report CPU metrics as a single utilisation value +{ + my $syscpu1 = $$dbcpu_before{'kernel.all.cpu.sys'}; + my $intcpu1 = $$dbcpu_before{'kernel.all.cpu.intr'}; + my $usrcpu1 = $$dbcpu_before{'kernel.all.cpu.user'}; + my $syscpu2 = $$dbcpu_after{'kernel.all.cpu.sys'}; + my $intcpu2 = $$dbcpu_after{'kernel.all.cpu.intr'}; + my $usrcpu2 = $$dbcpu_after{'kernel.all.cpu.user'}; + my $ncpu = 4; + + my $cpu_before = $ncpu * ( $$syscpu1{'average'} + + $$intcpu1{'average'} + $$usrcpu1{'average'} ); + my $cpu_after = $ncpu * ( $$syscpu2{'average'} + + $$intcpu2{'average'} + $$usrcpu2{'average'} ); + + $row++; + $sheet->write($row, 0, 'kernel.all.cpu'); + $sheet->write($row, $precol, $cpu_before * 100.0); + $sheet->write($row, $postcol, $cpu_after * 100.0); + $sheet->write($row, $units, 'percent', $unitscolumn); +} diff --git a/src/perl/LogSummary/extract.pl b/src/perl/LogSummary/extract.pl new file mode 100755 index 0000000..1165a7b --- /dev/null +++ b/src/perl/LogSummary/extract.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use PCP::LogSummary; + +my $archive = 't/db/20081125'; +my @metrics = ( 'kernel.all.cpu.user', 'kernel.all.cpu.idle', + 'kernel.all.cpu.intr', 'kernel.all.cpu.sys' ); +my $results = PCP::LogSummary->new($archive, \@metrics, '@09:00', '@17:00'); +#my $results = PCP::LogSummary->new($archive, \@metrics); + +foreach my $metric ( keys %$results ) { + my $summary = $$results{$metric}; + print "metric=", $metric, "\n"; + print " average=", $$summary{'average'}, "\n"; + print " samples=", $$summary{'samples'}, "\n"; +} diff --git a/src/perl/LogSummary/t/GNUmakefile b/src/perl/LogSummary/t/GNUmakefile new file mode 100644 index 0000000..6c00e8d --- /dev/null +++ b/src/perl/LogSummary/t/GNUmakefile @@ -0,0 +1,12 @@ +TOPDIR = ../../../.. +include $(TOPDIR)/src/include/builddefs +LSRCFILES = test.t +SUBDIRS = app db + +default: + +include $(BUILDRULES) + +install: + +default_pcp install_pcp: diff --git a/src/perl/LogSummary/t/app/20081125.0 b/src/perl/LogSummary/t/app/20081125.0 Binary files differnew file mode 100644 index 0000000..43e5f4a --- /dev/null +++ b/src/perl/LogSummary/t/app/20081125.0 diff --git a/src/perl/LogSummary/t/app/20081125.index b/src/perl/LogSummary/t/app/20081125.index Binary files differnew file mode 100644 index 0000000..76eb3b9 --- /dev/null +++ b/src/perl/LogSummary/t/app/20081125.index diff --git a/src/perl/LogSummary/t/app/20081125.meta b/src/perl/LogSummary/t/app/20081125.meta Binary files differnew file mode 100644 index 0000000..5007180 --- /dev/null +++ b/src/perl/LogSummary/t/app/20081125.meta diff --git a/src/perl/LogSummary/t/app/20081126.0 b/src/perl/LogSummary/t/app/20081126.0 Binary files differnew file mode 100644 index 0000000..9563c3c --- /dev/null +++ b/src/perl/LogSummary/t/app/20081126.0 diff --git a/src/perl/LogSummary/t/app/20081126.index b/src/perl/LogSummary/t/app/20081126.index Binary files differnew file mode 100644 index 0000000..d5d7fa6 --- /dev/null +++ b/src/perl/LogSummary/t/app/20081126.index diff --git a/src/perl/LogSummary/t/app/20081126.meta b/src/perl/LogSummary/t/app/20081126.meta Binary files differnew file mode 100644 index 0000000..b60336c --- /dev/null +++ b/src/perl/LogSummary/t/app/20081126.meta diff --git a/src/perl/LogSummary/t/app/GNUmakefile b/src/perl/LogSummary/t/app/GNUmakefile new file mode 100644 index 0000000..8309f9c --- /dev/null +++ b/src/perl/LogSummary/t/app/GNUmakefile @@ -0,0 +1,13 @@ +TOPDIR = ../../../../.. +include $(TOPDIR)/src/include/builddefs +LSRCFILES = \ + 20081125.meta 20081125.index 20081125.0 \ + 20081126.meta 20081126.index 20081126.0 + +default: + +include $(BUILDRULES) + +install: + +default_pcp install_pcp: diff --git a/src/perl/LogSummary/t/db/20081125.0 b/src/perl/LogSummary/t/db/20081125.0 Binary files differnew file mode 100644 index 0000000..5c8d606 --- /dev/null +++ b/src/perl/LogSummary/t/db/20081125.0 diff --git a/src/perl/LogSummary/t/db/20081125.index b/src/perl/LogSummary/t/db/20081125.index Binary files differnew file mode 100644 index 0000000..450dd1a --- /dev/null +++ b/src/perl/LogSummary/t/db/20081125.index diff --git a/src/perl/LogSummary/t/db/20081125.meta b/src/perl/LogSummary/t/db/20081125.meta Binary files differnew file mode 100644 index 0000000..52f8376 --- /dev/null +++ b/src/perl/LogSummary/t/db/20081125.meta diff --git a/src/perl/LogSummary/t/db/20081126.0 b/src/perl/LogSummary/t/db/20081126.0 Binary files differnew file mode 100644 index 0000000..758c6ae --- /dev/null +++ b/src/perl/LogSummary/t/db/20081126.0 diff --git a/src/perl/LogSummary/t/db/20081126.index b/src/perl/LogSummary/t/db/20081126.index Binary files differnew file mode 100644 index 0000000..eac9dbb --- /dev/null +++ b/src/perl/LogSummary/t/db/20081126.index diff --git a/src/perl/LogSummary/t/db/20081126.meta b/src/perl/LogSummary/t/db/20081126.meta Binary files differnew file mode 100644 index 0000000..835e3be --- /dev/null +++ b/src/perl/LogSummary/t/db/20081126.meta diff --git a/src/perl/LogSummary/t/db/GNUmakefile b/src/perl/LogSummary/t/db/GNUmakefile new file mode 100644 index 0000000..8309f9c --- /dev/null +++ b/src/perl/LogSummary/t/db/GNUmakefile @@ -0,0 +1,13 @@ +TOPDIR = ../../../../.. +include $(TOPDIR)/src/include/builddefs +LSRCFILES = \ + 20081125.meta 20081125.index 20081125.0 \ + 20081126.meta 20081126.index 20081126.0 + +default: + +include $(BUILDRULES) + +install: + +default_pcp install_pcp: diff --git a/src/perl/LogSummary/t/test.t b/src/perl/LogSummary/t/test.t new file mode 100644 index 0000000..816c114 --- /dev/null +++ b/src/perl/LogSummary/t/test.t @@ -0,0 +1,41 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl test.t' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +use Test; +BEGIN { plan tests => 15 }; +use PCP::LogSummary; +ok(1); # If we made it this far, we're ok. + +######################### + +my $archive = 't/db/20081125'; +my @metrics = ( 'kernel.all.cpu.user', 'kernel.all.cpu.sys' ); +my $results = PCP::LogSummary->new($archive, \@metrics); +ok(1, defined($results), "log summarised"); + +foreach my $metric ( sort keys %$results ) { + my $summary = $$results{$metric}; + #print("metric=", $metric, "\n"); + #print(" average=", $$summary{'average'}, "\n"); + #print(" samples=", $$summary{'samples'}, "\n"); + ok(1, ($$summary{'samples'} == 5758), "samples verified"); + ok(1, ($$summary{'average'} > 0), "average lower bounds check"); + ok(1, ($$summary{'average'} < 1), "average upper bounds check") ; +} + +$results = PCP::LogSummary->new($archive, \@metrics, '@09:00', '@17:00'); +ok(1, defined($results), "restricted log summarised"); + +foreach my $metric ( sort keys %$results ) { + my $summary = $$results{$metric}; + #print("metric=", $metric, "\n"); + #print(" average=", $$summary{'average'}, "\n"); + #print(" samples=", $$summary{'samples'}, "\n"); + ok(1, ($$summary{'samples'} == 1919), "restricted samples verified"); + ok(1, ($$summary{'average'} > 0), "average lower bounds check"); + ok(1, ($$summary{'average'} < 1), "average upper bounds check") ; +} |