monotone

monotone Mtn Source Tree

Root/contrib/parse-accounting.pl

  • Property mtn:execute set to true
1#!/usr/bin/perl -w
2use strict;
3use FileHandle;
4
5# possible values that can be extracted from the file...
6my ($cpus, $max_size, $max_resident, $copied, $malloc);
7
8die "Usage: <test|header> <step> <file> " unless @ARGV == 3;
9
10my ($test,$what,$file) = @ARGV;
11
12parse_file($file);
13
14if (defined $copied && defined $malloc && defined $max_resident && defined $max_size) {
15 if ($test eq 'header') {
16print <<'END_OF_HEADER';
17 Maximum (MiB) Copied Malloc
18 *Test* Operation CPU(s) Size Resident (MiB) (MiB)
19---------------- --------- ------ ------- ------- -------- --------
20END_OF_HEADER
21 }
22 eval '
23 format STDOUT =
24@<<<<<<<<<<<<<<< @<<<<<<<< @###.# @###.## @###.## @####### @#######
25$test, $what, $cpus, $max_size, $max_resident, $copied, $malloc
26.
27 '; die $@ if $@
28} elsif (defined $max_resident && defined $max_size) {
29 if ($test eq 'header') {
30print <<'END_OF_HEADER';
31 Maximum (MiB)
32 *Test* Operation CPU(s) Size Resident
33---------------- --------- ------ ------- -------
34END_OF_HEADER
35 }
36 eval '
37 format STDOUT =
38@<<<<<<<<<<<<<<< @<<<<<<<< @###.# @###.## @###.##
39$test, $what, $cpus, $max_size, $max_resident,
40.
41 '; die $@ if $@
42} else {
43 if ($test eq 'header') {
44print <<'END_OF_HEADER';
45 *Test* Operation CPU(s)
46---------------- --------- ------
47END_OF_HEADER
48 }
49 eval '
50 format STDOUT =
51@<<<<<<<<<<<<<<< @<<<<<<<< @###.#
52$test, $what, $cpus
53.
54 '; die $@ if $@
55}
56
57exit(0) if $test eq 'header';
58
59$max_size ||= -1;
60$max_resident ||= -1;
61$copied ||= -1;
62$malloc ||= -1;
63
64write;
65
66sub parse_file {
67 my($file) = @_;
68
69 my $fh = new FileHandle($file) or die "Can't open $file for read: $!";
70 my ($usertime,$systime);
71 while(<$fh>) {
72# parse builtin accounting...
73$cpus = $1 + $2
74 if /^STATS: User time: (\d+\.\d+)s, System time: (\d+\.\d+)s$/o;
75($max_size,$max_resident) = ($1,$2)
76 if /^STATS: Max Size MiB: (\d+\.\d+), Max Resident MiB: (\d+\.\d+)$/o;
77$copied = $1
78 if /^STATS: MiB copied: (\d+\.\d+), Total/o;
79$malloc = $1
80 if /^STATS: MiB malloced: (\d+\.\d+), Malloc/o;
81
82# parse external accounting by /usr/bin/time on debian...
83$usertime = $1 * 60 + $2
84 if /^user\s+(\d+)m(\d+\.\d+)s$/o;
85$systime = $1 * 60 + $2
86 if /^sys\s+(\d+)m(\d+\.\d+)s$/o;
87# parse external accounting by time in zsh...
88($usertime,$systime) = ($1,$2)
89 if /^(\d+\.\d+)user (\d+\.\d+)system .*CPU/o;
90 }
91
92 if (defined $usertime || defined $systime) {
93die "both internal and external statistics?? log in $file"
94 if defined $cpus;
95die "missing user or system time?? log in $file"
96 unless defined $usertime && defined $systime;
97$cpus = $usertime + $systime;
98 }
99 die "internal, didn't get cpu seconds from $file?!" unless defined $cpus;
100}
101

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status