Hi,
Fix/improve pmrep CSV output handling, especially when instances are in
play. Addresses ticket #114. Updates QA accordingly.
---
qa/1069 | 2 ++
qa/1069.out | 11 +++++++++--
src/pmrep/pmrep.py | 17 ++++++++++++-----
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/qa/1069 b/qa/1069
index 58bff40..41955fc 100755
--- a/qa/1069
+++ b/qa/1069
@@ -101,6 +101,8 @@ echo "== exercise CSV and alternate delimiters"
pmrep -s 5 -t 2 $log -c $tmp.config -o csv -p -P 1 sample
pmrep -s 5 -t 2 $log -c $tmp.config -o csv --delimiter '|' sample | \
tee -a $tmp.out1
+echo "== exercise CSV and instance handling"
+pmrep -s 5 -t 2 $log2 -c $tmp.config -o csv hinv.map.scsi kernel.all.load
echo "== compare output-to-file versus stdout"
pmrep -s 5 -t 2 $log -c $tmp.config -o csv --delimiter '|' -F $tmp.out2 sample
diff $tmp.out1 $tmp.out2
diff --git a/qa/1069.out b/qa/1069.out
index 0e23cb6..02a82d9 100644
--- a/qa/1069.out
+++ b/qa/1069.out
@@ -115,18 +115,25 @@ HH:MM:SS 1
10:36:51 1.000 1000.001
10:36:53 1.000 1000.016
== exercise CSV and alternate delimiters
-Time,sample.seconds,sample.milliseconds
+Time,"sample.seconds","sample.milliseconds"
2000-05-01 20:36:45,"",""
2000-05-01 20:36:47,380434,380433679.3
2000-05-01 20:36:49,380436,380435679.4
2000-05-01 20:36:51,380438,380437679.4
2000-05-01 20:36:53,380440,380439679.4
-Time|sample.seconds|sample.milliseconds
+Time|"sample.seconds"|"sample.milliseconds"
2000-05-01 20:36:45|""|""
2000-05-01 20:36:47|380434|380433679.314
2000-05-01 20:36:49|380436|380435679.381
2000-05-01 20:36:51|380438|380437679.382
2000-05-01 20:36:53|380440|380439679.413
+== exercise CSV and instance handling
+Time,"hinv.map.scsi-scsi0:0:0:0 Direct-Access","hinv.map.scsi-scsi0:0:1:0
Direct-Access","hinv.map.scsi-scsi0:0:2:0
Direct-Access","hinv.map.scsi-scsi0:0:3:0
Direct-Access","hinv.map.scsi-scsi0:0:4:0 Direct-Access","kernel.all.load-1
minute","kernel.all.load-5 minute","kernel.all.load-15 minute"
+2013-07-06 00:47:01,"sda","sdb","sdc","sdd","sde",0.820,0.700,0.590
+2013-07-06 00:47:03,"sda","sdb","sdc","sdd","sde",0.820,0.700,0.590
+2013-07-06 00:47:05,"sda","sdb","sdc","sdd","sde",0.820,0.700,0.590
+2013-07-06 00:47:07,"sda","sdb","sdc","sdd","sde",0.820,0.700,0.590
+2013-07-06 00:47:09,"sda","sdb","sdc","sdd","sde",0.820,0.700,0.590
== compare output-to-file versus stdout
ok
== exercise repeated headers option
diff --git a/src/pmrep/pmrep.py b/src/pmrep/pmrep.py
index 04e3f95..e618684 100755
--- a/src/pmrep/pmrep.py
+++ b/src/pmrep/pmrep.py
@@ -1063,8 +1063,15 @@ class PMReporter(object):
if self.output == OUTPUT_CSV:
self.writer.write("Time")
- for metric in self.metrics:
- self.writer.write(self.delimiter + metric)
+ for i, metric in enumerate(self.metrics):
+ ins = 1 if self.insts[i][0][0] == PM_IN_NULL else
len(self.insts[i][0])
+ for j in range(ins):
+ if self.insts[i][0][0] != PM_IN_NULL and
self.insts[i][1][j]:
+ name = metric + "-" + self.insts[i][1][j]
+ else:
+ name = metric
+ name = name.replace(self.delimiter, " ").replace("\n", "
").replace("\"", " ")
+ self.writer.write(self.delimiter + "\"" + name + "\"")
self.writer.write("\n")
if self.output == OUTPUT_STDOUT:
@@ -1188,9 +1195,9 @@ class PMReporter(object):
if value == NO_VAL:
line += '""'
else:
- value = value.replace(self.delimiter, " ")
- value = value.replace("\"", "\"\"")
- line += str("\"" + value + "\"")
+ if value:
+ value = value.replace(self.delimiter, "
").replace("\n", " ").replace("\"", " ")
+ line += str("\"" + value + "\"")
self.writer.write(line + "\n")
def write_stdout(self, timestamp):
Thanks,
--
Marko Myllynen
|