sniper_stats.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import sys, os, sniper_lib
  2. _, EVENT_MARKER, EVENT_THREAD_NAME, EVENT_APP_START, EVENT_APP_EXIT, EVENT_THREAD_CREATE, EVENT_THREAD_EXIT = range(7)
  3. class SniperStatsBase:
  4. def parse_stats(self, (k1, k2), ncores, metrics = None):
  5. v1 = self.read_snapshot(k1, metrics = metrics)
  6. v2 = self.read_snapshot(k2, metrics = metrics)
  7. results = []
  8. for metricid in self.names.keys():
  9. name = '%s.%s' % self.names[metricid]
  10. if metrics and name not in metrics:
  11. continue
  12. id_min = min(min(v2.get(metricid, {}).keys() or [0]), 0)
  13. id_max = max(max(v2.get(metricid, {}).keys() or [0])+1, ncores)
  14. vals1 = v1.get(metricid, {})
  15. vals2 = v2.get(metricid, {})
  16. results += [ (name, idx, vals2.get(idx, 0) - vals1.get(idx, 0)) for idx in range(id_min, id_max) ]
  17. if name == 'performance_model.elapsed_time' and idx < ncores:
  18. results += [ ('performance_model.elapsed_time_begin', idx, vals1.get(idx, 0)) for idx in range(ncores) ]
  19. results += [ ('performance_model.elapsed_time_end', idx, vals2.get(idx, 0)) for idx in range(ncores) ]
  20. elif name == 'barrier.global_time':
  21. results += [ ('barrier.global_time_begin', idx, vals1.get(idx, 0)) for idx in range(ncores) ]
  22. results += [ ('barrier.global_time_end', idx, vals2.get(idx, 0)) for idx in range(ncores) ]
  23. return results
  24. def get_topology(self):
  25. raise ValueError("Topology information not available from statistics of this type")
  26. def get_events(self):
  27. raise ValueError("Event information not available from statistics of this type")
  28. def get_markers(self):
  29. markers = {}
  30. for event, time, core, thread, arg0, arg1, s in self.get_events():
  31. if event == EVENT_MARKER:
  32. markers.append((time, core, thread, arg0, arg1, s))
  33. return markers
  34. def get_thread_names(self):
  35. names = {}
  36. for event, time, core, thread, arg0, arg1, s in self.get_events():
  37. if event == EVENT_THREAD_NAME:
  38. names[thread] = s
  39. return names
  40. def get_results(self, **kwds):
  41. return sniper_lib.get_results(stats = self, **kwds)
  42. def SniperStats(resultsdir = '.', jobid = None):
  43. if jobid:
  44. import sniper_stats_jobid
  45. stats = sniper_stats_jobid.SniperStatsJobid(jobid)
  46. elif os.path.exists(os.path.join(resultsdir, 'sim.stats.sqlite3')):
  47. import sniper_stats_sqlite
  48. stats = sniper_stats_sqlite.SniperStatsSqlite(os.path.join(resultsdir, 'sim.stats.sqlite3'))
  49. elif os.path.exists(os.path.join(resultsdir, 'sim.stats.db')):
  50. import sniper_stats_db
  51. stats = sniper_stats_db.SniperStatsDb(os.path.join(resultsdir, 'sim.stats.db'))
  52. else:
  53. import sniper_stats_compat
  54. stats = sniper_stats_compat.SniperStatsCompat(resultsdir)
  55. stats.config = sniper_lib.get_config(jobid, resultsdir)
  56. return stats