home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / diagnostic / hierprof_2 / !HierProf / h / HierProf
Text File  |  1995-10-15  |  5KB  |  205 lines

  1. /*
  2.     #   # #             ####                ##
  3.     #   #               #   #              #  #
  4.     #   # #  ###  # ##  #   # # ##   ###   #
  5.     ##### # #   # ##  # ####  ##  # #   # ###  
  6.     #   # # ##### #     #     #     #   #  #
  7.     #   # # #     #     #     #     #   #  #   
  8.     #   # #  ###  #     #     #      ###   #   
  9.     ___________________________________________
  10.  
  11.  
  12. Author:        Copyright © 1995 Julian Smith
  13. Purpose:    Hierachical profiling of C code.
  14.  
  15. */
  16.  
  17. /*
  18. All HierProf_ macros should /not/ be followed by the usual ';' character.
  19.  
  20. Example HierProf usage:
  21.  
  22. int    Foo()
  23. {
  24. HierProf_FnStart( "Foo")
  25.  
  26. HierProf_Start( "Loop")
  27. for(...)    { ...    }
  28. HierProf_Stop()
  29. if (...)    HierProf_ReturnValue( 3)
  30. HierProf_NonVoidFnStop()
  31. }
  32.  
  33. void    Bar()
  34. {
  35. HierProf_FnStart( "Bar")
  36. if (...)    HierProf_ReturnVoid()
  37. HierProf_VoidFnStop()
  38. }
  39.  
  40. Or you can use HierProfCC to automatically add such macros to a C source
  41. file before compilation.
  42.  */
  43.  
  44. #ifndef __HierProf_h
  45. #define    __HierProf_h
  46.  
  47.  
  48. #ifdef __cplusplus
  49. extern "C"    {
  50. #endif
  51.  
  52.  
  53. #include <stdio.h>
  54.  
  55.  
  56. /*
  57. The following are to control where profile output will be sent. The
  58. default is to send it to stderr using the function fprintf. You can send
  59. profiling output to your own function if you like.
  60.  */
  61.  
  62.  
  63. typedef int (*HierProf_printfnptr)( void *where, const char *format, ...);
  64. /* 
  65. A pointer to a fprintf-type function, except the first argument is a
  66. (void *) rather than a (FILE *).
  67.  */
  68.  
  69. void    HierProf_InitOuterNesting( void);
  70. /*
  71. Tells Profile to start its outer loop. This is done automatically at the
  72. beginning of the first profile loop if you don't call this function
  73. yourself.
  74.  */
  75.  
  76. void    HierProf_OutputToFunction( HierProf_printfnptr function, void *where);
  77. /*
  78. Send subsequent profiles to this function. 'where' will be sent as the
  79. first argument to 'function'. e.g. to send output to stderr, use
  80. HierProf_OutputToFunction( (HierProf_printfnptr) fprintf, stderr);
  81.  */
  82.  
  83. void    HierProf_OutputToTempFile( void);
  84. /*
  85. Send subsequent profiles to filename returned by ANSI C's tmpnam()
  86. function. With Acorn C, this will be a file in the directory
  87. <Wimp$ScrapDir>
  88.  */
  89.  
  90. void    HierProf_OutputToFilenamef( char *fmt, ...);
  91. /*
  92. Send subsequent profiles to this filename.
  93.  */
  94.  
  95. void    HierProf_OutputToFilestream( FILE *stream);
  96. /* 
  97. Send subsequent profiles to this filestream
  98.  */
  99.  
  100. void    HierProf_DontOutput( void);
  101. /*
  102. Make subsequent profiles not output anything.
  103.  */
  104.  
  105. void    HierProf_OutputNow( void);
  106. /*
  107. Sends a full profile resume to whatever is the current output
  108. stream/function/filename
  109.  */
  110.  
  111.  
  112.  
  113.  
  114.  
  115. /* These determines the timer used by the HierProf library.    */
  116. #include <time.h>
  117. typedef unsigned int            HierProf_clock_t;
  118. #define    HierProf_CLOCKS_PER_SEC        CLOCKS_PER_SEC
  119. #define    HierProf_Clock()        ( (HierProf_clock_t) clock())
  120.  
  121. #define    HierProf_WindClock()
  122. /* Called by HierProf library at start of program    */    
  123.  
  124. #define    HierProf_UnwindClock()
  125. /* Called by HierProf library at end of program        */
  126.  
  127.  
  128.  
  129.  
  130. /* These are called by the HierProf block start/stop macros    */
  131. int    HierProf__InitBlock( char* name);
  132. void    HierProf__StartClock( int ref, HierProf_clock_t t);
  133. void    HierProf__StopClock( int ref, HierProf_clock_t t);
  134.  
  135.  
  136.  
  137.  
  138.  
  139. #ifdef HierProf_PROFILE
  140.  
  141.     
  142.     #define    HierProf__StartBlock( name, ref)            \
  143.         {                            \
  144.         static int    ref = 0;                \
  145.         if ( ref==0)    ref = HierProf__InitBlock( name);    \
  146.         HierProf__StartClock( ref, HierProf_Clock());        \
  147.         {
  148.     
  149.     #define    HierProf__StopBlock( ref)            \
  150.         }                        \
  151.         HierProf__StopClock( ref, HierProf_Clock());    \
  152.         }
  153.     
  154.     #define    HierProf_Start( name)        HierProf__StartBlock( name, HierProf__ref)
  155.     #define    HierProf_Stop()            HierProf__StopBlock( HierProf__ref)
  156.     
  157.     #define    HierProf_FnStart( name)        HierProf__StartBlock( name, HierProf__fnref)
  158.     #define    HierProf_VoidFnStop()        HierProf__StopBlock( HierProf__fnref)
  159.     #define    HierProf_NonVoidFnStop()    }}
  160.     
  161.     #define    HierProf_ReturnValue( x)                    \
  162.         {                                \
  163.         HierProf__StopClock( HierProf__fnref, HierProf_Clock());    \
  164.         return x;                            \
  165.         }
  166.     
  167.     #define    HierProf_ReturnVoid()                        \
  168.         {                                \
  169.         HierProf__StopClock( HierProf__fnref, HierProf_Clock());    \
  170.         return;                                \
  171.         }
  172.     
  173.     #define    HierProf_DontProfile()
  174.     
  175.  
  176. #else
  177.  
  178.     #define    HierProf_Start( name)
  179.     #define    HierProf_Stop()
  180.     #define    HierProf_FnStart( name)
  181.     #define    HierProf_VoidFnStop()
  182.     #define    HierProf_NonVoidFnStop()
  183.     #define    HierProf_ReturnValue( x)    return x;
  184.     #define    HierProf_ReturnVoid()        return;
  185.     
  186.     #define    HierProf_InitOuterNesting()
  187.     #define    HierProf_OutputToFunction( function, where)
  188.     #define    HierProf_OutputToTempFile()
  189.     #define    HierProf_OutputToFilenamef (1) ? 0 : printf
  190.     #define    HierProf_OutputToFilestream( stream)
  191.     #define    HierProf_DontOutput()
  192.     #define    HierProf_OutputNow()
  193.     #define    HierProf_DontProfile()
  194.  
  195.  
  196. #endif
  197.  
  198.  
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202.  
  203.  
  204. #endif
  205.