# main ----------------------------------------------------------------- # ignore These are actually global names; ignore invalid name warning for now # TODO move main into a def and enable # pylint: disable-msg=C0103 if __name__ == '__main__': subsys = list() output_file = "" input_file = "" duration = 0.0 ss = Subsystem() ss.init_processor_metrics() ss.init_interrupt_metrics() ss.init_disk_metrics() ss.init_memory_metrics() ss.init_network_metrics() cpu = _cpuCollectPrint(ss) interrupt = _interruptCollectPrint(ss) disk = _diskCollectPrint(ss) memory = _memoryCollectPrint(ss) net = _netCollectPrint(ss) # Establish a PMAPI context to archive, host or local, via args opts = _Options() if c_api.pmGetOptionsFromList(sys.argv) != 0:
self.host = optarg # main ----------------------------------------------------------------- # ignore These are actually global names; ignore invalid name warning for now # TODO move main into a def and enable # pylint: disable-msg=C0103 if __name__ == '__main__': subsys = list() output_file = "" input_file = "" duration = 0.0 ss = Subsystem() ss.init_processor_metrics() ss.init_interrupt_metrics() ss.init_disk_metrics() ss.init_memory_metrics() ss.init_network_metrics() cpu = _cpuCollectPrint(ss) interrupt = _interruptCollectPrint(ss) disk = _diskCollectPrint(ss) memory = _memoryCollectPrint(ss) net = _netCollectPrint(ss) # Establish a PMAPI context to archive, host or local, via args opts = _Options() if c_api.pmGetOptionsFromList(sys.argv) != 0:
def main (stdscr_p): global stdscr stdscr = _StandardOutput(stdscr_p) output_file = "" input_file = "" sort = "" duration = 0 interval_arg = 5 duration_arg = 0 n_samples = 0 output_type = "g" host = "" create_archive = False replay_archive = False i = 1 subsys_options = ("g", "m") class NextOption(Exception): pass while i < len(sys.argv): try: if (sys.argv[i][:1] == "-"): for ssx in subsys_options: if sys.argv[i][1:] == ssx: output_type = ssx raise NextOption if (sys.argv[i] == "-w"): i += 1 output_file = sys.argv[i] create_archive = True elif (sys.argv[i] == "-r"): i += 1 input_file = sys.argv[i] replay_archive = True elif (sys.argv[i] == "-L"): i += 1 stdscr.width = int(sys.argv[i]) elif (sys.argv[i] == "--help"): return usage() elif (sys.argv[i] == "-h"): i += 1 host = sys.argv[i] else: return sys.argv[0] + ": Unknown option " + sys.argv[i] \ + "\nTry `" + sys.argv[0] + " --help' for more information." else: interval_arg = int(sys.argv[i]) i += 1 if (i < len(sys.argv)): n_samples = int(sys.argv[i]) i += 1 except NextOption: i += 1 pass ss = Subsystem() ss.init_processor_metrics() ss.init_memory_metrics() ss.init_disk_metrics() ss.init_network_metrics() ss.init_process_metrics() cpu = _ProcessorPrint(ss, stdscr) mem = _MemoryPrint(ss, stdscr) disk = _DiskPrint(ss, stdscr) net = _NetPrint(ss, stdscr) proc = _ProcPrint(ss, stdscr) proc.output_type = output_type if replay_archive: archive = input_file if not os.path.exists(input_file): return input_file + " does not exist" for line in open(input_file): if (line[:8] == "Archive:"): tokens = line[:-1].split() archive = os.path.join(os.path.dirname(input_file), tokens[2]) try: pmc = pmapi.pmContext(c_api.PM_CONTEXT_ARCHIVE, archive) except pmapi.pmErr, e: return "Cannot open PCP archive: " + archive
def main(stdscr_p): global stdscr stdscr = _StandardOutput(stdscr_p) sort = "" duration = 0.0 i = 1 ss = Subsystem() ss.init_processor_metrics() ss.init_memory_metrics() ss.init_disk_metrics() ss.init_network_metrics() ss.init_process_metrics() cpu = _ProcessorPrint(ss, stdscr) mem = _MemoryPrint(ss, stdscr) disk = _DiskPrint(ss, stdscr) net = _NetPrint(ss, stdscr) proc = _ProcPrint(ss, stdscr) proc.output_type = opts.output_type stdscr.width = opts.width pmc = pmapi.pmContext.fromOptions(opts.opts, sys.argv) if pmc.type == c_api.PM_CONTEXT_ARCHIVE: pmc.pmSetMode(c_api.PM_MODE_FORW, pmapi.timeval(0, 0), 0) host = pmc.pmGetContextHostName() (delta, errmsg) = pmc.pmParseInterval(str(opts.interval_arg) + " seconds") ss.setup_metrics(pmc) if opts.create_archive: delta_seconds = c_api.pmtimevalToReal(delta.tv_sec, delta.tv_usec) msec = str(int(1000.0 * delta_seconds)) configuration = "log mandatory on every " + msec + " milliseconds { " configuration += ss.dump_metrics() configuration += "}" if opts.n_samples != 0: duration = float(opts.n_samples) * delta_seconds else: duration = float(10) * delta_seconds status = record(pmgui.GuiClient(), configuration, duration, opts.output_file, host) if status != "": return status record_add_creator(opts.output_file) sys.exit(0) i_samples = 0 disk.interval = delta.tv_sec disk.replay_archive = opts.replay_archive try: elapsed = ss.get_metric_value('kernel.all.uptime') while (i_samples < opts.n_samples) or (opts.n_samples == 0): ss.get_stats(pmc) stdscr.move(0, 0) stdscr.addstr('ATOP - %s %s elapsed\n\n' % ( time.strftime("%c"), datetime.timedelta(0, elapsed))) elapsed = delta.tv_sec stdscr.move(2, 0) try: cpu.prc() cpu.cpu() mem.mem() disk.disk(pmc) net.net(pmc) proc.set_line() proc.proc() except pmapi.pmErr as e: return str(e) + " while processing " + str(ssx[0]) except Exception as e: # catch all errors, pcp or python or other pass stdscr.move(proc.command_line, 0) stdscr.refresh() stdscr.timeout(delta.tv_sec * 1000) char = stdscr.getch() if char != -1: # user typed a command try: cmd = chr(char) except ValueError: cmd = None if cmd == "q": raise KeyboardInterrupt elif cmd == "":
def main(stdscr_p): global stdscr stdscr = _StandardOutput(stdscr_p) sort = "" duration = 0.0 i = 1 ss = Subsystem() ss.init_processor_metrics() ss.init_memory_metrics() ss.init_disk_metrics() ss.init_network_metrics() ss.init_process_metrics() cpu = _ProcessorPrint(ss, stdscr) mem = _MemoryPrint(ss, stdscr) disk = _DiskPrint(ss, stdscr) net = _NetPrint(ss, stdscr) proc = _ProcPrint(ss, stdscr) proc.output_type = opts.output_type stdscr.width = opts.width pmc = pmapi.pmContext.fromOptions(opts.opts, sys.argv) if pmc.type == c_api.PM_CONTEXT_ARCHIVE: pmc.pmSetMode(c_api.PM_MODE_FORW, pmapi.timeval(0, 0), 0) host = pmc.pmGetContextHostName() (delta, errmsg) = pmc.pmParseInterval(str(opts.interval_arg) + " seconds") ss.setup_metrics(pmc) if opts.create_archive: delta_seconds = c_api.pmtimevalToReal(delta.tv_sec, delta.tv_usec) msec = str(int(1000.0 * delta_seconds)) configuration = "log mandatory on every " + msec + " milliseconds { " configuration += ss.dump_metrics() configuration += "}" if opts.n_samples != 0: duration = float(opts.n_samples) * delta_seconds else: duration = float(10) * delta_seconds status = record(pmgui.GuiClient(), configuration, duration, opts.output_file, host) if status != "": return status record_add_creator(opts.output_file) sys.exit(0) i_samples = 0 disk.interval = delta.tv_sec disk.replay_archive = opts.replay_archive try: elapsed = ss.get_metric_value('kernel.all.uptime') while (i_samples < opts.n_samples) or (opts.n_samples == 0): ss.get_stats(pmc) stdscr.move(0, 0) stdscr.addstr('ATOP - %s\t\t%s elapsed\n\n' % ( time.strftime("%c"), datetime.timedelta(0, elapsed))) elapsed = delta.tv_sec stdscr.move(2, 0) try: cpu.prc() cpu.cpu() mem.mem() disk.disk(pmc) net.net(pmc) proc.set_line() proc.proc() except pmapi.pmErr as e: return str(e) + " while processing " + str(ssx[0]) except Exception as e: # catch all errors, pcp or python or other pass stdscr.move(proc.command_line, 0) stdscr.refresh() stdscr.timeout(delta.tv_sec * 1000) char = stdscr.getch() if char != -1: # user typed a command try: cmd = chr(char) except ValueError: cmd = None if cmd == "q": raise KeyboardInterrupt elif cmd == "":