Commit bcc75931 authored by Mario Hock's avatar Mario Hock
Browse files

cnl_ls --summary

Two column output of matching files, similar to "visualize_brief()".
parent 22a5f447
......@@ -2,9 +2,10 @@
# -*- coding:utf-8 -*-
import os
from collections import defaultdict, deque
from cnl_library import CNLParser
from collections import defaultdict, deque
from summary import LogAnalyzer, show_match
def list_files_in_cur_dir():
......@@ -51,7 +52,7 @@ def merge_comments(left_file, right_file):
def print_line(left_file, right_file, long=False):
def print_line(left_file, right_file, long):
out = ""
if ( right_file ):
......@@ -72,6 +73,27 @@ def print_line(left_file, right_file, long=False):
print( out )
def show_summary(left_file, right_file=None):
## BRANCH: No match -> fallback to show_brief()
if ( not right_file ):
log = LogAnalyzer(left_file)
log.summarize()
log.show_brief()
## BRANCH: Match -> Display both next to each other.
else:
log_left = LogAnalyzer(left_file)
log_right = LogAnalyzer(right_file)
show_match(log_left, log_right)
def show(left_file, right_file, long=False, summary=False):
if ( summary ):
show_summary(left_file, right_file)
else:
print_line(left_file, right_file, long)
## MAIN ##
if __name__ == "__main__":
......@@ -84,6 +106,7 @@ if __name__ == "__main__":
parser.add_argument("files", nargs='*')
parser.add_argument("-l", "--long", action="store_true")
parser.add_argument("-s", "--summary", action="store_true")
args = parser.parse_args()
......@@ -112,14 +135,14 @@ if __name__ == "__main__":
for left_file in left_files:
matching_file = find_match(left_file, right_files)
print_line(left_file, matching_file, args.long)
show(left_file, matching_file, args.long, args.summary)
## Print left over right files.
if ( len(right_files) > 0 ):
print()
for f in right_files:
print_line(f, None, args.long)
show(f, None, args.long, args.summary)
## Print files with different hostnames
......@@ -129,8 +152,7 @@ if __name__ == "__main__":
for h in hostnames[2:]:
for f in cnl_files[h]:
print_line(f, None, args.long)
show(f, None, args.long, args.summary)
......
......@@ -35,6 +35,30 @@ def print_in_two_columns(format_str, left_col, right_col):
def show_match(left_file, right_file):
"""
Displays a brief summary of two CNL-file next to each other.
Should be used with two files that belong to the same experiment
(e.g. sender and receiver).
"""
left_head, left_rates = left_file.as_column()
right_head, right_rates = right_file.as_column()
## Head
print_in_two_columns("{:<50} {}", left_head, right_head)
## Rates
print_in_two_columns("{:<58} {}", left_rates, right_rates)
# Note: The escape sequence for the "rate-bar" is counted as characters.. :-/
print()
print()
class LogAnalyzer:
def __init__(self, cnl_file):
......@@ -63,6 +87,9 @@ class LogAnalyzer:
self.sums = [0.0] * len(self.watch_fields)
## Trigger "summarize"
self._summarize()
def _is_activity(self, line):
for field_name in self.watch_indices:
......@@ -84,7 +111,7 @@ class LogAnalyzer:
return line[self.end_index]
def summarize(self):
def _summarize(self):
for line in self.cnl_file.get_csv_iterator():
## on active samples
......@@ -147,25 +174,28 @@ class LogAnalyzer:
def visualize_brief(self):
def as_column(self):
## TODO change name?
## Head
head = list()
filename = os.path.basename(self.cnl_file.filename)
comments = self.cnl_file.get_comment().split(";")
left_col = list()
right_col = list()
#left_col.append( sprint_bold(filename + ":") )
left_col.append( filename + ":" )
head.append( filename )
for comment in comments:
left_col.append(comment.strip()[:48])
head.append(comment.strip()[:48])
speeds = list()
## Transmission rates
rates = list()
for i in range( len(self.sums) ):
speed = self.sums[i] / self.experiment_duration
number_str = "{:.2f}".format( round(speed / divisor, rounding_digits) )
#text = "{:>10} {}/s".format(s1, unit)
bar_str = "{:<20}".format(number_str + " " + unit + "/s")
label = "{:<6}".format( self.nics[int(i/2)] + ":" if i%2==0 else "" )
......@@ -173,10 +203,16 @@ class LogAnalyzer:
parts = split_proprtionally(bar_str, [speed, 1000000*10000-speed])
text = label + "|" + sprint_inverted(parts[0]) + parts[1] + "|"
right_col.append( text )
rates.append( text )
return head, rates
print_in_two_columns("{:<50} {}", left_col, right_col )
def visualize_brief(self):
head, rates = self.as_column()
print_in_two_columns("{:<50} {}", head, rates )
......@@ -191,7 +227,7 @@ if __name__ == "__main__":
cnl_file = CNLParser(filename)
log = LogAnalyzer(cnl_file)
log.summarize()
#log.summarize()
if ( len(filenames) > 1 ):
#log.show_brief()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment