rc-extract.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ## This script will extract the results of the line profiler
  2. ## for the CB Azure Client specifically, filters all long functions
  3. ## with given cutoffs, outputing a filtered results file containing
  4. ## only profiling of functions fitting the cut-offs, and a csv summary
  5. ## file containing information about the longest functions and associated
  6. ## lines
  7. from re import search
  8. from os import path, walk
  9. time_cutoff = 20 # seconds
  10. perc_cutoff = 75 # % of total functino time spent on this line
  11. results = 'results/'
  12. metaresults = 'metaresults/'
  13. print("Results directory used: {}".format(results))
  14. files = []
  15. for (dirpath, dirnames, filenames) in walk(results):
  16. for each_file in filenames:
  17. if ".res" in each_file:
  18. files.append(path.join(dirpath, each_file))
  19. print("Collected list: {}".format(files))
  20. summary = "{},{},{},{},{}\n".format("Test File", "CB functon", "Total Time (in s)", "Azure Operation", "Time per hit")
  21. filtered = ""
  22. inside = False
  23. capturing = False
  24. purge_line = True
  25. for each_file in files:
  26. print("Processing: {}\n".format(each_file))
  27. with open(each_file, 'r') as current:
  28. for line in current:
  29. match = search(r'^Total time: ([\.e\-0-9]+) s', line)
  30. if match:
  31. inside = False
  32. capturing = False
  33. total_time = float(match.group(1))
  34. if total_time > time_cutoff:
  35. inside = True
  36. filtered += "Test suite: {}\n".format(each_file)
  37. filtered += line
  38. elif inside:
  39. match = search(r'^Function: (.+) at line ([0-9]+)', line)
  40. if match:
  41. func_name = match.group(1)
  42. line_num = int(match.group(2))
  43. capturing = True
  44. filtered += line
  45. elif capturing:
  46. if purge_line:
  47. complete_contents = ""
  48. paran_num = 0
  49. filtered += line
  50. match = search(r'^\s+([0-9]+)\s+[0-9]+\s+([\.0-9]+)\s+([\.0-9]+)\s+([\.0-9]+)\s+([^\n]+)', line)
  51. if match:
  52. percentage = float(match.group(4))
  53. line_contents = match.group(5)
  54. complete_contents += line_contents.replace(" \\", "")
  55. paran_num += line_contents.count("(") - line_contents.count(")")
  56. purge_line = " \\" not in line_contents and paran_num == 0
  57. if percentage > perc_cutoff:
  58. line_num = int(match.group(1))
  59. line_time = float(match.group(2))/1000000
  60. hit_time = float(match.group(3))/1000000
  61. summary += "{},\"{}\",{},\"{}\",{}\n".format(each_file.split('/')[-1].replace(".res", ""), func_name, total_time, complete_contents, hit_time)
  62. else:
  63. match = search(r'^\s+([0-9]+)\s+([^\n]+)', line)
  64. if match:
  65. line_contents = match.group(2)
  66. complete_contents += line_contents.replace(" \\", "")
  67. paran_num += line_contents.count("(") - line_contents.count(")")
  68. purge_line = " \\" not in line_contents and paran_num == 0
  69. with open(metaresults+"summary.csv", 'w+') as sum_file:
  70. sum_file.write(summary)
  71. with open(metaresults+"filtered.txt", 'w+') as fil_file:
  72. fil_file.write(filtered)