Files
harbour-core/harbour/tests/testprof.prg
Viktor Szakats 6ae6c60b2f 2012-10-12 17:25 UTC+0200 Viktor Szakats (harbour syenar.net)
* contrib/hbmysql/utils/dbf2mysq.prg
    * formatting. for some reason hbformat misses to
      uppercase one specific FOR/NEXT loop.

  * contrib/hbnf/menu1.prg
  * contrib/hbnf/pegs.prg
  * contrib/hbnf/vertmenu.prg
  * extras/gtwvw/tests/prog0.prg
  * extras/gtwvw/tests/prog1.prg
  * extras/gtwvw/tests/prog2.prg
  * tests/db_brows.prg
  * tests/onidle.prg
  * tests/scroll.prg
  * tests/testbrw.prg
    % replaced DEVPOS()/DEVOUT() with HB_DISPOUTAT()/SETPOS()
      calls

  * include/harbour.hbx
  * contrib/hbnf/aredit.prg
  * contrib/hbnf/tbwhile.prg
  * extras/gtwvw/tests/prog0
  * extras/gtwvw/tests/prog1
  * extras/gtwvw/tests/prog2
  * extras/gtwvw/tests/wvwtest9
  * tests/brwpos.prg
  * tests/tb1.prg
  * tests/testbrw.prg
    ! fixed some function names wrongly camelcased

  * src/rtl/profiler.prg
    * formatted
    + added parameter list to METHOD declarations

  * tests/testprof.prg
    * replaced with copy embedded in src/rtl/profiler.prg
    * formatted

  * tests/wcecon.prg
    ! unicode fix
2012-10-12 15:26:58 +00:00

109 lines
2.4 KiB
Plaintext

/*
* $Id$
*/
/* Test code for the harbour profiler API and the profile reporting classes */
#include "inkey.ch"
PROCEDURE Main()
LOCAL oProfile := HBProfile():new()
LOCAL n
// Turn on profiling.
__SetProfiler( .T. )
// Make sure we've got something to see timewise.
DrawScreen( "Doing nothing for a couple of seconds" )
DoNothingForTwoSeconds()
// Make sure we've got something to see callwise.
FOR n := 1 TO 500
CallMe500Times()
NEXT
// Take a profile snapshot.
oProfile:gather()
// Report on calls greater than 0
DrawScreen( "All methods/functions called one or more times" )
MemoEdit( HBProfileReportToString():new( oProfile:callSort() ):generate( {| o | o:nCalls > 0 } ), 1,,,, .F. )
// Sorted by name
DrawScreen( "All methods/functions called one or more times, sorted by name" )
MemoEdit( HBProfileReportToString():new( oProfile:nameSort() ):generate( {| o | o:nCalls > 0 } ), 1,,,, .F. )
// Sorted by time
DrawScreen( "All methods/functions taking measurable time, sorted by time" )
MemoEdit( HBProfileReportToString():new( oProfile:timeSort() ):generate( {| o | o:nTicks > 0 } ), 1,,,, .F. )
// TBrowse all calls greater than 0
DrawScreen( "TBrowse all methods/functions called one or more times" )
Browser( HBProfileReportToTBrowse():new( oProfile:callSort() ):generate( {| o | o:nCalls > 0 }, 1 ) )
// Some closing stats
DrawScreen( "Totals" )
@ 2, 0 SAY " Total Calls: " + Str( oProfile:totalCalls() )
@ 3, 0 SAY " Total Ticks: " + Str( oProfile:totalTicks() )
@ 4, 0 SAY "Total Seconds: " + Str( oProfile:totalSeconds() )
RETURN
STATIC PROCEDURE DrawScreen( cTitle )
CLS
@ 0, 0 SAY PadR( cTitle, MaxCol() + 1 ) COLOR "N/W"
RETURN
PROCEDURE DoNothingForTwoSeconds()
Inkey( 2 )
RETURN
PROCEDURE CallMe500Times()
RETURN
STATIC PROCEDURE Browser( oBrowse )
LOCAL lBrowsing := .T.
DO WHILE lBrowsing
oBrowse:forceStable()
SWITCH Inkey( 0 )
CASE K_ESC
lBrowsing := .F.
EXIT
CASE K_DOWN
oBrowse:down()
EXIT
CASE K_UP
oBrowse:up()
EXIT
CASE K_LEFT
oBrowse:left()
EXIT
CASE K_RIGHT
oBrowse:right()
EXIT
CASE K_PGDN
oBrowse:pageDown()
EXIT
CASE K_PGUP
oBrowse:pageUp()
EXIT
// And so on.... (not really necessary for this test)
ENDSWITCH
ENDDO
RETURN