profiling.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef __PROFILING_H__
  36. #define __PROFILING_H__
  37. #include <pal_typedefs.h>
  38. #include <pal_timer.h>
  39. #define NUM_TIME_SLOT (10)
  40. struct profile_slot_info {
  41. char *name;
  42. uint32_t time;
  43. };
  44. /* definitions */
  45. struct profile_info {
  46. /* updated each time profiling_start is called */
  47. uint32_t start_time;
  48. uint32_t running;
  49. /* used to record current time slot used */
  50. uint32_t cur_time_slot_idx;
  51. /* used to break down time elapsed of multiple sections */
  52. struct profile_slot_info time[NUM_TIME_SLOT];
  53. };
  54. /* functions */
  55. /* enable/disable profiling */
  56. void set_profiling_enable(uint32_t enable);
  57. /* reset profile info structure */
  58. void profiling_reset(struct profile_info *ctx);
  59. /* start profiling */
  60. void profiling_start(struct profile_info *ctx, char *prompt_str,
  61. char *time_slot_name);
  62. /* record time elapsed in current section and move to next section */
  63. void profiling_stop(struct profile_info *ctx, char *prompt_str,
  64. uint32_t advance_time_slot);
  65. /* end profilng */
  66. void profiling_end(struct profile_info *ctx, char *prompt_str);
  67. extern unsigned int g_profile_level;
  68. #define PROFILING_PRINTF(FMT, ...) dprintf(CRITICAL, "[PROFILE] ::: lvl(%d) " FMT "\n", \
  69. g_profile_level, ##__VA_ARGS__)
  70. #define PROFILING_START(MSG) { char *msg = MSG; \
  71. unsigned int __profile_start = get_timer(0); \
  72. g_profile_level++;
  73. #define PROFILING_END() PROFILING_PRINTF("%s takes %d ms", \
  74. msg, \
  75. (int)get_timer(__profile_start)); \
  76. g_profile_level--; \
  77. }
  78. #endif /* __PROFILING_H__ */