Skip to content

Commit 641a583

Browse files
authored
Merge pull request #109 from Zengkai163/master
Add brief mode for cpu info display
2 parents 2c29fe3 + f7eee8e commit 641a583

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

UnixBench/Run

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ my $RESULTDIR = getDir('UB_RESULTDIR', $FindBin::Bin . "/results");
100100
# Directory where the tests are executed.
101101
my $TESTDIR = getDir('UB_TESTDIR', $FindBin::Bin . "/testdir");
102102

103+
my $quietMode = 0;
104+
my $notQuietMode = 1;
105+
my $verboseMode = 2;
106+
my $briefMode = 3;
103107

104108
############################################################################
105109
# TEST SPECIFICATIONS
@@ -945,6 +949,7 @@ sub getNumActiveCpus {
945949
# load System load message as per "uptime".
946950
# numUsers Number of users and/or open shell sessions.
947951
sub getSystemInfo {
952+
my ( $verbose ) = @_;
948953
my $info = { };
949954

950955
# Get host system data.
@@ -979,10 +984,12 @@ sub getSystemInfo {
979984
$lang, $map, $coll;
980985

981986
# Get details on the CPUs, if possible.
982-
my $cpus = getCpuInfo();
983-
if (defined($cpus)) {
984-
$info->{'cpus'} = $cpus;
985-
$info->{'numCpus'} = scalar(@$cpus);
987+
if ($verbose != $briefMode) {
988+
my $cpus = getCpuInfo();
989+
if (defined($cpus)) {
990+
$info->{'cpus'} = $cpus;
991+
$info->{'numCpus'} = scalar(@$cpus);
992+
}
986993
}
987994

988995
# Get available number of CPUs (not disabled CPUs), if possible.
@@ -1066,9 +1073,11 @@ sub parseArgs {
10661073
die("Run: unknown test \"$word\"\n");
10671074
}
10681075
} elsif ($word eq "-q") {
1069-
$params->{'verbose'} = 0;
1076+
$params->{'verbose'} = $quietMode;
10701077
} elsif ($word eq "-v") {
1071-
$params->{'verbose'} = 2;
1078+
$params->{'verbose'} = $verboseMode;
1079+
} elsif ($word eq "-b") {
1080+
$params->{'verbose'} = $briefMode;
10721081
} elsif ($word eq "-i") {
10731082
$params->{'iterations'} = shift(@words);
10741083
} elsif ($word eq "-c") {
@@ -1430,7 +1439,7 @@ sub runOnePass {
14301439

14311440
# Get the command to run.
14321441
my $command = $params->{'command'};
1433-
if ($verbose > 1) {
1442+
if ($verbose == $verboseMode) {
14341443
printf "\n";
14351444
printf "COMMAND: \"%s\"\n", $command;
14361445
printf "COPIES: \"%d\"\n", $copies;
@@ -1497,7 +1506,7 @@ sub runBenchmark {
14971506
# Set up the benchmark results structure.
14981507
my $bresult = { 'name' => $bench, 'msg' => $params->{'logmsg'} };
14991508

1500-
if ($verbose > 0) {
1509+
if ($verbose > $quietMode) {
15011510
printf "\n%d x %s ", $copies, $params->{'logmsg'};
15021511
}
15031512

@@ -1518,7 +1527,7 @@ sub runBenchmark {
15181527
# make an attempt to flush buffers
15191528
system("sync; sleep 1; sync; sleep 2");
15201529
# display heartbeat
1521-
if ($verbose > 0) {
1530+
if ($verbose > $quietMode) {
15221531
printf " %d", $i;
15231532
}
15241533

@@ -1548,7 +1557,7 @@ sub runBenchmark {
15481557
unlink(${TESTDIR} . "/a.out");
15491558
}
15501559

1551-
if ($verbose > 0) {
1560+
if ($verbose > $quietMode) {
15521561
printf "\n";
15531562
}
15541563

@@ -1603,7 +1612,7 @@ sub runTests {
16031612
# Display a banner indicating the configuration of the system under test
16041613
# to the given file desc.
16051614
sub displaySystem {
1606-
my ( $info, $fd ) = @_;
1615+
my ( $info, $fd, $verbose ) = @_;
16071616

16081617
# Display basic system info.
16091618
printf $fd " System: %s: %s\n", $info->{'name'}, $info->{'system'};
@@ -1615,7 +1624,9 @@ sub displaySystem {
16151624
# Get and display details on the CPUs, if possible.
16161625
my $cpus = $info->{'cpus'};
16171626
if (!defined($cpus)) {
1618-
printf $fd " CPU: no details available\n";
1627+
if ($verbose != $briefMode) {
1628+
printf $fd " CPU: no details available\n";
1629+
}
16191630
} else {
16201631
for (my $i = 0; $i <= $#$cpus; ++$i) {
16211632
printf $fd " CPU %d: %s (%.1f bogomips)\n",
@@ -1833,7 +1844,7 @@ EOF
18331844
# Display a banner indicating the configuration of the system under test
18341845
# to the given file desc.
18351846
sub displaySystemHtml {
1836-
my ( $info, $fd ) = @_;
1847+
my ( $info, $fd ,$verbose) = @_;
18371848

18381849
printf $fd "<h3>Test System Information</h3>\n";
18391850
printf $fd "<p><table>\n";
@@ -1859,10 +1870,12 @@ sub displaySystemHtml {
18591870
# Get and display details on the CPUs, if possible.
18601871
my $cpus = $info->{'cpus'};
18611872
if (!defined($cpus)) {
1862-
printf $fd "<tr>\n";
1863-
printf $fd " <td><b>CPUs:</b></td>\n";
1864-
printf $fd " <td colspan=2>no details available</td>\n";
1865-
printf $fd "</tr>\n";
1873+
if ($verbose != $briefMode) {
1874+
printf $fd "<tr>\n";
1875+
printf $fd " <td><b>CPUs:</b></td>\n";
1876+
printf $fd " <td colspan=2>no details available</td>\n";
1877+
printf $fd "</tr>\n";
1878+
}
18661879
} else {
18671880
for (my $i = 0; $i <= $#$cpus; ++$i) {
18681881
printf $fd "<tr>\n";
@@ -2036,7 +2049,7 @@ sub main {
20362049
my @args = @_;
20372050

20382051
my $params = parseArgs(@args);
2039-
my $verbose = $params->{'verbose'} || 1;
2052+
my $verbose = $params->{'verbose'} || $notQuietMode;
20402053
if ($params->{'iterations'}) {
20412054
$longIterCount = $params->{'iterations'};
20422055
$shortIterCount = int(($params->{'iterations'} + 1) / 3);
@@ -2054,7 +2067,7 @@ sub main {
20542067
createDirrectoriesIfNotExists(@creatingDirectories);
20552068

20562069
preChecks();
2057-
my $systemInfo = getSystemInfo();
2070+
my $systemInfo = getSystemInfo($verbose);
20582071

20592072
# If the number of copies to run was not set, set it to 1
20602073
# and the number of CPUs in the system (if > 1).
@@ -2070,11 +2083,11 @@ sub main {
20702083
system("cat \"${BINDIR}/unixbench.logo\"");
20712084

20722085
# Show output output directories, if not in quiet mode.
2073-
if ($verbose > 0) {
2086+
if ($verbose > $quietMode) {
20742087
printUsingDirectories();
20752088
}
20762089

2077-
if ($verbose > 1) {
2090+
if ($verbose == $verboseMode) {
20782091
printf "\n", join(", ", @$tests);
20792092
printf "Tests to run: %s\n", join(", ", @$tests);
20802093
}
@@ -2106,14 +2119,14 @@ sub main {
21062119
runHeaderHtml($systemInfo, $reportFd2);
21072120

21082121
# Dump information about the system under test.
2109-
displaySystem($systemInfo, $reportFd);
2110-
displaySystemHtml($systemInfo, $reportFd2);
2122+
displaySystem($systemInfo, $reportFd, $verbose);
2123+
displaySystemHtml($systemInfo, $reportFd2, $verbose);
21112124

21122125
# Run the tests! Do a test run once for each desired number of copies;
21132126
# for example, on a 2-CPU system, we may do a single-processing run
21142127
# followed by a dual-processing run.
21152128
foreach my $c (@$copies) {
2116-
if ($verbose > 1) {
2129+
if ($verbose == $verboseMode) {
21172130
printf "Run with %s\n", number($c, "copy", "copies");
21182131
}
21192132
my $results = runTests($tests, $verbose, $logFile, $c);
@@ -2140,7 +2153,7 @@ sub main {
21402153
}
21412154

21422155
# Display the report, if not in quiet mode.
2143-
if ($verbose > 0) {
2156+
if ($verbose > $quietMode) {
21442157
printf "\n";
21452158
printf "========================================================================\n";
21462159
system("cat \"$reportFile\"");

UnixBench/USAGE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ The Run script takes a number of options which you can use to customise a
3535
test, and you can specify the names of the tests to run. The full usage
3636
is:
3737

38-
Run [ -q | -v ] [-i <n> ] [-c <n> [-c <n> ...]] [test ...]
38+
Run [ -q | -b | -v ] [-i <n> ] [-c <n> [-c <n> ...]] [test ...]
3939

4040
The option flags are:
4141

4242
-q Run in quiet mode.
43+
-b Run in brief mode, do not display mass of cpu info details.
4344
-v Run in verbose mode.
4445
-i <count> Run <count> iterations for each test -- slower tests
4546
use <count> / 3, but at least 1. Defaults to 10 (3 for

0 commit comments

Comments
 (0)