From: Ketmar Dark Date: Thu, 17 Aug 2017 13:09:15 +0000 (+0300) Subject: more profiler fixes X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=ef5f8a60d55c94c5c0e0b4f556867dc0ad9c2c44;p=d2df-sdl.git more profiler fixes --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index fa9c288..ff4006b 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1489,8 +1489,6 @@ var w: Word; i, b: Integer; begin - g_Map_ProfilersBegin(); - g_ResetDynlights(); // Ïîðà âûêëþ÷àòü èãðó: if gExit = EXIT_QUIT then @@ -2012,8 +2010,6 @@ begin end; if gGameOn then g_Weapon_AddDynLights(); - - g_Map_ProfilersEnd(); end; procedure g_Game_LoadData(); diff --git a/src/game/g_map.pas b/src/game/g_map.pas index b84bf3a..77660a8 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -205,9 +205,9 @@ begin // create sections if g_profile_collision then begin - profMapCollision.sectionBeginAccum('wall coldet'); + profMapCollision.sectionBegin('wall coldet'); profMapCollision.sectionEnd(); - profMapCollision.sectionBeginAccum('liquid coldet'); + profMapCollision.sectionBegin('liquid coldet'); profMapCollision.sectionEnd(); end; end; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 045a49f..e3226ea 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -47,7 +47,8 @@ uses {$IFDEF WINDOWS}Windows,{$ENDIF} SDL2, GL, GLExt, e_graphics, e_log, g_main, g_console, SysUtils, e_input, g_options, g_game, - g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net; + g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net, + g_map; var h_Wnd: PSDL_Window; @@ -577,6 +578,8 @@ begin wNeedTimeReset := False; end; + g_Map_ProfilersBegin(); + t := Time_Delta div 28{(27777 div 1000)}; if t > 0 then begin @@ -594,6 +597,8 @@ begin else if NetMode = NET_CLIENT then g_Net_Client_Update(); end; + g_Map_ProfilersEnd(); + if wLoadingQuit then begin g_Game_Free(); diff --git a/src/shared/xprofiler.pas b/src/shared/xprofiler.pas index 0837048..ac9b54b 100644 --- a/src/shared/xprofiler.pas +++ b/src/shared/xprofiler.pas @@ -15,6 +15,7 @@ *) // stopwatch timer to measure short periods (like frame rendering phases) {$INCLUDE a_modes.inc} +{.$DEFINE XPROFILER_SLOW_AVERAGE} unit xprofiler; interface @@ -69,7 +70,7 @@ type const - TProfHistorySize = 100; + TProfHistorySize = 1000; type TProfilerBar = record @@ -78,8 +79,10 @@ type private history: array [0..TProfHistorySize-1] of Integer; // circular buffer - hisHead: Integer; - curval: Single; + hisLast: Integer; + //curval: Single; + curAccum: UInt64; + curAccumCount: Integer; mName: AnsiString; mLevel: Integer; @@ -267,36 +270,42 @@ end; // ////////////////////////////////////////////////////////////////////////// // -procedure TProfilerBar.initialize (); begin hisHead := -1; curval := 0; end; +procedure TProfilerBar.initialize (); begin hisLast := -1; curAccum := 0; curAccumCount := 0; end; procedure TProfilerBar.update (val: Integer); var idx: Integer; begin if (val < 0) then val := 0; //else if (val > 1000000) val := 1000000; - if (hisHead = -1) then begin hisHead := 0; curval := 0; for idx := 0 to TProfHistorySize-1 do history[idx] := val; end; - history[hisHead] := val; - Inc(hisHead); - if (hisHead = TProfHistorySize) then hisHead := 0; - curval := FilterFadeoff*val+(1.0-FilterFadeoff)*curval; + if (hisLast = -1) then begin hisLast := TProfHistorySize-1; curAccum := 0; curAccumCount := 0; for idx := 0 to TProfHistorySize-1 do history[idx] := val; end; + if (curAccumCount = TProfHistorySize) then Dec(curAccum, UInt64(history[(hisLast+1) mod TProfHistorySize])) else Inc(curAccumCount); + Inc(hisLast); + if (hisLast >= TProfHistorySize) then hisLast := 0; + Inc(curAccum, UInt64(val)); + history[hisLast] := val; + //curval := FilterFadeoff*val+(1.0-FilterFadeoff)*curval; end; function TProfilerBar.getvalue (): Integer; -//var idx: Integer; +{$IFDEF XPROFILER_SLOW_AVERAGE} +var idx: Integer; +{$ENDIF} begin - result := round(curval); - { + {$IFDEF XPROFILER_SLOW_AVERAGE} result := 0; for idx := 0 to TProfHistorySize-1 do Inc(result, history[idx]); result := result div TProfHistorySize; - } + {$ELSE} + //result := round(curval); + if curAccumCount > 0 then result := Integer(curAccum div curAccumCount) else result := 0; + {$ENDIF} end; function TProfilerBar.getcount (): Integer; begin result := TProfHistorySize; end; function TProfilerBar.getvalat (idx: Integer): Integer; begin - if (idx < 0) or (idx >= TProfHistorySize) then result := 0 else result := history[(hisHead-idx-1+TProfHistorySize*2) mod TProfHistorySize]; + if (idx < 0) or (idx >= TProfHistorySize) then result := 0 else result := history[(hisLast-idx+TProfHistorySize*2) mod TProfHistorySize]; end;