Skip to content

Commit

Permalink
toplev: Support --columns in csv mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Andi Kleen committed Oct 9, 2015
1 parent 1e79136 commit 80f905c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ analysis on Intel CPUs on top of [Linux perf](https://perf.wiki.kernel.org/index

# Recent new features:

* toplev now supports columnar output in CSV mode (-x, --column)
* toplev can print the critical bottleneck with --bottleneck
* The tools can now find event lists for the original user of sudo
* jevents now has a perf stat like tool called jstat (renamed to jestat)
Expand Down
1 change: 1 addition & 0 deletions tl-tester
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ EVENTMAP=${cpus[hsw]} FORCECPU=hsw $WRAP ./toplev.py --graph -o x.png -d --metri
fi
EVENTMAP=${cpus[ivb]} FORCECPU=ivb $WRAP ./toplev.py -d -l4 -I 100 sleep 1
EVENTMAP=${cpus[ivb]} FORCECPU=ivb $WRAP ./toplev.py -d -l4 -I 100 --columns sleep 1
EVENTMAP=${cpus[ivb]} FORCECPU=ivb $WRAP ./toplev.py -d -l4 -I 100 --columns -x, sleep 1
EVENTMAP=${cpus[ivb]} FORCECPU=ivb $WRAP ./toplev.py -d -l4 --valcsv val.csv --user $LOAD | tee log
grep :u log
grep /u log
Expand Down
56 changes: 55 additions & 1 deletion toplev.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,57 @@ def flush(self):
self.print_desc(desc, sample)
self.nodes = dict()

class OutputColumnsCSV(OutputColumns):
"""Columns output in CSV mode."""

def __init__(self, logfile, sep):
OutputColumns.__init__(self, logfile)
self.writer = csv.writer(self.logf, delimiter=sep)
self.printed_header = False

def show(self, timestamp, title, area, hdr, s, remark, desc, sample, valstat):
self.timestamp = timestamp
key = (area, hdr)
if key not in self.nodes:
self.nodes[key] = dict()
assert title not in self.nodes[key]
self.nodes[key][title] = (s, remark, desc, sample, valstat)

def flush(self):
cpunames = sorted(self.cpunames)
if not self.printed_header:
ts = ["Timestamp"] if self.timestamp else []
self.writer.writerow(ts + ["Area", "Node"] + cpunames + ["Description", "Sample", "Stddev", "Multiplex"])
self.printed_header = True
for key in sorted(sorted(self.nodes.keys(), key=lambda x: x[1]), key=lambda x: x[0] == ""):
node = self.nodes[key]
ts = [self.timestamp] if self.timestamp else []
l = ts + [key[0], key[1]]
vlist = []
ol = dict()
desc, sample = "", ""
for cpuname in cpunames:
if cpuname in node:
cpu = node[cpuname]
if cpu[2]:
desc = cpu[2]
if cpu[3]:
sample = cpu[3]
# ignore remark for now
if cpu[4]:
vlist.append(cpu[4])
ol[cpuname] = float(cpu[0])
l += [ol[x] if x in ol else "" for x in cpunames]
l.append(desc)
l.append(sample)
vs = combine_valstat(vlist)
if vs:
l += (vs.stddev, vs.multiplex if not isnan(vs.multiplex) else "")
else:
l += ["", ""]
self.writer.writerow(l)
self.nodes = dict()

class OutputCSV(Output):
"""Output data in CSV format."""
def __init__(self, logfile, sep):
Expand Down Expand Up @@ -1784,7 +1835,10 @@ def setup_with_metrics(p, runner):

runner.collect()
if csv_mode:
out = OutputCSV(args.output, csv_mode)
if args.columns:
out = OutputColumnsCSV(args.output, csv_mode)
else:
out = OutputCSV(args.output, csv_mode)
elif args.columns:
out = OutputColumns(args.output)
else:
Expand Down

0 comments on commit 80f905c

Please sign in to comment.