-
Notifications
You must be signed in to change notification settings - Fork 29
/
uDoc.pas
1398 lines (1283 loc) · 39.9 KB
/
uDoc.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit uDoc;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, uCacheGrind, ExtCtrls, ImgList, XPStyleActnCtrls,
ActnList, ActnMan, ToolWin, Menus, StdCtrls, uConfig, CommCtrl,
JvCombobox, JvExStdCtrls;
type
TListLBLSort = (lsFunction, lsSelf, lsCum, lsFileName, lsLine);
TListMergedSort = (msFunction, msAvgSelf, msAvgCum, msTotSelf, msTotCum, msCalls);
TMergedInstancesSort = (misIndex, misSelf, misCum, misCaller, misCallerFile);
TfDoc = class(TForm)
ilCacheGrind: TImageList;
il: TImageList;
am: TActionManager;
aViewPercent: TAction;
aViewMs: TAction;
mm: TMainMenu;
View1: TMenuItem;
Milliseconds1: TMenuItem;
Percentages1: TMenuItem;
aViewFullPath: TAction;
N1: TMenuItem;
FullPath1: TMenuItem;
aViewHideLibFuncs: TAction;
N2: TMenuItem;
HideLibraryFunctions1: TMenuItem;
aViewGoToUpOneLevel: TAction;
N3: TMenuItem;
UpOneLevel1: TMenuItem;
pmLBL: TPopupMenu;
aViewGoToOpen: TAction;
Open1: TMenuItem;
UpOneLevel2: TMenuItem;
aMergedInstancesGoTo: TAction;
pmMergedInstances: TPopupMenu;
GoTo1: TMenuItem;
pmTree: TPopupMenu;
aTreeOpenEditor: TAction;
Openineditor1: TMenuItem;
aTreeShowInfo: TAction;
Showadvancedinformation1: TMenuItem;
N4: TMenuItem;
aLBLShowInfo: TAction;
N5: TMenuItem;
Showadvancedinformation2: TMenuItem;
tb: TToolBar;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton6: TToolButton;
ToolButton3: TToolButton;
tv: TTreeView;
Splitter1: TSplitter;
Panel1: TPanel;
pcProfiler: TPageControl;
tsLBL: TTabSheet;
lvLBL: TListView;
tsMerged: TTabSheet;
Splitter2: TSplitter;
lvMerged: TListView;
lvMergedInstances: TListView;
pInfo: TPanel;
lInfoName: TLabel;
lInfo: TLabel;
lInfoFileName: TLabel;
iInfo: TImage;
Panel2: TPanel;
Label1: TLabel;
Image1: TImage;
aProfilerFind: TAction;
ToolButton9: TToolButton;
ToolButton10: TToolButton;
N6: TMenuItem;
Find1: TMenuItem;
aLBLOpenEditor: TAction;
N7: TMenuItem;
Openineditor2: TMenuItem;
aTreeGoToRoot: TAction;
GoToRoot1: TMenuItem;
N8: TMenuItem;
UpOneLevel3: TMenuItem;
GoToRoot2: TMenuItem;
GoToRoot3: TMenuItem;
pmMerged: TPopupMenu;
UpOneLevel4: TMenuItem;
GoToRoot4: TMenuItem;
aMergedInstancesOpenEditor: TAction;
aMergedInstancesShowInfo: TAction;
N9: TMenuItem;
N10: TMenuItem;
Showadvancedinformation3: TMenuItem;
Openineditor3: TMenuItem;
aLBLShowOverall: TAction;
aTreeShowOverall: TAction;
N11: TMenuItem;
N12: TMenuItem;
ShowOverall2: TMenuItem;
aTreeExpand: TAction;
aTreeCollapse: TAction;
aTreeExpandAll: TAction;
N13: TMenuItem;
Expand1: TMenuItem;
ExpandAll1: TMenuItem;
Collapse1: TMenuItem;
ShowOverall1: TMenuItem;
aViewHideFastFuncs: TAction;
HideFastFunctions1: TMenuItem;
ToolButton11: TToolButton;
ToolButton12: TToolButton;
cbRE: TCheckBox;
cbFind: TJvComboBox;
tFind: TTimer;
lFind: TLabel;
Panel3: TPanel;
lMerged: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure lvLBLData(Sender: TObject; Item: TListItem);
procedure tvChange(Sender: TObject; Node: TTreeNode);
procedure lvLBLDblClick(Sender: TObject);
procedure lvLBLKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure aViewPercentUpdate(Sender: TObject);
procedure aViewMsUpdate(Sender: TObject);
procedure aViewPercentExecute(Sender: TObject);
procedure aViewMsExecute(Sender: TObject);
procedure tvExpanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
procedure aViewFullPathExecute(Sender: TObject);
procedure aViewFullPathUpdate(Sender: TObject);
procedure lvMergedData(Sender: TObject; Item: TListItem);
procedure lvLBLColumnClick(Sender: TObject; Column: TListColumn);
procedure lvMergedColumnClick(Sender: TObject; Column: TListColumn);
procedure aViewHideLibFuncsUpdate(Sender: TObject);
procedure aViewHideLibFuncsExecute(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure aViewGoToUpOneLevelUpdate(Sender: TObject);
procedure aViewGoToUpOneLevelExecute(Sender: TObject);
procedure lvMergedInstancesData(Sender: TObject; Item: TListItem);
procedure aViewGoToOpenUpdate(Sender: TObject);
procedure aViewGoToOpenExecute(Sender: TObject);
procedure lvMergedInstancesColumnClick(Sender: TObject;
Column: TListColumn);
procedure aMergedInstancesGoToUpdate(Sender: TObject);
procedure aMergedInstancesGoToExecute(Sender: TObject);
procedure lvMergedInstancesDblClick(Sender: TObject);
procedure lvMergedInstancesKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure aTreeOpenEditorUpdate(Sender: TObject);
procedure aTreeOpenEditorExecute(Sender: TObject);
procedure tvKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure aTreeShowInfoUpdate(Sender: TObject);
procedure aLBLShowInfoUpdate(Sender: TObject);
procedure aLBLShowInfoExecute(Sender: TObject);
procedure aTreeShowInfoExecute(Sender: TObject);
procedure tvCollapsing(Sender: TObject; Node: TTreeNode;
var AllowCollapse: Boolean);
procedure lvMergedSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure aProfilerFindExecute(Sender: TObject);
procedure cbFindChange(Sender: TObject);
procedure aLBLOpenEditorUpdate(Sender: TObject);
procedure aLBLOpenEditorExecute(Sender: TObject);
procedure aTreeGoToRootExecute(Sender: TObject);
procedure aTreeGoToRootUpdate(Sender: TObject);
procedure aMergedInstancesOpenEditorUpdate(Sender: TObject);
procedure aMergedInstancesOpenEditorExecute(Sender: TObject);
procedure aMergedInstancesShowInfoUpdate(Sender: TObject);
procedure aMergedInstancesShowInfoExecute(Sender: TObject);
procedure aLBLShowOverallExecute(Sender: TObject);
procedure aLBLShowOverallUpdate(Sender: TObject);
procedure aTreeShowOverallExecute(Sender: TObject);
procedure aTreeShowOverallUpdate(Sender: TObject);
procedure aTreeExpandUpdate(Sender: TObject);
procedure aTreeExpandExecute(Sender: TObject);
procedure aTreeCollapseUpdate(Sender: TObject);
procedure aTreeCollapseExecute(Sender: TObject);
procedure aTreeExpandAllUpdate(Sender: TObject);
procedure aTreeExpandAllExecute(Sender: TObject);
procedure aViewHideFastFuncsUpdate(Sender: TObject);
procedure aViewHideFastFuncsExecute(Sender: TObject);
procedure tFindTimer(Sender: TObject);
procedure cbFindSelect(Sender: TObject);
procedure cbREClick(Sender: TObject);
private
FFileName: string;
FCacheGrind: TCacheGrind;
FListLBL, FListMerged, FMergedInstances: TList;
FTimeDisplay: TTimeDisplay;
FUseShortName: Boolean;
FListLBLSort: TListLBLSort;
FListMergedSort: TListMergedSort;
FHideLibFuncs: Boolean;
FMergedInstancesSort: TMergedInstancesSort;
FHideFastFuncs: Boolean;
{ Private declarations }
function AddToTree(Parent: TTreeNode; Inst: TProfInstance; Cascade: Boolean): TTreeNode;
procedure CacheGrindAnalyzeProgress(Sender: TObject; Position, Max: Integer; Status: string);
procedure CacheGrindLoadProgress(Sender: TObject; Position, Max: Integer; Status: string);
function GetImageIndex(Kind: TFuncKind): Integer;
procedure SetTimeDisplay(const Value: TTimeDisplay);
procedure SetUseShortName(const Value: Boolean);
procedure SetListLBLSort(const Value: TListLBLSort);
procedure SetListMergedSort(const Value: TListMergedSort);
procedure SetHideLibFuncs(const Value: Boolean);
function GetConfig: TConfig;
procedure SetMergedInstancesSort(const Value: TMergedInstancesSort);
procedure SetHideFastFuncs(const Value: Boolean);
public
{ Public declarations }
property CacheGrind: TCacheGrind read FCacheGrind;
property Config: TConfig read GetConfig;
property FileName: string read FFileName;
property HideFastFuncs: Boolean read FHideFastFuncs write SetHideFastFuncs;
property HideLibFuncs: Boolean read FHideLibFuncs write SetHideLibFuncs;
property ListLBLSort: TListLBLSort read FListLBLSort write SetListLBLSort;
property ListMergedSort: TListMergedSort read FListMergedSort write SetListMergedSort;
property MergedInstancesSort: TMergedInstancesSort read FMergedInstancesSort write SetMergedInstancesSort;
property TimeDisplay: TTimeDisplay read FTimeDisplay write SetTimeDisplay;
property UseShortName: Boolean read FUseShortName write SetUseShortName;
procedure ClearListLBL;
procedure ClearListMerged;
procedure ClearListMergedInstances;
procedure ClearLists;
procedure ClearTree;
function FormatMs(Ms: TProfTime): string;
function FormatPercent(Percent: Double): string;
procedure Open(AFileName: string);
procedure RefreshTree;
procedure RefreshListLBL;
procedure RefreshListMerged;
procedure RefreshListMergedInstances;
procedure RefreshLists;
procedure Reload;
procedure RepaintLists;
procedure SelectLBLInstance(AInst: TProfInstance);
procedure SelectListItem(LV: TListView; AIndex: Integer);
procedure SelectMergedFunc(AFunc: TProfFunc);
procedure SelectTreeInstance(AInst: TProfInstance);
procedure SelectTreeNode(Node: TTreeNode);
procedure ShowInfo(AInst: TProfInstance);
procedure ShowMerged(AFunc: TProfFunc);
procedure SyncTree;
procedure SyncTreeNode(ANode: TTreeNode);
procedure UpdateInfo;
end;
implementation
uses uWait, uMain, RegExpr;
{$R *.dfm}
function CompareDouble(A, B: Double): Integer;
begin
if A > B then
Result := 1
else if B > A then
Result := -1
else
Result := 0;
end;
function LBLSort(A, B: Pointer): Integer;
var
Form: TfDoc;
IA, IB: TProfInstance;
begin
Result := 0;
IA := TProfInstance(A);
IB := TProfInstance(B);
Form := IA.CacheGrind.Owner as TfDoc;
case Form.ListLBLSort of
lsFunction: Result := CompareText(IA.Name, IB.Name);
lsSelf: Result := -CompareDouble(IA.SelfTime, IB.SelfTime);
lsCum: Result := -CompareDouble(IA.CumTime, IB.CumTime);
lsFileName: Result := CompareText(IA.FileName, IB.FileName);
end;
if Result = 0 then
Result := CompareText(IA.Name, IB.Name);
end;
function MergedSort(A, B: Pointer): Integer;
var
Form: TfDoc;
FA, FB: TProfFunc;
begin
Result := 0;
FA := TProfFunc(A);
FB := TProfFunc(B);
Form := FA.CacheGrind.Owner as TfDoc;
case Form.ListMergedSort of
msFunction: Result := CompareText(FA.Name, FB.Name);
msAvgSelf: Result := -CompareDouble(FA.AvgSelfTime, FB.AvgSelfTime);
msAvgCum: Result := -CompareDouble(FA.AvgCumTime, FB.AvgCumTime);
msTotSelf: Result := -CompareDouble(FA.TotSelfTime, FB.TotSelfTime);
msTotCum: Result := -CompareDouble(FA.TotCumTime, FB.TotCumTime);
msCalls: Result := FB.InstanceCount - FA.InstanceCount;
end;
if Result = 0 then
Result := CompareText(FA.Name, FB.Name);
end;
function MergedInstancesSort(A, B: Pointer): Integer;
var
Form: TfDoc;
IA, IB: TProfInstance;
begin
Result := 0;
IA := TProfInstance(A);
IB := TProfInstance(B);
Form := IA.CacheGrind.Owner as TfDoc;
case Form.MergedInstancesSort of
misIndex: Result := IA.Index - IB.Index;
misSelf: Result := -CompareDouble(IA.SelfTime, IB.SelfTime);
misCum: Result := -CompareDouble(IA.CumTime, IB.CumTime);
misCaller: Result := CompareText(IA.Caller.Name, IB.Caller.Name);
misCallerFile: begin
Result := CompareText(IA.Caller.FileName, IB.Caller.FileName);
if Result = 0 then
Result := IA.Line - IB.Line;
end;
end;
if Result = 0 then
Result := IA.Index - IB.Index;
end;
{ TfDoc }
procedure TfDoc.Open(AFileName: string);
begin
fWait := TfWait.Create(Self);
try
fWait.Show;
// clear stuff
ClearLists;
ClearTree;
// parse
CacheGrind.Load(AFileName);
// add this to MRU
Config.AddMRU(AFileName, CacheGrind.Cmd);
// ok
FFileName := AFileName;
Caption := CacheGrind.Cmd + ' (' + ExtractFileName(FileName) + ')';
// Analyzing
CacheGrind.ReAnalyze;
// update
fWait.lWait.Caption := 'Updating tree view...';
fWait.Update;
RefreshTree;
RefreshLists;
UpdateInfo;
finally
fWait.Free;
end;
end;
procedure TfDoc.FormCreate(Sender: TObject);
begin
FCacheGrind := TCacheGrind.Create(Self);
FCacheGrind.OnAnalyzeProgress := CacheGrindAnalyzeProgress;
FCacheGrind.OnLoadProgress := CacheGrindLoadProgress;
FListLBL := TList.Create;
FListMerged := TList.Create;
FMergedInstances := TList.Create;
// defaults
FTimeDisplay := Config.TimeDisplay;
FUseShortName := not Config.ShowFullPath;
FHideLibFuncs := Config.HideLibFuncs;
FListLBLSort := lsCum;
FListMergedSort := msTotCum;
// visual stuff
pcProfiler.ActivePageIndex := 0;
end;
procedure TfDoc.FormDestroy(Sender: TObject);
begin
ClearLists;
FreeAndNil(FListLBL);
FreeAndNil(FMergedInstances);
FreeAndNil(FListMerged);
FreeAndNil(FCacheGrind);
end;
procedure TfDoc.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TfDoc.ClearTree;
begin
tv.Items.Clear;
end;
procedure TfDoc.RefreshTree;
var
RootNode: TTreeNode;
begin
ClearTree;
RootNode := AddToTree(nil, CacheGrind.Root, false);
tv.Selected := RootNode;
RootNode.Expand(False);
end;
function TfDoc.AddToTree(Parent: TTreeNode; Inst: TProfInstance; Cascade: Boolean): TTreeNode;
var
Node: TTreeNode;
I: Integer;
S: string;
begin
tv.Items.BeginUpdate;
try
if UseShortName then
S := Inst.ShortName
else
S := Inst.Name;
Node := tv.Items.AddChild(Parent, S);
Node.Data := Inst;
Node.ImageIndex := GetImageIndex(Inst.Kind);
Node.SelectedIndex := Node.ImageIndex;
Node.HasChildren := Inst.CallCount > 0;
// link this instance to the tree node so we won't have to perform
// searches later
Inst.Data := Node;
if Cascade then begin
for I := 0 to Inst.CallCount - 1 do
AddToTree(Node, Inst.Calls[I], True);
end;
Result := Node;
finally
tv.Items.EndUpdate;
end;
end;
procedure TfDoc.ClearListLBL;
begin
lvLBL.Items.Count := 0;
FListLBL.Clear;
lvLBL.Invalidate;
end;
procedure TfDoc.lvLBLData(Sender: TObject; Item: TListItem);
var
Inst: TProfInstance;
S: string;
begin
if (Item.Index >= 0) and (Item.Index < FListLBL.Count) then begin
Inst := TProfInstance(FListLBL[Item.Index]);
Item.Data := Inst;
if UseShortName then
Item.Caption := Inst.ShortName
else
Item.Caption := Inst.Name;
case TimeDisplay of
tdMs: begin
Item.SubItems.Add(FormatMs(Inst.SelfTime));
Item.SubItems.Add(FormatMs(Inst.CumTime));
end;
tdPercent: begin
Item.SubItems.Add(FormatPercent(Inst.SelfPercent));
Item.SubItems.Add(FormatPercent(Inst.CumPercent));
end;
else
raise Exception.Create('Unknown time display option.');
end;
if UseShortName then
S := Inst.ShortFileName
else
S := Inst.FileName;
Item.SubItems.Add(S);
if UseShortName then
S := Inst.Caller.ShortFileName
else
S := Inst.Caller.FileName;
// Inst.Line is the line number of the *CALLING* function
if Inst.Line > 0 then
S := S + ' (' + Format ('%.0n', [Inst.Line * 1.0]) + ')';
Item.SubItems.Add(S);
// set image
Item.ImageIndex := GetImageIndex(Inst.Kind);
end;
end;
procedure TfDoc.tvChange(Sender: TObject; Node: TTreeNode);
begin
RefreshLists;
UpdateInfo;
end;
function TfDoc.GetImageIndex(Kind: TFuncKind): Integer;
begin
case Kind of
fkRoot: begin
if CacheGrind.SummaryExists then
Result := 1
else
Result := 0;
end;
fkSection: Result := 2;
fkFunc: Result := 3;
fkConstructor: Result := 4;
fkDestructor: Result := 5;
fkPublicMethod: Result := 6;
fkPrivateMethod: Result := 7;
fkStaticMethod: Result := 8;
fkInclude: Result := 9;
fkLibFunc: Result := 10;
else
Result := 0;
end;
end;
procedure TfDoc.lvLBLDblClick(Sender: TObject);
begin
aViewGoToOpen.Execute;
end;
procedure TfDoc.lvLBLKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Shift = [] then begin
if Key = VK_RETURN then
aViewGoToOpen.Execute
else if Key = VK_BACK then
aViewGoToUpOneLevel.Execute;
end else if (Shift = [ssAlt]) and (Key = VK_RETURN) then
aLBLShowInfo.Execute;
end;
procedure TfDoc.SetTimeDisplay(const Value: TTimeDisplay);
begin
FTimeDisplay := Value;
RepaintLists;
end;
procedure TfDoc.aViewPercentUpdate(Sender: TObject);
begin
aViewPercent.Checked := TimeDisplay = tdPercent;
end;
procedure TfDoc.aViewMsUpdate(Sender: TObject);
begin
aViewMs.Checked := TimeDisplay = tdMs;
end;
procedure TfDoc.aViewPercentExecute(Sender: TObject);
begin
TimeDisplay := tdPercent;
end;
procedure TfDoc.aViewMsExecute(Sender: TObject);
begin
TimeDisplay := tdMs;
end;
procedure TfDoc.SetUseShortName(const Value: Boolean);
begin
FUseShortName := Value;
SyncTree;
RepaintLists;
end;
(**
* Synchronizes the tree with underlying data.
*
* One of the cases when this is called is after a change to
* {@link UseShortName} property. It will be unwise to refresh
* the whole tree, so we just rename the nodes' captions accordingly.
*)
procedure TfDoc.SyncTree;
var
I: Integer;
begin
for I := 0 to tv.Items.Count - 1 do
SyncTreeNode(tv.Items[I]);
end;
procedure TfDoc.SyncTreeNode(ANode: TTreeNode);
var
Inst: TProfInstance;
I: Integer;
begin
Inst := TProfInstance(ANode.Data);
if UseShortName then
ANode.Text := Inst.ShortName
else
ANode.Text := Inst.Name;
for I := 0 to ANode.Count - 1 do
SyncTreeNode(ANode[I]);
end;
procedure TfDoc.CacheGrindAnalyzeProgress(Sender: TObject; Position,
Max: Integer; Status: string);
begin
fWait.lWait.Caption := Status;
fWait.pbWait.Position := Position;
fWait.pbWait.Max := Max;
fWait.Update;
end;
procedure TfDoc.CacheGrindLoadProgress(Sender: TObject; Position,
Max: Integer; Status: string);
begin
fWait.lWait.Caption := Status;
fWait.pbWait.Position := Position;
fWait.pbWait.Max := Max;
fWait.Update;
end;
procedure TfDoc.tvExpanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
var
Inst: TProfInstance;
I: Integer;
begin
if Node.HasChildren and (Node.Count = 0) then begin
tv.Items.BeginUpdate;
try
// we do need to expand this
Inst := TProfInstance(Node.Data);
for I := 0 to Inst.CallCount - 1 do
AddToTree(Node, Inst.Calls[I], False);
finally
tv.Items.EndUpdate;
end;
end;
end;
procedure TfDoc.aViewFullPathExecute(Sender: TObject);
begin
UseShortName := not UseShortName;
end;
procedure TfDoc.aViewFullPathUpdate(Sender: TObject);
begin
aViewFullPath.Checked := not UseShortName;
end;
procedure TfDoc.ClearLists;
begin
ClearListLBL;
ClearListMerged;
end;
procedure TfDoc.ClearListMerged;
begin
lvMerged.Items.Count := 0;
FListMerged.Clear;
lvMerged.Invalidate;
end;
procedure TfDoc.RefreshListLBL;
var
Parent, Inst, LastInst: TProfInstance;
I: Integer;
Pass: Boolean;
begin
LastInst := nil;
if lvLBL.Selected <> nil then
LastInst := TProfInstance(FListLBL[lvLBL.ItemIndex]);
ClearListLBL;
if tv.Selected <> nil then begin
Parent := TProfInstance(tv.Selected.Data);
for I := 0 to Parent.CallCount - 1 do begin
Inst := Parent.Calls[I];
Pass := True;
if HideLibFuncs and (Inst.Kind = fkLibFunc) then
Pass := False
else if (HideFastFuncs) and (Inst.CumTime < Config.FastThreshold) then
Pass := False;
if Pass then
FListLBL.Add(Inst);
end;
if ListLBLSort <> lsLine then
FListLBL.Sort(LBLSort);
lvLBL.Items.Count := FListLBL.Count;
SelectListItem(lvLBL, 0);
SelectLBLInstance(LastInst);
end;
lvLBL.Invalidate;
end;
procedure TfDoc.RefreshListMerged;
var
Parent: TProfInstance;
Func, LastFunc: TProfFunc;
I: Integer;
Q: string;
Delete: Boolean;
RE: TRegExpr;
SumSelf: TProfTime;
SumSelfPercent: Double;
SumCalls: Integer;
begin
lFind.Caption := '';
LastFunc := nil;
if lvMerged.ItemIndex >= 0 then
LastFunc := TProfFunc(FListMerged[lvMerged.ItemIndex]);
ClearListMerged;
SumSelf := 0;
SumSelfPercent := 0;
SumCalls := 0;
if tv.Selected <> nil then begin
Parent := TProfInstance(tv.Selected.Data);
Parent.GetMerged(FListMerged);
// filter
RE := TRegExpr.Create;
try
if cbRE.Checked then begin
RE.ModifierI := True;
Q := cbFind.Text;
if Q <> '' then begin
try
RE.Expression := Q;
RE.Compile;
except
Q := '';
lFind.Caption := 'Pattern invalid';
lFind.Visible := True;
end;
end;
end else
Q := Trim(LowerCase(cbFind.Text));
for I := FListMerged.Count - 1 downto 0 do begin
Func := TProfFunc(FListMerged[I]);
// filtering
Delete := False;
// filter for hide funcs
if HideLibFuncs and(Func.Kind = fkLibFunc) then
Delete := True
// hide fast funcs
else if HideFastFuncs and (Func.TotCumTime < Config.FastThreshold) then
Delete := True
// find
else if Q <> '' then begin
if cbRE.Checked then begin
if not RE.Exec(Func.Name) then
Delete := True;
end else begin
if (Pos(Q, LowerCase(Func.Name)) <= 0) then
Delete := True;
end;
end;
if Delete then begin
FListMerged.Delete(I);
end else begin
// calculate sum
SumSelf := SumSelf + Func.TotSelfTime;
SumSelfPercent := SumSelfPercent + Func.TotSelfPercent;
SumCalls := SumCalls + Func.InstanceCount;
end;
end;
finally
FreeAndNil(RE);
end;
// ok, continue
FListMerged.Sort(MergedSort);
lvMerged.Items.Count := FListMerged.Count;
// select last function if available
SelectListItem(lvMerged, 0);
SelectMergedFunc(LastFunc);
end;
lvMerged.Invalidate;
lMerged.Caption :=
' Sum of total self time: '+ FormatMs(SumSelf) +' ('+ FormatPercent(SumSelfPercent) + ')'
+ ' Sum of calls: '+ Format('%.0n', [SumCalls * 1.0]);
end;
procedure TfDoc.RefreshLists;
begin
RefreshListLBL;
RefreshListMerged;
RefreshListMergedInstances;
end;
procedure TfDoc.lvMergedData(Sender: TObject; Item: TListItem);
var
Func: TProfFunc;
begin
if (Item.Index >= 0) and (Item.Index < FListMerged.Count) then begin
Func := TProfFunc(FListMerged[Item.Index]);
Item.Data := Func;
if UseShortName then
Item.Caption := Func.ShortName
else
Item.Caption := Func.Name;
case TimeDisplay of
tdMs: begin
Item.SubItems.Add(FormatMs(Func.AvgSelfTime));
Item.SubItems.Add(FormatMs(Func.AvgCumTime));
Item.SubItems.Add(FormatMs(Func.TotSelfTime));
Item.SubItems.Add(FormatMs(Func.TotCumTime));
end;
tdPercent: begin
Item.SubItems.Add(FormatPercent(Func.AvgSelfPercent));
Item.SubItems.Add(FormatPercent(Func.AvgCumPercent));
Item.SubItems.Add(FormatPercent(Func.TotSelfPercent));
Item.SubItems.Add(FormatPercent(Func.TotCumPercent));
end;
else
raise Exception.Create('Unknown time display option.');
end;
Item.SubItems.Add(Format('%.0n', [Func.InstanceCount * 1.0]));
// set image
Item.ImageIndex := GetImageIndex(Func.Kind);
end;
end;
procedure TfDoc.RepaintLists;
begin
lvLBL.Invalidate;
lvMerged.Invalidate;
end;
function TfDoc.FormatMs(Ms: TProfTime): string;
begin
if Ms < 0.1 then
Result := '-'
else if Ms < 10 then
Result := Format('%.1n', [Ms]) + 'ms'
else
Result := Format('%.0n', [Ms]) + 'ms';
end;
function TfDoc.FormatPercent(Percent: Double): string;
begin
if Percent < 0.01 then
Result := '-'
else
Result := Format('%.2f%%', [Percent]);
end;
procedure TfDoc.SetListLBLSort(const Value: TListLBLSort);
begin
FListLBLSort := Value;
RefreshListLBL;
end;
procedure TfDoc.SetListMergedSort(const Value: TListMergedSort);
begin
FListMergedSort := Value;
RefreshListMerged;
end;
procedure TfDoc.lvLBLColumnClick(Sender: TObject; Column: TListColumn);
begin
ListLBLSort := TListLBLSort(Column.Index);
end;
procedure TfDoc.lvMergedColumnClick(Sender: TObject; Column: TListColumn);
begin
ListMergedSort := TListMergedSort(Column.Index);
end;
procedure TfDoc.UpdateInfo;
var
Inst: TProfInstance;
begin
if tv.Selected <> nil then begin
Inst := TProfInstance(tv.Selected.Data);
lInfoName.Caption := Inst.Name;
lInfoFileName.Caption := 'File: '+ Inst.FileName;
lInfo.Caption := 'Self time: '+ FormatMs(Inst.SelfTime) + ' (' + FormatPercent(Inst.SelfPercent) + ')'
+ ' Cumulative time: '+ FormatMs(Inst.CumTime) + ' (' + FormatPercent(Inst.CumPercent) + ')';
iInfo.Picture.Assign(nil);
ilCacheGrind.GetBitmap(GetImageIndex(Inst.Kind), iInfo.Picture.Bitmap);
pInfo.Visible := True;
end else begin
pInfo.Visible := False;
end;
end;
procedure TfDoc.Reload;
begin
Open(FileName);
end;
procedure TfDoc.SetHideLibFuncs(const Value: Boolean);
begin
FHideLibFuncs := Value;
RefreshLists;
end;
procedure TfDoc.aViewHideLibFuncsUpdate(Sender: TObject);
begin
aViewHideLibFuncs.Checked := HideLibFuncs;
end;
procedure TfDoc.aViewHideLibFuncsExecute(Sender: TObject);
begin
HideLibFuncs := not HideLibFuncs;
end;
procedure TfDoc.ToolButton1Click(Sender: TObject);
begin
case TimeDisplay of
tdMs: TimeDisplay := tdPercent;
tdPercent: TimeDisplay := tdMs;
else
raise Exception.Create('Unrecognize time display option.');
end;
end;
function TfDoc.GetConfig: TConfig;
begin
Result := fMain.Config;
end;
procedure TfDoc.aViewGoToUpOneLevelUpdate(Sender: TObject);
begin
aViewGoToUpOneLevel.Enabled := (tv.Selected <> nil) and (tv.Selected.Parent <> nil);
end;
procedure TfDoc.aViewGoToUpOneLevelExecute(Sender: TObject);
var
LastInst: TProfInstance;
begin
if (tv.Selected <> nil) and (tv.Selected.Parent <> nil) then begin
LastInst := TProfInstance(tv.Selected.Data);
SelectTreeNode(tv.Selected.Parent);
RefreshListLBL;
SelectLBLInstance(LastInst);
end;
end;
procedure TfDoc.RefreshListMergedInstances;
var
Func: TProfFunc;
I: Integer;
begin
ClearListMergedInstances;
if lvMerged.Selected <> nil then begin
Func := TProfFunc(FListMerged[lvMerged.ItemIndex]);
for I := 0 to Func.InstanceCount - 1 do
FMergedInstances.Add(Func.Instances[I]);
if MergedInstancesSort <> misIndex then
FMergedInstances.Sort(uDoc.MergedInstancesSort);
lvMergedInstances.Items.Count := FMergedInstances.Count;
SelectListItem(lvMergedInstances, 0);
end;
lvMergedInstances.Invalidate;
end;
procedure TfDoc.ClearListMergedInstances;
begin
lvMergedInstances.Items.Count := 0;
FMergedInstances.Clear;
lvMergedInstances.Invalidate;
end;
procedure TfDoc.lvMergedInstancesData(Sender: TObject; Item: TListItem);
var
Inst, Cur: TProfInstance;
S: string;
begin
if (Item.Index >= 0) and (Item.Index < FMergedInstances.Count) then begin
Inst := TProfInstance(FMergedInstances[Item.Index]);
Item.Data := Inst;
Item.Caption := Format('%.0n', [(Inst.Index + 1) * 1.0]);
// set image
Item.ImageIndex := GetImageIndex(Inst.Kind);
case TimeDisplay of
tdMs: begin
Item.SubItems.Add(FormatMs(Inst.SelfTime));
Item.SubItems.Add(FormatMs(Inst.CumTime));
end;
tdPercent: begin
Item.SubItems.Add(FormatPercent(Inst.SelfPercent));
Item.SubItems.Add(FormatPercent(Inst.CumPercent));
end;
else
raise Exception.Create('Unknown time display option.');
end;
if UseShortName then
Item.SubItems.Add(Inst.Caller.ShortName)
else
Item.SubItems.Add(Inst.Caller.Name);
if UseShortName then
S := Inst.Caller.ShortFileName
else
S := Inst.Caller.FileName;
// Inst.Line is the line number of the *CALLING* function
if Inst.Line > 0 then
S := S + ' (' + Format ('%.0n', [Inst.Line * 1.0]) + ')';
Item.SubItems.Add(S);
// stack trace euy!!! :-P
S := '';
Cur := Inst.Caller;
while Cur <> nil do begin