You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB

  1. #!/usr/bin/env python
  2. import sys
  3. try:
  4. data = open(sys.argv[1])
  5. except:
  6. print "Could not open '%s'" % (sys.argv[1][0])
  7. exit(0)
  8. ts_factor = 1.
  9. ts_prev = 0.
  10. threadlist = []
  11. for line in data:
  12. line = line.rstrip("\n")
  13. vals = line.split()
  14. [n, tid, ts, funcline] = vals[0:4]
  15. # 'note' is all text following funcline
  16. note = ''
  17. for v in vals[4:-1]:
  18. note += v+' '
  19. note += vals[-1]
  20. if ( note == 'calibrate done' ):
  21. ts_factor = float(ts) - ts_prev
  22. print "Factor = ", ts_factor, "("+str(ts_factor/1000000000)[0:4]+"GHz)"
  23. time = (float(ts)-ts_prev)/ts_factor
  24. # create a list of threads
  25. # - each thread has a list of <note,time> pairs, where time is the accumulated time for that note
  26. # - search threadlist for thread_id (tid)
  27. # - if found, search corresponding list of <note,time> pairs for the current note
  28. # - if found, update (+=) the time
  29. # - if not found, create a new <note,time> pair
  30. # - if not found, create a new thread,<note,time> entry
  31. found_thread = 0
  32. for thread in threadlist:
  33. if tid == thread[0]:
  34. found_thread = 1
  35. notetimelist = thread[1]
  36. found_note = 0
  37. for notetime in notetimelist:
  38. if note == notetime[0]:
  39. found_note = 1
  40. notetime[1] += time
  41. break
  42. if found_note == 0:
  43. thread[1].append([note, time])
  44. break
  45. if found_thread == 0:
  46. notetime = []
  47. notetime.append([note, time])
  48. threadlist.append([tid, notetime])
  49. ts_prev = float(ts)
  50. # trim out unneeded
  51. for thread in threadlist:
  52. trimlist = []
  53. for notetime in thread[1]:
  54. if notetime[0][0:9] == 'calibrate':
  55. trimlist.append(notetime)
  56. for notetime in trimlist:
  57. thread[1].remove(notetime)
  58. print ''
  59. # sum times to calculate percent (of 100)
  60. total_time = 0
  61. for thread in threadlist:
  62. for [note, time] in thread[1]:
  63. total_time += time
  64. print ' thread operation time(sec) percent'
  65. for thread in threadlist:
  66. print 'tid : %5s' % thread[0]
  67. for [note, time] in thread[1]:
  68. print ' %20s %f %5d' % (note, time, 100. * time/total_time)