profile.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2009 Openmoko Inc.
  3. *
  4. * Authors Marek Lindner
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA
  19. *
  20. */
  21. #include <profile.h>
  22. #include <tick.h>
  23. #include <string.h>
  24. #include <msg.h>
  25. #include <delay.h>
  26. #include <regs.h>
  27. #include <samo.h>
  28. #if PROFILER_ON
  29. struct prof_container prof_container[PROF_COUNT];
  30. static const char *prof_to_string[] = { PROF_TO_STRING };
  31. void profile_init(void)
  32. {
  33. memset(&prof_container, 0, sizeof(prof_container));
  34. }
  35. void prof_start(unsigned long index)
  36. {
  37. prof_container[index].start_time = Tick_get();
  38. }
  39. void prof_stop(unsigned long index)
  40. {
  41. unsigned long tmp_tick = Tick_get();
  42. prof_container[index].calls++;
  43. prof_container[index].total_time += tmp_tick - prof_container[index].start_time;
  44. }
  45. void prof_print(void)
  46. {
  47. unsigned long index, count = 0;
  48. msg(MSG_INFO, "\nProfile data:\n");
  49. for (index = 0; index < PROF_COUNT; index++) {
  50. if (prof_container[index].calls == 0)
  51. continue;
  52. count++;
  53. msg(MSG_INFO, " %s: total cpu time = %u, calls: %u, avg time per call = %u\n",
  54. prof_to_string[index],
  55. prof_container[index].total_time / MCLK_MHz, prof_container[index].calls,
  56. ((prof_container[index].total_time / MCLK_MHz) / prof_container[index].calls));
  57. }
  58. if (count == 0)
  59. msg(MSG_INFO, " no profile data available\n");
  60. }
  61. void prof_demo(void)
  62. {
  63. volatile unsigned int x = 2323;
  64. prof_start(PROF_add);
  65. x = 50000 + x;
  66. prof_stop(PROF_add);
  67. prof_start(PROF_subt);
  68. x = 50000 - x;
  69. prof_stop(PROF_subt);
  70. prof_start(PROF_mult);
  71. x = 50000 * x;
  72. prof_stop(PROF_mult);
  73. prof_start(PROF_div);
  74. x = 50000 / x;
  75. prof_stop(PROF_div);
  76. prof_start(PROF_mod);
  77. x = 50000 % x;
  78. prof_stop(PROF_mod);
  79. prof_start(PROF_delay);
  80. delay_us(1000);
  81. prof_stop(PROF_delay);
  82. }
  83. #else
  84. void profile_init(void)
  85. {
  86. }
  87. void prof_start(unsigned long index)
  88. {
  89. }
  90. void prof_stop(unsigned long index)
  91. {
  92. }
  93. void prof_print(void)
  94. {
  95. }
  96. void prof_demo(void)
  97. {
  98. }
  99. #endif