Skip to content

Commit

Permalink
Add: TFastStack for code profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
yavfast@gmail.com committed Aug 23, 2014
1 parent c50ca14 commit b4345e2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
9 changes: 1 addition & 8 deletions DbgCodeProfiler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ function TDbgCodeProfiler.ProcessTrackBreakPoint(DebugEvent: PDebugEvent): LongB
end;
end;

// Ñîçäàíèå íîâîé çàïèñè äëÿ Track Stack
TrackStackPoint := AllocMem(SizeOf(TTrackStackPoint));

// Äîáàâëÿåì â Track Stack
ThData^.DbgTrackStack.Push(TrackStackPoint);
TrackStackPoint := ThData^.DbgTrackStack.Push;

TrackStackPoint^.TrackFuncInfo := TrackFuncInfo;
TrackStackPoint^.ParentTrackFuncInfo := ParentTrackFuncInfo;
Expand Down Expand Up @@ -293,12 +290,8 @@ function TDbgCodeProfiler.ProcessTrackRETBreakPoint(DebugEvent: PDebugEvent): Lo
if TrackStackPoint^.TrackRETBreakpoint = TrackRETBp then
begin
// Dec(TrackRETBp.Count);

FreeMemory(TrackStackPoint);
Break;
end;

FreeMemory(TrackStackPoint);
end;
end;

Expand Down
71 changes: 69 additions & 2 deletions DebugerTypes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,23 @@ TTrackStackPoint = record
property Leave: UInt64 read GetLeave write SetLeave;
end;

TTrackStack = class(TStack);
TFastStack<T> = class
private
FTop: Integer;
FItems: array of T;

procedure Grow;
function GetCount: Integer; inline;
public
constructor Create(const ACapacity: Integer = 64);

function Push: Pointer;
function Pop: Pointer;
property Count: Integer read GetCount;
end;

TTrackStack = TFastStack<TTrackStackPoint>;


TThreadAdvInfoList = TBaseCollectList; //TCollectList<TThreadAdvInfo>;

Expand Down Expand Up @@ -981,7 +997,7 @@ procedure TThreadData.Init;
DbgTrackFuncList := TCodeTrackFuncInfoList.Create(4096, True);
DbgTrackFuncList.OwnsValues := True;

DbgTrackStack := TTrackStack.Create;
DbgTrackStack := TTrackStack.Create(64);
end;

procedure TThreadData.UpdateGetMemUnitList;
Expand Down Expand Up @@ -1929,4 +1945,55 @@ destructor TDbgLogItem.Destroy;
inherited;
end;

{ TTrackStack<T> }

constructor TFastStack<T>.Create(const ACapacity: Integer);
begin
inherited Create;

FTop := -1;
SetLength(FItems, ACapacity);
end;

function TFastStack<T>.GetCount: Integer;
begin
Result := FTop + 1;
end;

procedure TFastStack<T>.Grow;
var
L: Integer;
Delta: Integer;
begin
L := Length(Fitems);

if L <= 32 then
Delta := L
else
Delta := L div 2;

SetLength(FItems, L + Delta);
end;

function TFastStack<T>.Pop: Pointer;
begin
if FTop >= 0 then
begin
Result := @FItems[FTop];
Dec(FTop);
end
else
Result := Nil;
end;

function TFastStack<T>.Push: Pointer;
begin
Inc(FTop);

if FTop = Length(FItems) then
Grow;

Result := @FItems[FTop];
end;

end.

0 comments on commit b4345e2

Please sign in to comment.