| @@ -25,7 +25,7 @@ implementation | |||||
| {$IFDEF PROFILER_ENABLE} | {$IFDEF PROFILER_ENABLE} | ||||
| uses | uses | ||||
| Windows, Classes, unFastFileStream; | |||||
| Windows, Classes; | |||||
| type | type | ||||
| TWriterThread = class(TThread) | TWriterThread = class(TThread) | ||||
| @@ -47,21 +47,16 @@ type | |||||
| end; | end; | ||||
| TProfileDataFile = class | TProfileDataFile = class | ||||
| private | |||||
| fDF: TStream; | |||||
| public | public | ||||
| constructor Create(const {%H-}aFileName: string); | |||||
| procedure WriteEnter(Thread: TThreadID; When: Int64; Func: PtrUInt; Name: string); virtual; abstract; | |||||
| procedure WriteLeave(Thread: TThreadID; When: Int64); virtual; abstract; | |||||
| constructor Create(const aFileName: string); | |||||
| destructor Destroy; override; | |||||
| procedure WriteEnter(Thread: TThreadID; When: Int64; Func: PtrUInt; Name: string); | |||||
| procedure WriteLeave(Thread: TThreadID; When: Int64); | |||||
| end; | end; | ||||
| {$DEFINE __HEAD} | |||||
| //{$I uutlProfilerPlainText.inc} | |||||
| {$I uutlProfilerBinary.inc} | |||||
| //{$I uutlProfilerPlainTextMMap.inc} | |||||
| {$UnDef __HEAD} | |||||
| //{$I uutlProfilerPlainText.inc} | |||||
| {$I uutlProfilerBinary.inc} | |||||
| //{$I uutlProfilerPlainTextMMap.inc} | |||||
| {$I uutlProfilerBinaryFmt.inc} | |||||
| const | const | ||||
| MAX_EVENT_COUNT = 1000; | MAX_EVENT_COUNT = 1000; | ||||
| @@ -175,13 +170,6 @@ begin | |||||
| end; | end; | ||||
| end; | end; | ||||
| { TProfileDataFile } | |||||
| constructor TProfileDataFile.Create(const aFileName: string); | |||||
| begin | |||||
| inherited Create; | |||||
| end; | |||||
| { TWriterThread } | { TWriterThread } | ||||
| constructor TWriterThread.Create; | constructor TWriterThread.Create; | ||||
| @@ -216,8 +204,6 @@ begin | |||||
| end; | end; | ||||
| procedure TWriterThread.SaveCurrentWrite; | procedure TWriterThread.SaveCurrentWrite; | ||||
| var | |||||
| i: integer; | |||||
| begin | begin | ||||
| if Events[WritePtr].Func = 0 then | if Events[WritePtr].Func = 0 then | ||||
| exit; | exit; | ||||
| @@ -229,6 +215,54 @@ begin | |||||
| Events[WritePtr].Func:= 0; | Events[WritePtr].Func:= 0; | ||||
| end; | end; | ||||
| { TProfileDataFile } | |||||
| constructor TProfileDataFile.Create(const aFileName: string); | |||||
| var | |||||
| H: TPBHeader; | |||||
| begin | |||||
| inherited Create; | |||||
| // fDF:= TFastFileStream.Create(aFileName, fmCreate); | |||||
| fDF:= TFileStream.Create(aFileName, fmCreate); | |||||
| H.VersionMagic:= NtoBE(HEADER_VER_MAGIC); | |||||
| H.PtrSize:= Sizeof(PtrUInt); | |||||
| H.ProgramName:= ExtractFileName(ParamStr(0)); | |||||
| fDF.Write(H, sizeof(H)); | |||||
| end; | |||||
| destructor TProfileDataFile.Destroy; | |||||
| begin | |||||
| FreeAndNil(fDF); | |||||
| inherited; | |||||
| end; | |||||
| procedure TProfileDataFile.WriteEnter(Thread: TThreadID; When: Int64; Func: PtrUInt; Name: string); | |||||
| var | |||||
| H: TPBEventHeader; | |||||
| R: TPBEventEnterProc; | |||||
| begin | |||||
| H.ThreadID:= Thread; | |||||
| H.Timestamp:= When; | |||||
| H.Kind:= PB_KIND_ENTER; | |||||
| fDF.Write(H, Sizeof(H)); | |||||
| R.Func:= Func; | |||||
| R.NameLen:= Length(Name); | |||||
| fDF.Write(R, Sizeof(R)); | |||||
| if R.NameLen > 0 then | |||||
| fDF.Write(Name[1], R.NameLen); | |||||
| end; | |||||
| procedure TProfileDataFile.WriteLeave(Thread: TThreadID; When: Int64); | |||||
| var | |||||
| H: TPBEventHeader; | |||||
| begin | |||||
| H.ThreadID:= Thread; | |||||
| H.Timestamp:= When; | |||||
| H.Kind:= PB_KIND_EXIT; | |||||
| fDF.Write(H, Sizeof(H)); | |||||
| end; | |||||
| {$ELSE} | {$ELSE} | ||||
| procedure ProfilerEnterProc(const Addr: Pointer); inline; | procedure ProfilerEnterProc(const Addr: Pointer); inline; | ||||
| @@ -249,9 +283,7 @@ initialization | |||||
| WritePtr:= 0; | WritePtr:= 0; | ||||
| WriterThread:= nil; | WriterThread:= nil; | ||||
| CalibrateLineNumberCompensation; | CalibrateLineNumberCompensation; | ||||
| //ProfilerDataFile:= TProfilePlainText.Create(ChangeFileExt(ParamStr(0), '.profraw')); | |||||
| ProfilerDataFile:= TProfileBinary.Create(ChangeFileExt(ParamStr(0), '.profbin')); | |||||
| //ProfilerDataFile:= TProfilePlainTextMMap.Create(ChangeFileExt(ParamStr(0), '.profraw')); | |||||
| ProfilerDataFile:= TProfileDataFile.Create(ChangeFileExt(ParamStr(0), '.profbin')); | |||||
| ProfilerEnabled:= true; | ProfilerEnabled:= true; | ||||
| {$ENDIF} | {$ENDIF} | ||||
| @@ -1,64 +0,0 @@ | |||||
| {$ifdef __HEAD} | |||||
| TProfileBinary = class(TProfileDataFile) | |||||
| private | |||||
| fDF: TFastFileStream; | |||||
| public | |||||
| constructor Create(const aFileName: string); | |||||
| destructor Destroy; override; | |||||
| procedure WriteEnter(Thread: TThreadID; When: Int64; Func: PtrUInt; Name: string); override; | |||||
| procedure WriteLeave(Thread: TThreadID; When: Int64); override; | |||||
| end; | |||||
| {$I uutlProfilerBinaryFmt.inc} | |||||
| {$ELSE} | |||||
| { TProfileBinary } | |||||
| constructor TProfileBinary.Create(const aFileName: string); | |||||
| var | |||||
| H: TPBHeader; | |||||
| begin | |||||
| inherited; | |||||
| fDF:= TFastFileStream.Create(aFileName, fmCreate); | |||||
| H.VersionMagic:= NtoBE(HEADER_VER_MAGIC); | |||||
| H.PtrSize:= Sizeof(PtrUInt); | |||||
| H.ProgramName:= ExtractFileName(ParamStr(0)); | |||||
| fDF.Write(H, sizeof(H)); | |||||
| end; | |||||
| destructor TProfileBinary.Destroy; | |||||
| begin | |||||
| FreeAndNil(fDF); | |||||
| inherited; | |||||
| end; | |||||
| procedure TProfileBinary.WriteEnter(Thread: TThreadID; When: Int64; Func: PtrUInt; Name: string); | |||||
| var | |||||
| H: TPBEventHeader; | |||||
| R: TPBEventEnterProc; | |||||
| begin | |||||
| H.ThreadID:= Thread; | |||||
| H.Timestamp:= When; | |||||
| H.Kind:= PB_KIND_ENTER; | |||||
| fDF.Write(H, Sizeof(H)); | |||||
| R.Func:= Func; | |||||
| R.NameLen:= Length(Name); | |||||
| fDF.Write(R, Sizeof(R)); | |||||
| if R.NameLen > 0 then | |||||
| fDF.Write(Name[1], R.NameLen); | |||||
| end; | |||||
| procedure TProfileBinary.WriteLeave(Thread: TThreadID; When: Int64); | |||||
| var | |||||
| H: TPBEventHeader; | |||||
| begin | |||||
| H.ThreadID:= Thread; | |||||
| H.Timestamp:= When; | |||||
| H.Kind:= PB_KIND_EXIT; | |||||
| fDF.Write(H, Sizeof(H)); | |||||
| end; | |||||
| {$ENDIF} | |||||
| @@ -1,49 +0,0 @@ | |||||
| {$ifdef __HEAD} | |||||
| TProfilePlainText = class(TProfileDataFile) | |||||
| private | |||||
| fDF: Textfile; | |||||
| fBuffer: array[0..16*1024-1] of byte; | |||||
| public | |||||
| constructor Create(const aFileName: string); | |||||
| destructor Destroy; override; | |||||
| procedure WriteEnter(Thread: TThreadID; When: Int64; Func, Src: String; Line: Integer); override; | |||||
| procedure WriteLeave(Thread: TThreadID; When: Int64); override; | |||||
| end; | |||||
| {$ELSE} | |||||
| { TProfilePlainText } | |||||
| constructor TProfilePlainText.Create(const aFileName: string); | |||||
| begin | |||||
| inherited; | |||||
| AssignFile(fDF, aFileName); | |||||
| SetTextBuf(fDF, {%H-}fBuffer[0], sizeof(fBuffer)); | |||||
| Rewrite(fDF); | |||||
| end; | |||||
| destructor TProfilePlainText.Destroy; | |||||
| begin | |||||
| CloseFile(fDF); | |||||
| inherited; | |||||
| end; | |||||
| procedure TProfilePlainText.WriteEnter(Thread: TThreadID; When: Int64; Func, Src: String; Line: Integer); | |||||
| var | |||||
| l: string; | |||||
| begin | |||||
| l:= hexStr(When, 16)+ ';'+hexStr(Thread, 4)+ ';'+Src+ ';'+IntToStr(Line)+';'+Func; | |||||
| WriteLn(fDF, l); | |||||
| end; | |||||
| procedure TProfilePlainText.WriteLeave(Thread: TThreadID; When: Int64); | |||||
| var | |||||
| l: string; | |||||
| begin | |||||
| l:= hexStr(When, 16)+ ';'+hexStr(Thread, 4)+ ';'; | |||||
| WriteLn(fDF, l); | |||||
| end; | |||||
| {$ENDIF} | |||||
| @@ -1,46 +0,0 @@ | |||||
| {$ifdef __HEAD} | |||||
| TProfilePlainTextMMap = class(TProfileDataFile) | |||||
| private | |||||
| fDF: TFastFileStream; | |||||
| public | |||||
| constructor Create(const aFileName: string); | |||||
| destructor Destroy; override; | |||||
| procedure WriteEnter(Thread: TThreadID; When: Int64; Func, Src: String; Line: Integer); override; | |||||
| procedure WriteLeave(Thread: TThreadID; When: Int64); override; | |||||
| end; | |||||
| {$ELSE} | |||||
| { TProfilePlainTextMMap } | |||||
| constructor TProfilePlainTextMMap.Create(const aFileName: string); | |||||
| begin | |||||
| inherited; | |||||
| fDF:= TFastFileStream.Create(aFileName, fmCreate, fmShareExclusive); | |||||
| end; | |||||
| destructor TProfilePlainTextMMap.Destroy; | |||||
| begin | |||||
| FreeAndNil(fDF); | |||||
| inherited; | |||||
| end; | |||||
| procedure TProfilePlainTextMMap.WriteEnter(Thread: TThreadID; When: Int64; Func, Src: String; Line: Integer); | |||||
| var | |||||
| l: string; | |||||
| begin | |||||
| l:= hexStr(When, 16)+ ';'+hexStr(Thread, 4)+ ';'+Src+ ';'+IntToStr(Line)+';'+Func + #13#10; | |||||
| fDF.Write(l[1], Length(l)); | |||||
| end; | |||||
| procedure TProfilePlainTextMMap.WriteLeave(Thread: TThreadID; When: Int64); | |||||
| var | |||||
| l: string; | |||||
| begin | |||||
| l:= hexStr(When, 16)+ ';'+hexStr(Thread, 4)+ ';'#13#10; | |||||
| fDF.Write(l[1], Length(l)); | |||||
| end; | |||||
| {$ENDIF} | |||||