StopWatch.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright (C) 2014 by Xiao Shaun Wang <wangxiao@cs.umd.edu>
  2. package com.oblivm.backend.util;
  3. public class StopWatch {
  4. public long ands = 0;
  5. double startTimeOT = 0;
  6. double stopTimeOT = 0;
  7. public double elapsedTimeOT = 0;
  8. double startTimeGC = 0;
  9. double stopTimeGC = 0;
  10. public double elapsedTimeGC = 0;
  11. double startTimeTotal = 0;
  12. double stopTimeTotal = 0;
  13. public double elapsedTimeTotal = 0;
  14. double startTimeOTIO = 0;
  15. double stopTimeOTIO = 0;
  16. public double elapsedTimeOTIO = 0;
  17. double startTimeGCIO = 0;
  18. double stopTimeGCIO = 0;
  19. public double elapsedTimeGCIO = 0;
  20. boolean countTime;
  21. long counter = 1;
  22. public StopWatch(boolean countTime) {
  23. this.countTime = countTime;
  24. }
  25. public void startOT() {
  26. if (countTime)
  27. startTimeOT = System.nanoTime();
  28. }
  29. public void stopOT() {
  30. if (countTime) {
  31. stopTimeOT = System.nanoTime();
  32. elapsedTimeOT += stopTimeOT - startTimeOT;
  33. }
  34. }
  35. public void startOTIO() {
  36. if (countTime)
  37. startTimeOTIO = System.nanoTime();
  38. }
  39. public void stopOTIO() {
  40. if (countTime) {
  41. stopTimeOTIO = System.nanoTime();
  42. elapsedTimeOTIO += stopTimeOTIO - startTimeOTIO;
  43. }
  44. }
  45. public void startGC() {
  46. if (countTime)
  47. startTimeGC = System.nanoTime();
  48. }
  49. public void stopGC() {
  50. if (countTime) {
  51. stopTimeGC = System.nanoTime();
  52. elapsedTimeGC += stopTimeGC - startTimeGC;
  53. }
  54. }
  55. public void startGCIO() {
  56. if (countTime)
  57. startTimeGCIO = System.nanoTime();
  58. }
  59. public void stopGCIO() {
  60. if (countTime) {
  61. stopTimeGCIO = System.nanoTime();
  62. elapsedTimeGCIO += stopTimeGCIO - startTimeGCIO;
  63. }
  64. }
  65. public void startTotal() {
  66. startTimeTotal = System.nanoTime();
  67. }
  68. public double stopTotal() {
  69. stopTimeTotal = System.nanoTime();
  70. elapsedTimeTotal += stopTimeTotal - startTimeTotal;
  71. return stopTimeTotal - startTimeTotal;
  72. }
  73. public void addCounter() {
  74. ++counter;
  75. }
  76. public void flush() {
  77. ands = 0;
  78. startTimeOT = 0;
  79. stopTimeOT = 0;
  80. elapsedTimeOT = 0;
  81. startTimeGC = 0;
  82. stopTimeGC = 0;
  83. elapsedTimeGC = 0;
  84. startTimeTotal = 0;
  85. stopTimeTotal = 0;
  86. elapsedTimeTotal = 0;
  87. startTimeOTIO = 0;
  88. stopTimeOTIO = 0;
  89. elapsedTimeOTIO = 0;
  90. startTimeGCIO = 0;
  91. stopTimeGCIO = 0;
  92. elapsedTimeGCIO = 0;
  93. counter = 1;
  94. }
  95. public void print() {
  96. System.out.println("Total Time \t GC CPU Time\t GCIO Time\t OTCPU Time\t OTIO Time\n");
  97. System.out.println(elapsedTimeTotal / 1000000000.0 / counter + "\t"
  98. + (elapsedTimeGC - elapsedTimeGCIO) / 1000000000.0 / counter + "\t"
  99. + elapsedTimeGCIO / 1000000000.0 / counter + " "
  100. + (elapsedTimeOT - elapsedTimeOTIO) / 1000000000.0 / counter + "\t"
  101. + elapsedTimeOTIO / 1000000000.0 / counter + "\n");
  102. System.out.println("Number of Gate:" + ands);
  103. }
  104. public void print(int i) {
  105. System.out.println("timer:\t" + i + " \t" + elapsedTimeTotal / 1000000000.0 / counter + "\t"
  106. + (elapsedTimeGC - elapsedTimeGCIO) / 1000000000.0 / counter + "\t"
  107. + elapsedTimeGCIO / 1000000000.0 / counter + " "
  108. + (elapsedTimeOT - elapsedTimeOTIO) / 1000000000.0 / counter + "\t"
  109. + elapsedTimeOTIO / 1000000000.0 / counter + "\n");
  110. }
  111. }