コード例 #1
0
 def test_process_start_time(self):
     # Mostly just a smoke test.
     start_t_ms = timestamp.process_start_time_ms()
     age_ms = timestamp.process_age_ms()
     now = timestamp.now_ms()
     self.assertTrue(start_t_ms < now)
     self.assertTrue(((start_t_ms + age_ms) - now) < 10)
コード例 #2
0
 def test_process_start_time(self):
     # Mostly just a smoke test.
     start_t_ms = timestamp.process_start_time_ms()
     age_ms = timestamp.process_age_ms()
     now = timestamp.now_ms()
     self.assertTrue(start_t_ms < now)
     self.assertTrue(((start_t_ms + age_ms) - now) < 10)
コード例 #3
0
def build_sysinfo_page():
    contents = ["<html><head><title>System Information</title></head><body>"]
    contents.append("<h1>System Information</h1>")
    contents.append("The current time is %s" % timestamp.get_pretty())

    def add(key, val):
        contents.append("<tr><td><i>%s</i></td><td>%s</td></tr>" % (key, val))

    contents.append("<h2>Process</h2>")
    contents.append("<table>")
    add("command line", " ".join(sys.argv))

    start_ms = timestamp.process_start_time_ms()
    age_ms = timestamp.process_age_ms()
    add("started at", timestamp.get_pretty_ms(start_ms))
    add("running for", timestamp.get_human_readable_duration(age_ms / 1000.0))

    add("process pid", os.getpid())
    gc_counts = gc.get_count()
    add("live objects", "%d (%s)" % (sum(gc_counts),
                                     " / ".join(str(x) for x in gc_counts)))

    add("live threads", threading.activeCount())

    cpu_s, sys_cpu_s = os.times()[:2]
    cpu_percent = 100 * (1000 * cpu_s) / age_ms
    sys_cpu_percent = 100 * (1000 * sys_cpu_s) / age_ms
    add("cpu utilization", "%.2f%%" % cpu_percent)
    add("system cpu", "%.2f%%" % sys_cpu_percent)


    add("Python version", sys.version)

    contents.append("</table>")
    contents.append("<h2>Machine</h2>")
    contents.append("<table>")

    add("hostname", socket.gethostname())
    add("uname", " / ".join(os.uname()))
    add("load average", " / ".join(str(x) for x in os.getloadavg()))
    add("uptime", timestamp.get_human_readable_duration(os.times()[-1]))
        
    contents.append("</table>")
    contents.append("</body></html>")
    return "\n".join(contents)