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

profile.c 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #include "common.h"
  39. #include <signal.h>
  40. #include <strings.h>
  41. #define USE_FUNCTABLE
  42. #include "../../interface/functable.h"
  43. func_profile_t function_profile_table[MAX_PROF_TABLE];
  44. int gotoblas_profile = 1;
  45. static struct sigaction sa, ig;
  46. void gotoblas_profile_quit(void) {
  47. int i;
  48. unsigned long long calls, fops, cycles, tcycles, area;
  49. sigaction(SIGPROF, &ig, NULL);
  50. calls = 0;
  51. fops = 0;
  52. cycles = 0;
  53. tcycles = 0;
  54. area = 0;
  55. for (i = 0; i < MAX_PROF_TABLE; i ++) {
  56. if (function_profile_table[i].calls) {
  57. calls += function_profile_table[i].calls;
  58. cycles += function_profile_table[i].cycles;
  59. tcycles += function_profile_table[i].tcycles;
  60. area += function_profile_table[i].area;
  61. fops += function_profile_table[i].fops;
  62. }
  63. }
  64. if (cycles > 0) {
  65. fprintf(stderr, "\n\t====== BLAS Profiling Result =======\n\n");
  66. fprintf(stderr, " Function No. of Calls Time Consumption Efficiency Bytes/cycle Wall Time(Cycles)\n");
  67. for (i = 0; i < MAX_PROF_TABLE; i ++) {
  68. if (function_profile_table[i].calls) {
  69. #ifndef OS_WINDOWS
  70. fprintf(stderr, "%-12s : %10Ld %8.2f%% %10.3f%% %8.2f %Ld\n",
  71. #else
  72. fprintf(stderr, "%-12s : %10lld %8.2f%% %10.3f%% %8.2f %lld\n",
  73. #endif
  74. func_table[i],
  75. function_profile_table[i].calls,
  76. (double)function_profile_table[i].cycles / (double)cycles * 100.,
  77. (double)function_profile_table[i].fops / (double)function_profile_table[i].tcycles * 100.,
  78. (double)function_profile_table[i].area / (double)function_profile_table[i].cycles,
  79. function_profile_table[i].cycles
  80. );
  81. }
  82. }
  83. fprintf(stderr, " --------------------------------------------------------------------\n");
  84. #ifndef OS_WINDOWS
  85. fprintf(stderr, "%-12s : %10Ld %10.3f%% %8.2f\n",
  86. #else
  87. fprintf(stderr, "%-12s : %10lld %10.3f%% %8.2f\n",
  88. #endif
  89. "Total",
  90. calls,
  91. (double)fops / (double)tcycles * 100.,
  92. (double)area / (double)cycles);
  93. }
  94. sigaction(SIGPROF, &sa, NULL);
  95. }
  96. void gotoblas_profile_clear(void) {
  97. int i;
  98. for (i = 0; i < MAX_PROF_TABLE; i ++) {
  99. function_profile_table[i].calls = 0;
  100. function_profile_table[i].cycles = 0;
  101. function_profile_table[i].tcycles = 0;
  102. function_profile_table[i].area = 0;
  103. function_profile_table[i].fops = 0;
  104. }
  105. }
  106. void gotoblas_profile_init(void) {
  107. gotoblas_profile_clear();
  108. bzero(&sa, sizeof(struct sigaction));
  109. sa.sa_handler = (void *)gotoblas_profile_quit;
  110. sa.sa_flags = SA_NODEFER | SA_RESETHAND;
  111. bzero(&ig, sizeof(struct sigaction));
  112. ig.sa_handler = SIG_IGN;
  113. ig.sa_flags |= SA_NODEFER | SA_RESETHAND;
  114. sigaction(SIGPROF, &sa, NULL);
  115. }