aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric B Munson <ebmunson@us.ibm.com>2010-03-24 15:02:40 +0000
committerEric B Munson <ebmunson@us.ibm.com>2010-03-25 09:48:07 +0000
commit8fb9dca78f3ec1e28cc777ef70580d9dd16fa69a (patch)
tree2664d47721d9bc9a77ca080986083169443747a4
parent820146642a4f6ccd338e312dee0ed6c083325ac1 (diff)
downloadlibhugetlbfs-8fb9dca78f3ec1e28cc777ef70580d9dd16fa69a.tar.gz
Protect against div by 0 error
Currently if no dtlb misses are observed in a time period and either --misses-per-instruction or --misses-per-cycle are specified, the script will hit a division by zero error. This patch protects the division against this error. Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
-rwxr-xr-xcpupcstat12
1 files changed, 10 insertions, 2 deletions
diff --git a/cpupcstat b/cpupcstat
index c928263..2de14cf 100755
--- a/cpupcstat
+++ b/cpupcstat
@@ -140,15 +140,23 @@ sub run_profile()
$ret = $collector->get_current_eventcount($binName,
"instructions");
$ins_new = $ret - $ins_prev;
- printf("%24f\n",
+ if ($new == 0) {
+ printf("%24f\n", $new);
+ } else {
+ printf("%24f\n",
($ins_new * $ins_scale) / ($new * $miss_scale));
+ }
$ins_prev = $ret;
} elsif ($cycle_ratio) {
$ret = $collector->get_current_eventcount($binName,
"timer");
$cyc_new = $ret - $cyc_prev;
- printf("%24f\n",
+ if ($new == 0) {
+ printf("%24f\n", $new);
+ } else {
+ printf("%24f\n",
($cyc_new * $cyc_scale) / ($new * $miss_scale));
+ }
$cyc_prev = $ret;
} else {
print("\n");