def benchmark(cls, sysinfo=True): """ prints out all timers in a convenient benchmark tabble :return: :rtype: """ # # PRINT PLATFORM # if sysinfo: data_platform = systeminfo() print( Printer.attribute(data_platform, ["Machine Arribute", "Time/s"])) # # PRINT TIMERS # timers = StopWatch.keys() data_timers = {} for timer in timers: data_timers[timer] = { 'time': round(StopWatch.get(timer), 2), 'timer': timer } for attribute in [ "node", "system", "machine", "mac_version", "win_version" ]: data_timers[timer][attribute] = data_platform[attribute] # print(Printer.attribute(data_timers, header=["Command", "Time/s"])) print( Printer.write(data_timers, order=[ "timer", "time", "node", "system", "mac_version", "win_version" ])) print() print( Printer.write(data_timers, order=[ "timer", "time", "node", "system", "mac_version", "win_version" ], output="csv"))
def do_dictComm(self, args, arguments): """ :: Usage: dictComm time dictComm --ping=PING dictComm system This command does some useful things. Arguments: PING a site to ping Options: -p specify the site to ping """ arguments.PING = arguments["--ping"] or None VERBOSE(arguments) m = Manager() if arguments.time: print("option a") pprint(datetime.now()) elif arguments.PING: print("option b - ping a site") m.list(subprocess.run(["ping", arguments.PING, "-n", "1"])) elif arguments.system: print("option c - system") m.list(arguments) pprint(systeminfo()) Console.error("This is just a sample") return ""
def benchmark(cls, sysinfo=True, csv=True, prefix="# csv", tag=None, sum=True): """ prints out all timers in a convenient benchmark table :return: :rtype: """ # # PRINT PLATFORM # print() data_platform = systeminfo() data_platform['cpu_count'] = multiprocessing.cpu_count() if sysinfo: print(Printer.attribute( data_platform, order=["Machine Attribute", "Value"], output="table" )) # # PRINT TIMERS # timers = StopWatch.keys() if len(timers) > 0: data_timers = {} for timer in timers: data_timers[timer] = { 'start': time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime( StopWatch.timer_start[timer])), 'time': StopWatch.get(timer, digits=3), 'sum': StopWatch.sum(timer, digits=3), 'status': StopWatch.get_status(timer), 'timer': timer, 'tag': tag or '' } for attribute in ["uname.node", "user", "uname.system", "uname.machine", "platform.version", "sys.platform"]: data_timers[timer][attribute] = data_platform[attribute] # print(Printer.attribute(data_timers, header=["Command", "Time/s"])) if 'benchmark_start_stop' in data_timers: del data_timers['benchmark_start_stop'] for key in data_timers: if key != 'benchmark_start_stop' and data_timers[key][ 'status'] == None: data_timers[key]['status'] = "failed" elif data_timers[key]['status'] != None and data_timers[key][ 'status'] == True: data_timers[key]['status'] = "ok" order = [ "timer", "status", "time", "sum", "start", "tag", "uname.node", "user", "uname.system", "platform.version" ] header = [ "Name", "Status", "Time", "Sum", "Start", "tag", "Node", "User", "OS", "Version" ] print() print(Printer.write( data_timers, order=order, header=header, output="table" )) print() if csv: if prefix is not None: for entry in data_timers: data_timers[entry]["# csv"] = prefix order = ["# csv"] + order print(Printer.write( data_timers, order=order, header=header, output="csv" )) else: pprint(data_timers) print(Printer.write( data_timers, order=order[1:], output="csv" )) else: print("ERROR: No timers found")
def benchmark(cls, sysinfo=True, csv=True, tag=None): """ prints out all timers in a convenient benchmark table :return: :rtype: """ # # PRINT PLATFORM # print() data_platform = systeminfo() data_platform['cpu_count'] = multiprocessing.cpu_count() mem = psutil.virtual_memory() try: data_platform['mem_total'] = humanize.naturalsize(mem.total, \ binary=True) except: pass try: data_platform['mem_available'] = humanize.naturalsize( mem.available, binary=True) except: pass try: data_platform['mem_percent'] = str(mem.percent) + "%" except: pass try: data_platform['mem_used'] = humanize.naturalsize(mem.used, binary=True) except: pass try: data_platform['mem_free'] = humanize.naturalsize(mem.free, binary=True) except: pass try: data_platform['mem_active'] = humanize.naturalsize(mem.active, binary=True) except: pass try: data_platform['mem_inactive'] = humanize.naturalsize(mem.inactive, binary=True) except: pass try: data_platform['mem_wired'] = humanize.naturalsize(mem.wired, binary=True) except: pass # svmem(total=17179869184, available=6552825856, percent=61.9, if sysinfo: print( Printer.attribute(data_platform, ["Machine Attribute", "Value"])) # # PRINT TIMERS # timers = StopWatch.keys() if len(timers) > 0: data_timers = {} for timer in timers: data_timers[timer] = { 'start': time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(StopWatch.timer_start[timer])), 'time': StopWatch.get(timer, digits=3), 'timer': timer, 'tag': tag or '' } for attribute in [ "node", "user", "system", "machine", "mac_version", "win_version" ]: data_timers[timer][attribute] = data_platform[attribute] # print(Printer.attribute(data_timers, header=["Command", "Time/s"])) print( Printer.write(data_timers, order=[ "timer", "time", "start", "tag", "node", "user", "system", "mac_version", "win_version" ])) print() if csv: print( Printer.write(data_timers, order=[ "timer", "time", "start" "tag", "node", "user", "system", "mac_version", "win_version" ], output="csv")) else: print("ERROR: No timers found")