profiling.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2017. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. *
  31. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. #include <pal_typedefs.h>
  36. #include <pal_log.h>
  37. #include <profiling.h>
  38. #define PROFILING_DEFAULT_EN (0)
  39. #define MOD "PROFILING"
  40. #if PROFILING_DEFAULT_EN
  41. static uint32_t g_profiling_enable = 1;
  42. #else
  43. static uint32_t g_profiling_enable = 0;
  44. #endif
  45. void set_profiling_enable(uint32_t enable)
  46. {
  47. g_profiling_enable = enable;
  48. return;
  49. }
  50. void profiling_reset(struct profile_info *ctx)
  51. {
  52. uint32_t i;
  53. ctx->start_time = 0;
  54. ctx->running = 0;
  55. ctx->cur_time_slot_idx = 0;
  56. for (i = 0; i < NUM_TIME_SLOT; i++) {
  57. ctx->time[i].name = NULL;
  58. ctx->time[i].time = 0;
  59. }
  60. return;
  61. }
  62. void profiling_start(struct profile_info *ctx, char *prompt_str, char *time_slot_name)
  63. {
  64. if (0 == g_profiling_enable)
  65. return;
  66. if (NULL == prompt_str)
  67. prompt_str = "NULL";
  68. pal_log_debug("[%s] %s start\n", MOD, prompt_str);
  69. if (NULL != time_slot_name && (ctx->cur_time_slot_idx < NUM_TIME_SLOT))
  70. ctx->time[ctx->cur_time_slot_idx].name = time_slot_name;
  71. ctx->running = 1;
  72. ctx->start_time = pal_get_timer(0);
  73. return;
  74. }
  75. void profiling_stop(struct profile_info *ctx, char *prompt_str, uint32_t advance_time_slot)
  76. {
  77. if (0 == g_profiling_enable) {
  78. return;
  79. }
  80. if (0 == ctx->running)
  81. return;
  82. /* behavior similar to we stop then start timer immediately, but we don't stop timer actually */
  83. if (ctx->cur_time_slot_idx < NUM_TIME_SLOT) {
  84. ctx->time[ctx->cur_time_slot_idx].time += pal_get_timer(ctx->start_time);
  85. if (advance_time_slot)
  86. ctx->cur_time_slot_idx++;
  87. } else
  88. pal_log_err("profiling time slot depleted\n");
  89. if (NULL == prompt_str)
  90. prompt_str = "NULL";
  91. pal_log_debug("[%s] %s stop\n", MOD, prompt_str);
  92. ctx->running = 0;
  93. return;
  94. }
  95. void profiling_end(struct profile_info *ctx, char *prompt_str)
  96. {
  97. uint32_t i = 0;
  98. uint32_t total_time = 0;
  99. if (0 == g_profiling_enable)
  100. return;
  101. profiling_stop(ctx, prompt_str, 0);
  102. if (NULL == prompt_str)
  103. prompt_str = "NULL";
  104. pal_log_debug("[%s] %s end\n", MOD, prompt_str);
  105. for (i = 0; i < NUM_TIME_SLOT; i++) {
  106. char *time_slot_name = NULL;
  107. if (0 == ctx->time[i].time)
  108. break;
  109. time_slot_name = ctx->time[i].name != NULL ? ctx->time[i].name : "NULL";
  110. pal_log_info("[%s][%s][%s][0x%x] time = %dms\n", MOD, prompt_str, time_slot_name, i, ctx->time[i].time);
  111. total_time += ctx->time[i].time;
  112. }
  113. pal_log_info("[%s][%s] total time = %dms\n", MOD, prompt_str, total_time);
  114. return;
  115. }