# UProcTrace: User-space Process Tracing
# Copyright 2020: Stefan Schuermans, Aachen, Germany <stefan@schuermans.info>
# Copyleft: GNU LESSER GENERAL PUBLIC LICENSE version 3 (see LICENSE)
"""
Command line interface of UProcTrace: "upt-tool".
"""
import argparse
import shlex
import sys
def dump(args):
"""
Dump all events in trace file to standard output.
"""
import uproctrace.dump
with open(args.trace, 'rb') as proto_file:
while uproctrace.dump.dump_event(proto_file, sys.stdout):
pass
def gui(args):
"""
Run the graphical user interface.
"""
import uproctrace.gui
uproctrace.gui.run(args.trace)
def pstree(args):
"""
Print process tree.
"""
import uproctrace.processes
with open(args.trace, 'rb') as proto_file:
processes = uproctrace.processes.Processes(proto_file)
# tree output (iterative)
to_be_output = [processes.toplevel]
while to_be_output:
procs = to_be_output[-1]
if not procs:
del to_be_output[-1]
continue
indent = ' ' * (len(to_be_output) - 1)
proc = procs[0]
del procs[0]
cmdline = proc.cmdline
if cmdline is None:
cmdline_str = '???'