ProfilingEngine.c
资源名称:mmi.rar [点击查看]
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:24k
源码类别:
MTK
开发平台:
C/C++
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * Profiling.c
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- * MMI performance profiling utilities and framework
- *
- * Author:
- * -------
- * -------
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- /* Include: MMI header file */
- #include "MMI_features.h"
- #include "stdC.h"
- #include "L4Dr1.h"
- #include "PixtelDataTypes.h"
- #include "gui_data_types.h"
- #include "gui.h"
- #include "gui_themes.h"
- #include "UCS2prot.h"
- #include "ProfilingEngine.h"
- #include "DebugInitDef.h"
- #ifndef __MTK_TARGET__
- /* MoDIS or PC Simulator */
- #include <sys/timeb.h>
- #include <time.h>
- #elif defined(KAL_ON_NUCLEUS)
- #include "kal_nucleus.h"
- #endif /* __MTK_TARGET__ */
- #include "gdi_include.h"
- /* Include: PS header file */
- #ifdef __MMI_INTERACTIVE_PROFILNG__
- /*
- * Define
- */
- /* Screen outout buffer size */
- #define MMI_FRM_PROFILING_OUTBUF_SIZE 64
- /* Number of interactive profing set */
- #define MMI_FRM_PROFILING_NUM_ISET 3
- /*
- * Typedef
- */
- #ifdef MMI_ON_WIN32
- typedef clock_t profiling_tick_t;
- #else
- typedef kal_uint32 profiling_tick_t;
- #endif
- typedef struct
- {
- /* Start tick of interactive mode */
- profiling_tick_t interactive_start[MMI_FRM_PROFILING_NUM_ISET];
- /* End tick of interactive mode */
- profiling_tick_t interactive_end[MMI_FRM_PROFILING_NUM_ISET];
- } mmi_frm_profiling_struct;
- /*
- * Local Variable
- */
- /* Context of profiling */
- static mmi_frm_profiling_struct g_mmi_frm_profiling_data;
- /* Enable interactive profiling */
- static MMI_BOOL g_mmi_frm_profiling_interactive_enabled = MMI_FALSE;
- static MMI_BOOL g_mmi_frm_profiling_gdi_profile_enabled = MMI_FALSE;
- static const color g_mmi_frm_profiling_bgcolor = {0, 0, 0, 100};
- static const color g_mmi_frm_profiling_fgcolor = {255, 255, 255, 100};
- /* Delay emulation */
- static profiling_tick_t g_mmi_frm_profiling_delay_start_time[MMI_FRM_PROFILING_DELAY_MAX_TYPE];
- static profiling_tick_t g_mmi_frm_profiling_delay_tick[MMI_FRM_PROFILING_DELAY_MAX_TYPE];
- /*
- * Local Function
- */
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_get_time
- * DESCRIPTION
- * Portable way for
- * PARAMETERS
- * void
- * RETURNS
- * It returns time in millisecond for PC Simulator and ticks for target/MoDIS
- *****************************************************************************/
- static profiling_tick_t mmi_frm_profiling_get_time(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- profiling_tick_t t;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef MMI_ON_WIN32
- t = clock();
- return t * 1000 / CLOCKS_PER_SEC;
- #else /* MMI_ON_WIN32 */
- kal_get_time(&t);
- return t;
- #endif /* MMI_ON_WIN32 */
- }
- /*
- * Global Variable
- */
- /*
- * Global Function
- */
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_is_enabled
- * DESCRIPTION
- * Is interactive profiling enabled
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- MMI_BOOL mmi_frm_profiling_interactive_is_enabled(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return g_mmi_frm_profiling_interactive_enabled;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_enable
- * DESCRIPTION
- * Enable/disable interactive profiling
- * PARAMETERS
- * enable [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_interactive_enable(MMI_BOOL enable)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_mmi_frm_profiling_interactive_enabled = enable;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_gdi_profile_is_enabled
- * DESCRIPTION
- * Is interactive profiling enabled
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- MMI_BOOL mmi_frm_profiling_gdi_profile_is_enabled(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return g_mmi_frm_profiling_gdi_profile_enabled;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_gdi_profile_enable
- * DESCRIPTION
- * Enable/disable interactive profiling
- * PARAMETERS
- * enable [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_gdi_profile_enable(MMI_BOOL enable)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- g_mmi_frm_profiling_gdi_profile_enabled = enable;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_start
- * DESCRIPTION
- * Start of interactive profiling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_interactive_start(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_mmi_frm_profiling_interactive_enabled)
- {
- g_mmi_frm_profiling_data.interactive_start[0] = mmi_frm_profiling_get_time();
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_start2
- * DESCRIPTION
- * Start of interactive profiling of 2nd test set
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_interactive_start2(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_mmi_frm_profiling_interactive_enabled)
- {
- g_mmi_frm_profiling_data.interactive_start[1] = mmi_frm_profiling_get_time();
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_start3
- * DESCRIPTION
- * Start of interactive profiling of 3rd test set
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_interactive_start3(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_mmi_frm_profiling_interactive_enabled)
- {
- g_mmi_frm_profiling_data.interactive_start[2] = mmi_frm_profiling_get_time();
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_end
- * DESCRIPTION
- * End of interactive profiling
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_interactive_end(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_mmi_frm_profiling_interactive_enabled)
- {
- g_mmi_frm_profiling_data.interactive_end[0] = mmi_frm_profiling_get_time();
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_end2
- * DESCRIPTION
- * End of interactive profiling of 2nd test set
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_interactive_end2(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_mmi_frm_profiling_interactive_enabled)
- {
- g_mmi_frm_profiling_data.interactive_end[1] = mmi_frm_profiling_get_time();
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_end3
- * DESCRIPTION
- * End of interactive profiling of 3rd test set
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_interactive_end3(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (g_mmi_frm_profiling_interactive_enabled)
- {
- g_mmi_frm_profiling_data.interactive_end[2] = mmi_frm_profiling_get_time();
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_interactive_show
- * DESCRIPTION
- * Display profiling information on screen (typically on softkey bar)
- * PARAMETERS
- * prompt [IN] Prompt string to be displayed
- * flags [IN] Which to show (MMI_FRM_PROFILING_MASK_#)
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_interactive_show(U8 *prompt, U32 flags)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 i;
- profiling_tick_t ms; /* millisecond */
- S32 prompt_len;
- U8 ascii_str[MMI_FRM_PROFILING_OUTBUF_SIZE + 1];
- U8 unicode_str[(MMI_FRM_PROFILING_OUTBUF_SIZE + 1) * 2];
- S32 sw, sh; /* string width, height */
- S32 x1, y1, x2, y2;
- S32 bottom_y;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (!g_mmi_frm_profiling_interactive_enabled)
- {
- return;
- }
- gui_lock_double_buffer();
- bottom_y = UI_device_height - 1;
- for (i = 0; i < MMI_FRM_PROFILING_NUM_ISET; i++)
- {
- if (!(flags & (MMI_FRM_PROFILING_MASK_1 << i)))
- {
- continue;
- }
- ms = g_mmi_frm_profiling_data.interactive_end[i] - g_mmi_frm_profiling_data.interactive_start[i];
- #ifndef MMI_ON_WIN32
- ms = ms * 1000 / KAL_TICKS_1_SEC;
- #endif
- sprintf((char*)ascii_str, "%d.%03d", (int)(ms / 1000), (int)(ms % 1000));
- UCS2Strncpy((S8*) unicode_str, (S8*) prompt, MMI_FRM_PROFILING_OUTBUF_SIZE);
- prompt_len = UCS2Strlen((S8*) unicode_str);
- AnsiiNToUnicodeString(
- (S8*) unicode_str + (prompt_len * 2),
- (S8*) ascii_str,
- MMI_FRM_PROFILING_OUTBUF_SIZE - prompt_len);
- gui_set_font(&MMI_small_font);
- gui_measure_string((UI_string_type) unicode_str, &sw, &sh);
- x1 = (UI_device_width - sw) >> 1;
- x2 = x1 + sw - 1;
- y2 = bottom_y;
- y1 = y2 - sh + 1;
- bottom_y -= sh + 1;
- gui_push_clip();
- gui_set_clip(x1, y1, x2, y2);
- gui_fill_rectangle(x1, y1, x2, y2, g_mmi_frm_profiling_bgcolor);
- gui_set_text_color(g_mmi_frm_profiling_fgcolor);
- gui_move_text_cursor(x1, y1);
- gui_print_text((UI_string_type) unicode_str);
- gui_pop_clip();
- gui_BLT_double_buffer(x1, y1, x2, y2);
- }
- gui_unlock_double_buffer();
- gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
- }
- /*****************************************************************************
- * Delay emulation
- *
- * This is used internally in MTK to experiment human perception of UI delay
- *****************************************************************************/
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_delay_set
- * DESCRIPTION
- * Configure delay emulation
- *
- * Set 'ms' to 0 to disable the UI delay effects
- * PARAMETERS
- * type [IN] Type of delay event
- * ms [IN] Delay in milliseconds
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_frm_profiling_delay_set(mmi_frm_profiling_delay_enum type, U32 ms)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_ASSERT(type < MMI_FRM_PROFILING_DELAY_MAX_TYPE);
- #ifdef MMI_ON_WIN32
- g_mmi_frm_profiling_delay_tick[type] = (profiling_tick_t) ms;
- #else
- g_mmi_frm_profiling_delay_tick[type] = (profiling_tick_t) kal_milli_secs_to_ticks(ms);
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_delay_get
- * DESCRIPTION
- * Get the configured delay emulation
- * PARAMETERS
- * type [IN] Type of delay event
- * RETURNS
- *
- *****************************************************************************/
- U32 mmi_frm_profiling_delay_get(mmi_frm_profiling_delay_enum type)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_ASSERT(type < MMI_FRM_PROFILING_DELAY_MAX_TYPE);
- #ifdef MMI_ON_WIN32
- return g_mmi_frm_profiling_delay_tick[type];
- #else
- return kal_ticks_to_milli_secs(g_mmi_frm_profiling_delay_tick[type]);
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_delay_start_timer
- * DESCRIPTION
- * Configure the current time to emulate UI delay effect
- * PARAMETERS
- * type [IN] Type of event
- * RETURNS
- * Expected delay time in ticks
- *****************************************************************************/
- void mmi_frm_profiling_delay_start_timer(mmi_frm_profiling_delay_enum type)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_ASSERT(type < MMI_FRM_PROFILING_DELAY_MAX_TYPE);
- if (!g_mmi_frm_profiling_delay_tick[type])
- {
- return;
- }
- if ((g_mmi_frm_profiling_delay_start_time[type] = mmi_frm_profiling_get_time()) == 0)
- {
- /* Keep non-zero value before mmi_frm_profiling_delay_perform() is invoked */
- g_mmi_frm_profiling_delay_start_time[type] = 1;
- }
- gdi_lcd_freeze(TRUE);
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_frm_profiling_delay_perform
- * DESCRIPTION
- * Start to emulate UI delay effect.
- *
- * Note: mmi_frm_profiling_start_delay_timer() should be used first.
- * PARAMETERS
- * type [IN] Type of event
- * RETURNS
- * Expected delay time in ticks
- *****************************************************************************/
- void mmi_frm_profiling_delay_perform(mmi_frm_profiling_delay_enum type)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- profiling_tick_t curr_tick, start_tick, delay_tick, offset_tick;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- MMI_ASSERT(type < MMI_FRM_PROFILING_DELAY_MAX_TYPE);
- offset_tick = g_mmi_frm_profiling_delay_tick[MMI_FRM_PROFILING_DELAY_OFFSET];
- delay_tick = g_mmi_frm_profiling_delay_tick[type];
- start_tick = g_mmi_frm_profiling_delay_start_time[type];
- if (!delay_tick || !start_tick)
- {
- return;
- }
- if (offset_tick > delay_tick)
- {
- delay_tick = 0;
- }
- else
- {
- delay_tick -= offset_tick;
- }
- curr_tick = mmi_frm_profiling_get_time();
- if (curr_tick > start_tick && /* timer not overflow (it's 32-bit variable) */
- (curr_tick - start_tick) < delay_tick)
- {
- #ifdef MMI_ON_WIN32
- Sleep(delay_tick - (curr_tick - start_tick));
- #else
- kal_sleep_task(delay_tick - (curr_tick - start_tick));
- #endif
- }
- gdi_lcd_freeze(FALSE);
- gdi_lcd_repaint_all();
- g_mmi_frm_profiling_delay_start_time[type] = 0;
- }
- #endif /* __MMI_INTERACTIVE_PROFILNG__ */