process-profile-data.nut 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. local profile_data = [==[
  2. 1 1 7 232.000000 _OP_LOAD
  3. 2 2 1193711 2332681.000000 _OP_LOADINT
  4. 6 6 796719 1642654.000000 _OP_CALL
  5. 8 8 265587 546637.000000 _OP_PREPCALLK
  6. 9 9 6 9.000000 _OP_GETK
  7. 10 10 659839 1282802.000000 _OP_MOVE
  8. 14 14 528410 1022085.000000 _OP_GET
  9. 17 17 265574 554243.000000 _OP_ADD
  10. 18 18 262849 501726.000000 _OP_SUB
  11. 19 19 4 7.000000 _OP_MUL
  12. 23 23 531133 1016261.000000 _OP_RETURN
  13. 26 26 265566 521499.000000 _OP_LOADBOOL
  14. 27 27 134148 280230.000000 _OP_DMOVE
  15. 28 28 1364 2154.000000 _OP_JMP
  16. 29 29 266936 539864.000000 _OP_JCMP
  17. 30 30 265566 671098.000000 _OP_JZ
  18. 32 32 525688 1059911.000000 _OP_GETOUTER
  19. 33 33 265566 516803.000000 _OP_NEWOBJ
  20. 34 34 528410 1138235.000000 _OP_APPENDARRAY
  21. 37 37 132782 247946.000000 _OP_INCL
  22. 48 48 2 25120.000000 _OP_CLOSURE
  23. ]==]
  24. local profile = [];
  25. local total_time = 0.0;
  26. foreach(line in profile_data.split('\n')){
  27. //print(line);
  28. local rec = line.split('\t');
  29. rec[2] = rec[2].tointeger();
  30. rec[3] = rec[3].tofloat();
  31. total_time += rec[3];
  32. profile.push(rec);
  33. }
  34. foreach(rec in profile){
  35. local pct = (rec[3] / total_time) * 100;
  36. rec[1] = math.roundf(pct, 2);
  37. rec.insert(3, math.roundf((rec[3]/rec[2]) * 0.001, 5));
  38. }
  39. profile.sort(@(a,b) b[1] <=> a[1]);
  40. print("OP\t%time\t%ncalls\ttm_1call\ttm_allcalls\tOP name");
  41. foreach(rec in profile){
  42. print(rec.concat("\t"));
  43. }