⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hxchkpt.h

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

/* These Macros are useful when trying to tune performance to see approximately how long in milliseconds certain lines of
 * code are taking.  The output will display approximately how long it took for the lines between checkpoints.
 * 
 * Available macros in this file and how to use them:
 * 
 * HX_ENABLE_CHECKPOINTS_FOR_MODULE(pModuleName, pOutputFileName)
 * This macro should be used once for the entire dll or exe you are compiling.  It declares a global that is used by the
 * entire module.  A good place to put this for example would be in the dllmain.cpp file.
 *
 * pModuleName -	The name of the directory in which the dll or exe you are compiling is located.  This is used 
 *			in the log when printing out the file name.
 * pOutputFileName -	The name of the output file name where checkpoint data is dumped
 * 
 * HX_LOG_INITIAL_CHECKPOINT(pFunctionName)
 * This macro should be used once at the beginning of each function or method you are interested in timing.
 * 
 * pFunctionName -	The name of the function that the checkpoints are in
 *
 * HX_LOG_CHECKPOINT(pComment)
 * This macro should be used whenver timing blocks of code are of interest.  This can be used repeatedly in each function.
 *
 * pComment -		The comment passed in will be dumped to the log file.  It is used as a hint to what was being executed
 *			for this checkpoint instead of having to refer back to the code.
 *
 * HX_LOG_BLOCK( pComment )
 * This macro logs entry to and exit from a brace delimited block. It writes out two checkpoints - the entry checkpoint 
 * will be the comment prefixed with 'Enter', the exit checkpoint will be the comment prefixed with 'Exit'
 * Note that this macro cannot be used in the same block as HX_LOG_INITIAL_CHECKPOINT.
 *
 * pComment -		An identifier for the block. Since blocks often correspond to functions this will often be the function name.
 *
 * 	   
 * LOG FILE FORMAT
 * The log file is written to in append mode and is several fields delimited by a ;
 * It can easily be loaded into a spreadsheet app since all of them should be able to read delimted text files.
 * Here is a breakdown of the individual fields:
 * Field1: Time elapsed since the last checkpoint
 * Field2: Time elapsed since the first checkpoint in the function
 * Field3: Time elapsed since the first checkpoint in the module
 * Field4: Tick count as reported from the OS
 * Field5: Path to file name
 * Field6: Function name
 * Field7: Line Number of checkpoint
 * Field8: Comment about what the checkpoint is timing
 */

#ifndef _HXCHKPT_H_
#define _HXCHKPT_H_

#if defined( ENABLE_CHECKPOINTS2 ) || defined( ENABLE_PERFORMANCE2 )

#include "hxperf.h"

#elif defined( ENABLE_CHECKPOINTS )

#include "hlxclib/stdio.h"
#include "hxtick.h"
#include "hxmap.h"

#define MAX_CHECKPOINTLISTS_PER_MODULE	256
#define MAX_CHECKPOINTS_PER_FUNCTION	1024
#define MAX_ACCUMULATORS_PER_FUNCTION	64

// This class represents the data that is unique per checkpoint
class CHXCheckpoint
{
public:
    CHXCheckpoint() :
	m_ulLineNumber(0),
	m_ulTime(0)
    {
    }

    ~CHXCheckpoint()
    {
    }

    // These are public members for access speed since the checkpoint code should be as lightweight as possible.  I am
    // also trying to reduce the number of lines of code since this is all inline in a header file.
    UINT32		m_ulLineNumber;
    UINT32		m_ulTime;
    char		m_pStaticComment[ 64 ]; /* Flawfinder: ignore */
};


class CHXAccumCheckpoint : 
    public CHXCheckpoint
{
public:
    CHXAccumCheckpoint() :
	CHXCheckpoint(),
	m_ulID( 0 ),
	m_ulMarker( 0 )
    {
    }

public:
    UINT32 		m_ulID;
    UINT32		m_ulMarker;
};


// This class represents a way to categorize the checkpoints associated with a function or method.  It contains the list
// of checkpoints for that function or method and the filename where that function or method is located.
class CHXCheckpointList
{
public:
    CHXCheckpointList(const char* pFunctionName, const char* pSourceFileName);

    ~CHXCheckpointList()
    {
    }

    void AddCheckpoint(const char* pComment, UINT32 ulLineNumber, UINT32 ulTime)
    {
	if( m_ulCheckpointIndex < MAX_CHECKPOINTS_PER_FUNCTION )
	{
	    CHXCheckpoint* pCheckpoint = &m_CheckpointArray[m_ulCheckpointIndex];
	    pCheckpoint->m_ulLineNumber = ulLineNumber;
	    pCheckpoint->m_ulTime = ulTime;
	    UINT32 copySize = sizeof(pCheckpoint->m_pStaticComment) - 1;
	    ::strncpy( pCheckpoint->m_pStaticComment, pComment, copySize ); /* Flawfinder: ignore */
	    pCheckpoint->m_pStaticComment[copySize] = '\0';
	    m_ulCheckpointIndex++;
	}
	else
	{
    	    for( int i = 0; i < MAX_CHECKPOINTS_PER_FUNCTION; ++i )
	    {
		CHXCheckpoint* pCheckpoint = &m_CheckpointArray[i];
		UINT32 copySize = sizeof(pCheckpoint->m_pStaticComment) - 1;
		::strncpy( pCheckpoint->m_pStaticComment, "***ERROR*** - too many checkpoints in checkpoint list", copySize ); /* Flawfinder: ignore */
		pCheckpoint->m_pStaticComment[copySize] = '\0';
	    }
	}
    }

    void PrimeAccumulator( UINT32 id, const char* pComment, UINT32 ulLineNumber, UINT32 ulTime )
    {
	void* pValue = NULL;
	if( m_accumulators.Lookup( id, pValue ) )
	{
	    CHXAccumCheckpoint* pCheckpoint = (CHXAccumCheckpoint*) pValue;
	    pCheckpoint->m_ulMarker = ulTime;
	}
	else if( m_ulAccumulatorIndex < MAX_ACCUMULATORS_PER_FUNCTION )
	{
	    CHXAccumCheckpoint* pCheckpoint = &m_AccumulatorArray[ m_ulAccumulatorIndex++ ];
	    m_accumulators.SetAt( id, pCheckpoint );

	    pCheckpoint->m_ulID = id;
	    pCheckpoint->m_ulLineNumber = ulLineNumber;
	    pCheckpoint->m_ulMarker = ulTime;
	    UINT32 copySize = sizeof(pCheckpoint->m_pStaticComment) - 1;
	    ::strncpy( pCheckpoint->m_pStaticComment, pComment, copySize ); /* Flawfinder: ignore */
	    pCheckpoint->m_pStaticComment[copySize] = '\0';
	}
	else
	{
	    for( int i = 0; i < MAX_ACCUMULATORS_PER_FUNCTION; ++i )
	    {
		CHXAccumCheckpoint* pCheckpoint = &m_AccumulatorArray[ i ];
		UINT32 copySize = sizeof(pCheckpoint->m_pStaticComment) - 1;
		::strncpy( pCheckpoint->m_pStaticComment, "***ERROR*** - too many accumulator checkpoints in checkpoint list", copySize ); /* Flawfinder: ignore */
		pCheckpoint->m_pStaticComment[copySize] = '\0';
	    }
	}
    }

    void UpdateAccumulator( UINT32 id, UINT32 ulTime )
    {
	void* pValue = NULL;
	if( m_accumulators.Lookup( id, pValue ) )
	{
	    CHXAccumCheckpoint* pCheckpoint = (CHXAccumCheckpoint*) pValue;
	    pCheckpoint->m_ulTime += ulTime - pCheckpoint->m_ulMarker;
	    pCheckpoint->m_ulMarker = 0;
	}
    }

    void AccumulateValue( UINT32 id, const char* pComment, UINT32 ulLineNumber, UINT32 ulValue )
    {
	void* pValue = NULL;
	if( m_accumulators.Lookup( id, pValue ) )
	{
	    CHXAccumCheckpoint* pCheckpoint = (CHXAccumCheckpoint*) pValue;
	    pCheckpoint->m_ulTime += ulValue;
	}
	else if( m_ulAccumulatorIndex < MAX_ACCUMULATORS_PER_FUNCTION )
	{
	    CHXAccumCheckpoint* pCheckpoint = &m_AccumulatorArray[ m_ulAccumulatorIndex++ ];
	    m_accumulators.SetAt( id, pCheckpoint );

	    pCheckpoint->m_ulID = id;
	    pCheckpoint->m_ulLineNumber = ulLineNumber;
	    pCheckpoint->m_ulTime = ulValue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -