ipcthreadtrace.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. ipctrace.py
  3. Write a trace of instantaneous IPC values for all cores.
  4. First argument is either a filename, or none to write to standard output.
  5. Second argument is the interval size in nanoseconds (default is 10000)
  6. """
  7. import sys, os, sim
  8. class IpcTrace:
  9. def setup(self, args):
  10. self.freq = sim.dvfs.get_frequency(0) # This script does not support DVFS
  11. args = dict(enumerate((args or '').split(':')))
  12. filename = args.get(0, None)
  13. interval_ns = long(args.get(1, 10000))
  14. if filename:
  15. self.fd = file(os.path.join(sim.config.output_dir, filename), 'w')
  16. self.isTerminal = False
  17. else:
  18. self.fd = sys.stdout
  19. self.isTerminal = True
  20. self.sd = sim.util.StatsDelta()
  21. self.stats = {
  22. 'threadinstrs': [],
  23. 'threadtime': [],
  24. }
  25. sim.util.Every(interval_ns * sim.util.Time.NS, self.periodic, statsdelta = self.sd, roi_only = True)
  26. def hook_thread_start(self, threadid, creator):
  27. for thread in range(len(self.stats['threadinstrs']), threadid+1):
  28. self.stats['threadinstrs'].append(self.sd.getter('thread', thread, 'instruction_count'))
  29. self.stats['threadtime'].append(self.sd.getter('thread', thread, 'elapsed_time'))
  30. def periodic(self, time, time_delta):
  31. if self.isTerminal:
  32. self.fd.write('[THREADIPC] ')
  33. self.fd.write('%u' % (time / 1e6)) # Time in ns
  34. for thread in range(sim.thread.get_nthreads()):
  35. # Print per-thread stats
  36. try:
  37. cycles = self.stats['threadtime'][thread].delta * self.freq / 1e9 # convert fs to cycles
  38. instrs = self.stats['threadinstrs'][thread].delta
  39. ipc = instrs / (cycles or 1)
  40. self.fd.write(' %.3f' % ipc)
  41. except TypeError:
  42. pass # Skip newly created threads
  43. self.fd.write('\n')
  44. sim.util.register(IpcTrace())