Ejemplo n.º 1
0
def display1(schema_entries, times, stats, **opts):
    opt_delta = opts.get("delta", True)
    opt_out = opts.get("out")
    use_human = opts.get("human", True)
    if use_human:
        time_width = len(human.fhms(0))
        val_width = 10
    else:
        time_width = len(str(2 * 86400))
        val_width = 15

    def pr(time_str, val_strs):
        print >> opt_out, time_str.rjust(time_width), string.join(
            str.rjust(val_width) for str in val_strs)

    def fmt(ent, val):
        str = human.fsize(val)
        if ent.unit:
            str += ent.unit
        if opt_delta and ent.event:
            str += "/s"
        return str

    row = 0
    for time, vals in zip(times, stats):
        if use_human and row % 20 == 0:
            pr('TIME', [entry.key for entry in schema_entries])
        row += 1
        if use_human:
            pr(human.fhms(time), map(fmt, schema_entries,
                                     vals))  # HMS or time.
        else:
            pr(str(time), [str(val) for val in vals])
Ejemplo n.º 2
0
def display1(schema_entries, times, stats, **opts):
    opt_delta = opts.get("delta", True)
    opt_out = opts.get("out")
    use_human = opts.get("human", True)
    if use_human:
        time_width = len(human.fhms(0))
        val_width = 10
    else:
        time_width = len(str(2 * 86400))
        val_width = 15
    def pr(time_str, val_strs):
        print>>opt_out, time_str.rjust(time_width), string.join(str.rjust(val_width) for str in val_strs)
    def fmt(ent, val):
        str = human.fsize(val)
        if ent.unit:
            str += ent.unit
        if opt_delta and ent.event:
            str += "/s"
        return str
    row = 0
    for time, vals in zip(times, stats):
        if use_human and row % 20 == 0:
            pr('TIME', [entry.key for entry in schema_entries])
        row += 1
        if use_human:
            pr(human.fhms(time), map(fmt, schema_entries, vals)) # HMS or time.
        else:
            pr(str(time), [str(val) for val in vals])
Ejemplo n.º 3
0
 def comment(self, type_name, dev, key, val):
     str = self.comments.get((type_name, dev, key))
     if str:
         return " # " + str
     if val == None:
         return ""
     str = ""
     if type_name == "amd64_core":
         str = human.fsize(long(val), align=True, space=" ")
         if key == "DCSF":
             str += "B"
     elif type_name == "amd64_sock":
         str = human.fsize(long(val), align=True, space=" ") + "B"
     elif type_name == "cpu":
         if self.cpu_total == 0:
             pct = 0.0
         else:
             pct = 100.0 * float(val) / float(self.cpu_total)
         str = "%5.2f %%" % pct
     elif type_name == "mem":
         str = human.fsize(long(val), align=True, space=" ") + "B"
         if key == "MemUsed":
             pct = 100.0 * float(val) / float(self.dict[("mem", None, "MemTotal")])
             str += " (%5.2f %%)" % pct
     elif key and key.endswith("_bytes"):
         str = human.fsize(long(val), align=True, space=" ") + "B"
     elif key and key.endswith("_time"):
         str = human.fhms(long(val))
     if str != "":
         str = " # " + str
     return str
Ejemplo n.º 4
0
 def comment(self, type_name, dev, key, val):
     str = self.comments.get((type_name, dev, key))
     if str:
         return " # " + str
     if val == None:
         return ""
     str = ""
     if type_name == "amd64_core":
         str = human.fsize(long(val), align=True, space=" ")
         if key == "DCSF":
             str += "B"
     elif type_name == "amd64_sock":
         str = human.fsize(long(val), align=True, space=" ") + "B"
     elif type_name == "cpu":
         if self.cpu_total == 0:
             pct = 0.0
         else:
             pct = 100.0 * float(val) / float(self.cpu_total)
         str = "%5.2f %%" % pct
     elif type_name == "mem":
         str = human.fsize(long(val), align=True, space=" ") + "B"
         if key == "MemUsed":
             pct = 100.0 * float(val) / float(
                 self.dict[("mem", None, "MemTotal")])
             str += " (%5.2f %%)" % pct
     elif key and key.endswith("_bytes"):
         str = human.fsize(long(val), align=True, space=" ") + "B"
     elif key and key.endswith("_time"):
         str = human.fhms(long(val))
     if str != "":
         str = " # " + str
     return str