opts = _Options() if c_api.pmGetOptionsFromList(sys.argv) != 0: c_api.pmUsageMessage() sys.exit(1) # Setup some default reporting if none specified so far if len(subsys) == 0: subsys.append(cpu) subsys.append(disk) subsys.append(net) if opts.create_archive: subsys.append(interrupt, memory) if opts.duration_arg != 0: (timeval, errmsg) = pm.pmParseInterval(str(opts.duration_arg)) duration = c_api.pmtimevalToReal(timeval) pm = pmapi.pmContext.fromOptions(opts.opts, sys.argv) if pm.type == c_api.PM_CONTEXT_ARCHIVE: pm.pmSetMode(c_api.PM_MODE_FORW, pmapi.timeval(0, 0), 0) # Find server-side pmcd host-name host = pm.pmGetContextHostName() (delta, errmsg) = pmapi.pmContext.pmParseInterval(str(opts.interval_arg) + " seconds") 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()
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 == "":
subsys.append(net) if opts.create_archive: subsys.append(interrupt) subsys.append(memory) pm = pmapi.pmContext.fromOptions(opts.opts, sys.argv) if pm.type == c_api.PM_CONTEXT_ARCHIVE: replay_archive = True input_file = opts.opts.pmGetOptionArchives()[0] pm.pmSetMode(c_api.PM_MODE_FORW, pmapi.timeval(0, 0), 0) # Find server-side pmcd host-name host = pm.pmGetContextHostName() (delta, errmsg) = pm.pmParseInterval(str(opts.interval_arg) + " seconds") delta_seconds = c_api.pmtimevalToReal(delta.tv_sec, delta.tv_usec) if opts.duration_arg != 0: (timeval, errmsg) = pm.pmParseInterval(str(opts.duration_arg)) duration = c_api.pmtimevalToReal(timeval.tv_sec, timeval.tv_usec) opts.n_samples = int((duration / delta_seconds) + 0.5) if opts.create_archive: msec = str(int(1000.0 * delta_seconds)) configuration = "log mandatory on every " + msec + " milliseconds {\n" configuration += ss.dump_metrics().replace(" ", "\n") configuration += "}\n" if duration == 0.0: if opts.n_samples != 0: duration = float(opts.n_samples) * delta_seconds else:
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 == "":