Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Profile.h
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if !defined(TGS_COMMON_PROFILE_H)
#define TGS_COMMON_PROFILE_H
#pragma once
#if TgCOMPILE_PROFILE


/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Types                                                                                                                                                          */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

enum { KTgMAX_PROFILE                       =   128 };  /*« Maximum number of profile tags in the system */
enum { KTgMAX_PROFILE_CALL                  =  4096 };  /*« Maximum number of in-flight calls in the system */
enum { KTgMAX_PROFILE_NAME_LENGTH           =   128 };  /*« Maximum string length of a profile tag. */
enum { KTgMAX_PROFILE_TL                    =    32 };  /*« Maximum number of thread local profile tags in the system */
enum { KTgMAX_PROFILE_TL_CALL               =   256 };  /*« Maximum number of thread local in-flight calls in the system */

#define PFCAT(A,B)                          A##B
#define PFCAT5(A,B,C,D,E)                   A##B##C##D##E
#define PFSTR(A)                            TgT(#A)

#define PROFILE_DEFINE(...)                 TgPROFILE_ID PFCAT(KTgPF_,__VA_ARGS__)
#define PROFILE_EXTERN(...)                 TgEXTN TgPROFILE_ID PFCAT(KTgPF_,__VA_ARGS__)
#define PROFILE_IS_INIT(...)                tgPROFILE_ID_Is_Valid( &PFCAT(KTgPF_,__VA_ARGS__) )
#define PROFILE_INIT(...)                   PFCAT(KTgPF_,__VA_ARGS__) = tgPF_Mark_Init( PFSTR(__VA_ARGS__) )
#define PROFILE_START(...)                  C_TgPROFILE_CALL_ID PFCAT5(profile_,__VA_ARGS__,call,__FUNC__,id) = tgPF_Mark_Start(PFCAT(KTgPF_,__VA_ARGS__))
#define PROFILE_STOP(...)                   tgPF_Mark_Stop( PFCAT(KTgPF_,__VA_ARGS__), PFCAT5(profile_,__VA_ARGS__,call,__FUNC__,id) )
#define PROFILE_RESET(...)                  tgPF_Mark_Reset( PFCAT(KTgPF_,__VA_ARGS__) )
#define PROFILE_NAME(...)                   tgPF_Query_Name( PFCAT(KTgPF_,__VA_ARGS__) )
#define PROFILE_TOTAL_TIME_CACHED(...)      tgPF_Query_Total_Time_Cached( PFCAT(KTgPF_,__VA_ARGS__) )

#define PROFILE_ARRAY_DEFINE(A,...)         TgPROFILE_ID PFCAT(KTgPF_,__VA_ARGS__)[A]
#define PROFILE_ARRAY_EXTERN(A,...)         TgEXTN TgPROFILE_ID PFCAT(KTgPF_,__VA_ARGS__)[A]
#define PROFILE_ARRAY_IS_INIT(A,...)        tgPROFILE_ID_Is_Valid( &PFCAT(KTgPF_,__VA_ARGS__) [A])
#define PROFILE_ARRAY_INIT(A,B,...)         PFCAT(KTgPF_,__VA_ARGS__)[A] = tgPF_Mark_Init(PFSTR(PFCAT(__VA_ARGS__,B)))
#define PROFILE_ARRAY_START(A,...)          C_TgPROFILE_CALL_ID PFCAT5(profile_,__VA_ARGS__,call,__FUNC__,id) = tgPF_Mark_Start(PFCAT(KTgPF_,__VA_ARGS__)[A])
#define PROFILE_ARRAY_STOP(A,...)           tgPF_Mark_Stop( PFCAT(KTgPF_,__VA_ARGS__)[A], PFCAT5(profile_,__VA_ARGS__,call,__FUNC__,id) )
#define PROFILE_ARRAY_RESET(A,...)          tgPF_Mark_Reset( PFCAT(KTgPF_,__VA_ARGS__)[A] )
#define PROFILE_ARRAY_NAME(A,...)           tgPF_Query_Name( PFCAT(KTgPF_,__VA_ARGS__)[A] )
#define PROFILE_ARRAY_TOTAL_TIME_CACHED(A,...) tgPF_Query_Total_Time_Cached( PFCAT(KTgPF_,__VA_ARGS__)[A] )

#define PROFILE_TL_DEFINE(...)              TgPROFILE_TL_ID PFCAT(KTgPF_,__VA_ARGS__)
#define PROFILE_TL_EXTERN(...)              TgEXTN TgPROFILE_TL_ID PFCAT(KTgPF_,__VA_ARGS__)
#define PROFILE_TL_IS_INIT(...)             tgPROFILE_TL_ID_Is_Valid( &PFCAT(KTgPF_,__VA_ARGS__) )
#define PROFILE_TL_INIT(...)                PFCAT(KTgPF_,__VA_ARGS__) = tgPF_TL_Mark_Init( PFSTR(__VA_ARGS__) )
#define PROFILE_TL_START(...)               C_TgPROFILE_CALL_TL_ID PFCAT5(profile_,__VA_ARGS__,call,__FUNC__,id) = tgPF_TL_Mark_Start(PFCAT(KTgPF_,__VA_ARGS__))
#define PROFILE_TL_STOP(...)                tgPF_TL_Mark_Stop( PFCAT(KTgPF_,__VA_ARGS__), PFCAT5(profile_,__VA_ARGS__,call,__FUNC__,id) )
#define PROFILE_TL_RESET(...)               tgPF_TL_Mark_Reset( PFCAT(KTgPF_,__VA_ARGS__) )
#define PROFILE_TL_NAME(...)                tgPF_TL_Query_Name( PFCAT(KTgPF_,__VA_ARGS__) )
#define PROFILE_TL_TOTAL_TIME_CACHED(...)   tgPF_TL_Query_Total_Time_Cached( PFCAT(KTgPF_,__VA_ARGS__) )


/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* The profile system tracks time spent per call and on module update will aggregate values into a per-tag summary. */
/* Note: time spent in a profile tag across multiple threads will be collected correctly, but time spent on a single thread in a function recursively will not be correct */

TgEXTN TgRESULT                             tgPF_Init( TgVOID );
TgEXTN TgRESULT                             tgPF_Boot( TgVOID );
TgEXTN TgVOID                               tgPF_Stop( TgVOID );
TgEXTN TgVOID                               tgPF_Free( TgVOID );
TgEXTN TgRESULT                             tgPF_Update( C_TgFLOAT32 );

TgEXTN TgBOOL                               tgPF_Query_Init( TgVOID );
TgEXTN TgBOOL                               tgPF_Query_Boot( TgVOID );

TgEXTN TgSIZE                               tgPF_Query_Fixed_Memory( TgVOID );

TgEXTN TgVOID                               tgPF_Report_Module( PC_STg2_Output );

TgEXTN TgPROFILE_ID                         tgPF_Mark_Init( CPC_TgCHAR );
TgEXTN TgPROFILE_CALL_ID                    tgPF_Mark_Start( C_TgPROFILE_ID );
TgEXTN TgVOID                               tgPF_Mark_Stop( C_TgPROFILE_ID, C_TgPROFILE_CALL_ID );
TgEXTN TgVOID                               tgPF_Mark_Reset( C_TgPROFILE_ID );

TgEXTN CP_TgCHAR                            tgPF_Query_Name( C_TgPROFILE_ID );
TgEXTN TgFLOAT64                            tgPF_Query_Total_Time_Cached( C_TgPROFILE_ID );

/* ---- Thread Local ------------------------------------------------------------------------------------------------------------------------------------------------------ */

TgEXTN TgRESULT                             tgPF_TL_Init_Boot( TgVOID );
TgEXTN TgVOID                               tgPF_TL_Stop_Free( TgVOID );
TgEXTN TgRESULT                             tgPF_TL_Update( C_TgFLOAT32 );

TgEXTN TgBOOL                               tgPF_TL_Query_Init( TgVOID );
TgEXTN TgBOOL                               tgPF_TL_Query_Boot( TgVOID );

TgEXTN TgSIZE                               tgPF_TL_Query_Fixed_Memory( TgVOID );

TgEXTN TgVOID                               tgPF_TL_Report_Module( PC_STg2_Output );

TgEXTN TgPROFILE_TL_ID                      tgPF_TL_Mark_Init( CPC_TgCHAR );
TgEXTN TgPROFILE_TL_CALL_ID                 tgPF_TL_Mark_Start( C_TgPROFILE_TL_ID );
TgEXTN TgVOID                               tgPF_TL_Mark_Stop( C_TgPROFILE_TL_ID, C_TgPROFILE_TL_CALL_ID );
TgEXTN TgVOID                               tgPF_TL_Mark_Reset( C_TgPROFILE_TL_ID );

TgEXTN CP_TgCHAR                            tgPF_TL_Query_Name( C_TgPROFILE_TL_ID );
TgEXTN TgFLOAT64                            tgPF_TL_Query_Total_Time_Cached( C_TgPROFILE_TL_ID );

/*# TgCOMPILE_PROFILE */
#else

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Profile System Disabled */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#define PFCAT(a,b)                          a##b

#define PROFILE_DEFINE(tag)                 UNUSED_TYPE TgSINT32 PFCAT(TgNOT_USED__, tag)
#define PROFILE_EXTERN(tag)                 TgEXTN TgSINT32 PFCAT(TgNOT_USED__, tag)
#define PROFILE_IS_INIT(tag)                TgFALSE
#define PROFILE_INIT(tag)
#define PROFILE_START(tag)
#define PROFILE_STOP(tag)
#define PROFILE_RESET(tag)

#define PROFILE_ARRAY_DEFINE(A,...)         UNUSED_TYPE TgSINT32 PFCAT(TgNOT_USED_ARRAY__, __VA_ARGS__)
#define PROFILE_ARRAY_EXTERN(A,...)         TgEXTN TgSINT32 PFCAT(TgNOT_USED_ARRAY__, __VA_ARGS__)
#define PROFILE_ARRAY_IS_INIT(A,...)        TgFALSE
#define PROFILE_ARRAY_INIT(A,B,...)
#define PROFILE_ARRAY_START(A,...)
#define PROFILE_ARRAY_STOP(A,...)
#define PROFILE_ARRAY_RESET(A,...)

#define PROFILE_TL_DEFINE(tag)              UNUSED_TYPE TgSINT32 PFCAT(TgNOT_USED_TLS__, tag)
#define PROFILE_TL_EXTERN(tag)              TgEXTN TgSINT32 PFCAT(TgNOT_USED_TLS__, tag)
#define PROFILE_TL_IS_INIT(tag)             TgFALSE
#define PROFILE_TL_INIT(tag)
#define PROFILE_TL_START(tag)
#define PROFILE_TL_STOP(tag)
#define PROFILE_TL_RESET(tag)

/*# TgCOMPILE_PROFILE */
#endif


/* ====================================================================================================================================================================== */
#endif