diff --git a/monitoring/db/scripts/get_detailed_power.py b/monitoring/db/scripts/get_detailed_power.py index 0915f69..ce80934 100755 --- a/monitoring/db/scripts/get_detailed_power.py +++ b/monitoring/db/scripts/get_detailed_power.py @@ -89,6 +89,12 @@ class Power: power = cls.from_list(all_list) + power.df = db.db_to_pf(jobid, interval, hawk_ai) + # power.df.to_pickle("pickle_df") + power.by_node = power.df.groupby('name') + power.by_epoch = power.df.groupby('time') + power.energy = power.summarize_energy() + return power def to_file(self, jobid, header=""): @@ -99,6 +105,7 @@ class Power: return None header += self.warnings + header += self.energy try: with open(fname, "w+") as f: f.write(header + self.header()) @@ -147,7 +154,23 @@ class Power: return self.summarize_time(ts) \ + self.summarize_values(values) \ + tuple(values) + + def energy_total(self): + energy = None + if hasattr(self, "by_node"): + energy = self.by_node.apply(self.energy_node).sum() + return energy + @staticmethod + def energy_node(group): + """Left-sided Riemann sum is enough, as time is lower bound of bucket""" + delta_t = group["time"].diff().shift(-1)/1000. # in seconds + pow = group["avg"] + return (delta_t * pow).iloc[:-1].sum() + + def summarize_energy(self): + return "# Total energy consumed by job: {energy:.0f} J\n".format(energy=self.energy_total()) + @staticmethod def pretty_print(args): return ",".join(str(a) for a in args) + '\n' @@ -252,7 +275,8 @@ class App: print('Created file {fn}'.format(fn=fn)) if power.warnings: print(power.warnings) - + if power.energy: + print(power.energy) if __name__ == "__main__": import sys