Browse Source

Unify CLI for ASCII and old plots

check-vt100
Aleksander Kiryk 4 years ago
parent
commit
a501ec6ea2
  1. 2
      .ci.yml
  2. 7
      common.py
  3. 28
      graph.py
  4. 2
      sargraph.py
  5. 4
      watch.py

2
.ci.yml

@ -29,7 +29,7 @@ simple_test:
- sargraph chart stop
- test -f plot.svg
- test -f plog.png
- test -f plot.png
- test -f plot.ascii
- cat chart.log

7
common.py

@ -46,6 +46,13 @@ def stof(s):
return float(s.replace(',', '.'))
# Return a string without given suffix or unchange if it doesn't have it
def cut_suffix(s, sfx):
if s.endswith(sfx):
s = s[:-len(sfx)]
return s
# Scale a value until it has a convenient size and unit, round the value
# and return a string representation with the new value and its unit
def unit_str(value, units, step=1024):

28
graph.py

@ -198,21 +198,31 @@ def graph(session, fname='plot.png'):
OUTPUT_TYPE = "pngcairo"
OUTPUT_EXT = "png"
if "SARGRAPH_OUTPUT_TYPE" in os.environ:
if os.environ["SARGRAPH_OUTPUT_TYPE"] == "svg":
OUTPUT_TYPE = "svg"
OUTPUT_EXT = "svg"
otype = os.environ["SARGRAPH_OUTPUT_TYPE"].lower()
# png is the default, so don't change anything
if otype != "png":
OUTPUT_TYPE = otype
OUTPUT_EXT = otype
elif fname.lower().endswith('.png'):
# png is the default, so don't change anything
pass
elif fname.lower().endswith('.svg'):
OUTPUT_TYPE = "svg"
OUTPUT_EXT = "svg"
elif fname.lower().endswith('.png'):
# Otherwise leave the default png
pass
elif fname.lower().endswith('.ascii'):
OUTPUT_TYPE = "ascii"
OUTPUT_EXT = "ascii"
else:
pass
# fail("unknown graph extension")
# Leave just the base name
fname = fname[:-4]
fname = cut_suffix(fname, f".{OUTPUT_EXT}")
# ASCII plots have their own routine
if OUTPUT_TYPE == "ascii":
return ascii_graph(session, fname)
read_comments(session)
@ -430,7 +440,7 @@ def render_ascii_plot(
print('\n\n')
def ascii_graph(session, fname='plot.png'):
def ascii_graph(session, fname='plot.ascii'):
data = read_data(session)
titles = [f"""cpu load (average = {AVERAGE_LOAD} %)""",
f"""ram usage (max = {MAX_USED_RAM})""",
@ -450,7 +460,7 @@ def ascii_graph(session, fname='plot.png'):
summary += f"Duration: {START_DATE} .. {END_DATE} ({DURATION})"
render_ascii_plot(
f'{Path(fname).with_suffix(".plot.txt")}',
Path(fname).with_suffix(".ascii"),
summary,
titles,
["time", "time", "time"],

2
sargraph.py

@ -106,9 +106,7 @@ elif cmd[0] == 'save':
elif cmd[0] == 'plot':
if len(cmd) < 2:
graph.graph(sid)
graph.ascii_graph(sid)
else:
graph.graph(sid, cmd[1])
graph.ascii_graph(sid, cmd[1])
else:
fail(f"unknown command '{cmd[0]}'")

4
watch.py

@ -174,10 +174,8 @@ def watch(session, fsdev):
pass
elif label_line:
graph.graph(session, label_line)
graph.ascii_graph(session, label_line)
elif not dont_plot:
graph.graph(session)
graph.ascii_graph(session)
dont_plot = True
die = 1
break
@ -190,10 +188,8 @@ def watch(session, fsdev):
summarize(session)
if not label_line:
graph.graph(session)
graph.ascii_graph(session)
else:
graph.graph(session, label_line)
graph.ascii_graph(session, label_line)
elif label_line.startswith('label:'):
label_line = label_line[len('label:'):]
with open(f"{session}.txt", "a") as f:

Loading…
Cancel
Save