Skip to content

Commit

Permalink
bin: extract-mmtests.pl: export multiple test data to a json file
Browse files Browse the repository at this point in the history
With this commit an user can export the results of multiple test
runs by doing:
	bin/extract-mmtests.pl -d work/log/ -b <test-type-name> \
	-n <folder-name-1>,<folder-name-2>,... --print-json \
	> ./benchmarks.json

In the example above folder-name-1 and folder-name-2 represent the
names of the folders that contain benchmark results inside the
work/log directory.

Signed-off-by: Mirco Romagnoli <romagnoli.mirco@gmail.com>
Signed-off-by: Mel Gorman <mgorman@techsingularity.net>
  • Loading branch information
mirco-romagnoli authored and gormanm committed May 4, 2021
1 parent c964294 commit 95a39b0
Showing 1 changed file with 87 additions and 57 deletions.
144 changes: 87 additions & 57 deletions bin/extract-mmtests.pl
Expand Up @@ -26,7 +26,7 @@
my ($opt_reportDirectory, $opt_monitor);
my ($opt_printHeader, $opt_printPlot, $opt_printType, $opt_printJSON);
my ($opt_subheading, $opt_format);
my ($opt_name, $opt_benchmark, $opt_altreport);
my ($opt_names, $opt_benchmark, $opt_altreport);
GetOptions(
'verbose|v' => \$opt_verbose,
'help|h' => \$opt_help,
Expand All @@ -37,7 +37,7 @@
'--print-json' => \$opt_printJSON,
'--print-monitor=s' => \$opt_monitor,
'--sub-heading=s' => \$opt_subheading,
'n|name=s' => \$opt_name,
'n|names=s' => \$opt_names,
'b|benchmark=s' => \$opt_benchmark,
'a|altreport=s' => \$opt_altreport,
'manual' => \$opt_manual,
Expand All @@ -48,7 +48,7 @@
pod2usage(-exitstatus => 0, -verbose => 2) if $opt_manual;

my ($reportDir);
$reportDir = "$opt_reportDirectory/$opt_name";
$reportDir = "$opt_reportDirectory";

# Sanity check directory
if (! -d $reportDir) {
Expand All @@ -57,7 +57,7 @@
}

sub exportJSON {
my ($module, $benchmark, $name) = @_;
my (@modules) = @_;
require Cpanel::JSON::XS;
my $json = Cpanel::JSON::XS->new();

Expand All @@ -66,38 +66,57 @@ sub exportJSON {
$json->allow_blessed();
$json->convert_blessed();

print $json->encode($module);
if (scalar(@modules) == 1) {
print $json->encode($modules[0]);
} else {
print $json->encode(\@modules);
}
}

# If monitors are requested, extract that and exit
# If monitors are requested, extract those and exit
if (defined $opt_monitor) {
my @monitorModules;
my $nrModules = 0;
my $monitorFactory = MMTests::ExtractFactory->new();
my $monitorModule;
eval {
$monitorModule = $monitorFactory->loadModule("monitor", $opt_monitor, $opt_name, $opt_subheading);
} or do {
printWarning("Failed to load module for monitor $opt_monitor\n$@");
exit(-1);
};
for my $name (split /,/, $opt_names) {
eval {
$monitorModules[$nrModules] = $monitorFactory->loadModule("monitor", $opt_monitor, $name, $opt_subheading);
} or do {
printWarning("Failed to load module for monitor $opt_monitor\n$@");
exit(-1);
};

if ($opt_printType) {
# Just print the type if asked
$monitorModules[$nrModules]->printDataType($opt_subheading);
} else {
my @iterdirs = <$reportDir/$name/iter-*>;
foreach my $iterdir (@iterdirs) {
$monitorModules[$nrModules]->extractReport($iterdir, "$opt_benchmark",
$opt_subheading);
$monitorModules[$nrModules]->nextIteration();
}
$nrModules++;
}
}

# Just print the type if asked
if ($opt_printType) {
$monitorModule->printDataType($opt_subheading);
exit;
}

my @iterdirs = <$reportDir/iter-*>;
foreach my $iterdir (@iterdirs) {
$monitorModule->extractReport($iterdir, "$opt_benchmark",
$opt_subheading);
$monitorModule->nextIteration();
}
if ($opt_printPlot) {
$monitorModule->printPlotHeaders() if $opt_printHeader;
$monitorModule->printPlot($opt_subheading);
} elsif ($opt_printJSON) {
exportJSON($monitorModule, "$opt_benchmark", $opt_name);
} else {
foreach my $monitorModule (@monitorModules) {
$monitorModule->printPlotHeaders() if $opt_printHeader;
$monitorModule->printPlot($opt_subheading);
print "\n";
}
exit;
}
if ($opt_printJSON) {
exportJSON(@monitorModules);
exit;
}
foreach my $monitorModule (@monitorModules) {
$monitorModule->printReportTop();
$monitorModule->printFieldHeaders() if $opt_printHeader;
$monitorModule->printReport();
Expand All @@ -106,43 +125,54 @@ sub exportJSON {
exit(0);
}

# Instantiate a handler of the requested type for the benchmark
# Instantiate a handler of the requested type for the benchmarks
my @extractModules;
my $nrModules = 0;
my $extractFactory = MMTests::ExtractFactory->new();
my $extractModule;
eval {
$extractModule = $extractFactory->loadModule("extract", "$opt_benchmark$opt_altreport", $opt_name, $opt_subheading);
} or do {
printWarning("Failed to load module for benchmark $opt_benchmark$opt_altreport\n$@");
exit(-1);
};

# Just print the type if asked
if ($opt_printType) {
$extractModule->printDataType($opt_subheading);
exit;
for my $name (split /,/, $opt_names) {
eval {
$extractModules[$nrModules] = $extractFactory->loadModule("extract", "$opt_benchmark$opt_altreport", $name, $opt_subheading);
} or do {
printWarning("Failed to load module for benchmark $opt_benchmark$opt_altreport\n$@");
exit(-1);
};

if ($opt_printType) {
# Just print the type if asked
$extractModules[$nrModules]->printDataType($opt_subheading);
print "\n";
} else {
# Extract data from the benchmark itself and print whatever was requested
my @iterdirs = <$reportDir/$name/iter-*>;
foreach my $iterdir (@iterdirs) {
# Make a guess at the sub-directory name if one is not specified
$iterdir = "$iterdir/$opt_benchmark";
$extractModules[$nrModules]->extractReport("$iterdir/logs");
$extractModules[$nrModules]->nextIteration();
}
$nrModules ++;
}
}

# Extract data from the benchmark itself and print whatever was requested
my @iterdirs = <$reportDir/iter-*>;
foreach my $iterdir (@iterdirs) {
# Make a guess at the sub-directory name if one is not specified
$iterdir = "$iterdir/$opt_benchmark";
$extractModule->extractReport("$iterdir/logs");
$extractModule->nextIteration();
if ($opt_printType) {
exit;
}
if ($opt_printJSON) {
exportJSON($extractModule, $opt_benchmark, $opt_name);
exportJSON(@extractModules);
exit;
}
$extractModule->printReportTop();
if ($opt_printPlot) {
$extractModule->printPlotHeaders() if $opt_printHeader;
$extractModule->printPlot($opt_subheading);
} else {
$extractModule->printFieldHeaders() if $opt_printHeader;
$extractModule->printReport();
foreach my $extractModule (@extractModules) {
$extractModule->printReportTop();
if ($opt_printPlot) {
$extractModule->printPlotHeaders() if $opt_printHeader;
$extractModule->printPlot($opt_subheading);
} else {
$extractModule->printFieldHeaders() if $opt_printHeader;
$extractModule->printReport();
}
$extractModule->printReportBottom();
}
$extractModule->printReportBottom();

# Below this line is help and manual page information
__END__
Expand All @@ -156,7 +186,7 @@ =head1 SYNOPSIS
Options:
-d, --directory Work log directory to extract data from
-n, --name Title for the series if tests given to run-mmtests.sh
-n, --names Title for the series if tests given to run-mmtests.sh
-b, --benchmark Benchmark to extract data for
-v, --verbose Verbose output
--format=text Output format, valid are html or text (default)
Expand All @@ -179,8 +209,8 @@ =head1 OPTIONS
=item B<n, --name>
The name of the test series as supplied to run-mmtests.sh. This might have
been a kernel version for example.
The name of the test series as supplied to run-mmtests.sh. These might have
been kernel versions for example.
=item B<b, --benchmark>
Expand Down

0 comments on commit 95a39b0

Please sign in to comment.