forked from fantaisie-software/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfiler.pb
1621 lines (1297 loc) · 62.6 KB
/
Profiler.pb
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
; --------------------------------------------------------------------------------------------
; Copyright (c) Fantaisie Software. All rights reserved.
; Dual licensed under the GPL and Fantaisie Software licenses.
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
; --------------------------------------------------------------------------------------------
#Profiler_Colors = 18 ; number of predefined colors
#ContainerBorder = 4 ; number of pixels to calc inner size of a container with double border
CompilerIf #CompileLinux
#Profiler_ScrollbarWidth = 18
CompilerElse
#Profiler_ScrollbarWidth = 15
CompilerEndIf
; OSX only supports up to 9 procedure args, so we put some of the static data
; into a structure and pass by reference
Structure ProfilerDrawing
x.l ; the offset/size of the display area inside the drawing area
y.l
w.l
h.l
linestart.l ; offset/size inside the profiler data to draw
lines.l
countstart.l
counts.l
EndStructure
Global Profiler_Arrow, Profiler_Select, Profiler_Cross, Profiler_Zoomin, Profiler_Zoomout, Profiler_Zoomall
Global Profiler_CurrentLine ; holds the line under cursor when the popup menu is displayed (0-based)
; calculate all the image positions in the ProfilerDrawing structure
; as this calculation is needed often.
;
Procedure Profiler_CalculateViewport(*Debugger.DebuggerData, *Area.ProfilerDrawing)
w = DesktopScaledX(GadgetWidth(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas]))
h = DesktopScaledY(GadgetHeight(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas]))
*Area\x = 16+*Debugger\ProfilerNumberLength*7
*Area\y = 11
*Area\w = w-27-*Debugger\ProfilerNumberLength*7
*Area\h = h-38
; prevent too small sizing and division by zero if w/h = 0
If *Area\w < 20: *Area\w = 20: EndIf
If *Area\h < 20: *Area\h = 20: EndIf
EndProcedure
Procedure Profiler_ClipToViewport(*x.INTEGER, *y.INTEGER, *Area.ProfilerDrawing)
If *x\i < *Area\x
*x\i = *Area\x
ElseIf *x\i >= *Area\x + *Area\w
*x\i = *Area\x + *Area\w - 1
EndIf
If *y\i < *Area\y
*y\i = *Area\y
ElseIf *y\i >= *Area\y + *Area\h
*y\i = *Area\y + *Area\h - 1
EndIf
EndProcedure
; returns an equal or higher step value that fvalue
; that is a nice round number for the coordinate labeling
Procedure Profiler_StepValue(fvalue.f)
mult = 1
While fvalue > 100
mult * 100
fvalue / 100
Wend
If fvalue <= 1: lvalue = 1 * mult
ElseIf fvalue <= 2: lvalue = 2 * mult
ElseIf fvalue <= 5: lvalue = 5 * mult
ElseIf fvalue <= 10: lvalue = 10 * mult
ElseIf fvalue <= 20: lvalue = 20 * mult
ElseIf fvalue <= 25: lvalue = 25 * mult
ElseIf fvalue <= 50: lvalue = 50 * mult
Else: lvalue = 100 * mult
EndIf
ProcedureReturn lvalue
EndProcedure
; Since the size of the default drawing font differs quite a lot
; between the OS, we use are own routine to draw numbers in a fixed
; 7*9 pixel font
;
Procedure Profiler_DrawNumber(x, y, Number, Color, isBold = 0, length = -1)
If length = -1
length = Len(Str(Number))
EndIf
For length = length-1 To 0 Step -1
*Pointer.BYTE = ?Profiler_Numbers + (Number % 10)*9
;DisableDebugger ; no debugger warning for plot outside of area
For dy = 0 To 8
For dx = 0 To 6
If *Pointer\b & (1 << (6-dx))
px = x + length*7 + dx
py = y+dy
; In 4.40+, this must be clipped as images are direct memory routines now
; Clip 1px more in the x direction for the bold pixel
;
If px >= 0 And py >= 0 And px < OutputWidth()-1 And py < OutputHeight()
Plot(px, py, color)
If isBold
Plot(px+1, py, color) ; simply place a dot one pixel to the right
EndIf
EndIf
EndIf
Next dx
*Pointer + 1
Next dy
;EnableDebugger
Number / 10
If Number = 0
Break
EndIf
Next length
EndProcedure
Procedure Profiler_DrawFile(*Debugger.DebuggerData, *Area.ProfilerDrawing, index, color)
*files.Debugger_ProfilerList = *Debugger\ProfilerFiles
maxlines = *files\file[index]\Size
*lines.Local_Array = *Debugger\ProfilerData + *files\file[index]\Offset * SizeOf(LONG)
line = *Area\lineStart
If *Area\h >= *Area\lines ; lines must be drawn thicker than one pixel
height = Round(*Debugger\ProfilerRatioY, 1)
While line < *Area\lineStart + *Area\lines - 1 And line < maxlines
length = (*lines\l[line] - *Area\countStart) * *Debugger\ProfilerRatioX
If length > 0 ; if length < 0, the count is outside the viewport
If length > *Area\w: length = *Area\w: EndIf
Box(*Area\x, *Area\y + (line-*Area\lineStart)* *Debugger\ProfilerRatioY, length, height, color)
If *Debugger\ProfilerRatioY >= 3
; separate 2 line entries if there is enough space for this (looks better)
Line(*Area\x, *Area\y + (line-*Area\lineStart)* *Debugger\ProfilerRatioY, *Area\w, 1, $FFFFFF)
EndIf
EndIf
line + 1
Wend
; draw the last line (may need clipping)
If line < *Area\lineStart + *Area\lines And line < maxlines
length = (*lines\l[line] - *Area\countStart) * *Debugger\ProfilerRatioX
If length > 0 ; if length < 0, the count is outside the viewport
If length > *Area\w: length = *Area\w: EndIf
If (line-*Area\lineStart)* *Debugger\ProfilerRatioY + height > *Area\h
height = *Area\h - (line-*Area\lineStart)* *Debugger\ProfilerRatioY
EndIf
Box(*Area\x, *Area\y + (line-*Area\lineStart)* *Debugger\ProfilerRatioY, length, height, color)
If *Debugger\ProfilerRatioY >= 3
; separate 2 line entries if there is enough space for this (looks better)
Line(*Area\x, *Area\y + (line-*Area\lineStart)* *Debugger\ProfilerRatioY, *Area\w, 1, $FFFFFF)
EndIf
EndIf
EndIf
Else ; multiple lines are combined on one pixel
thick.d = 0
lineDraw = 0
max = 0
While line < *Area\lineStart + *Area\lines And line < maxlines
thick + *Debugger\ProfilerRatioY
max = Max(max, *lines\l[line])
If thick >= 1
length = (max - *Area\countStart) * *Debugger\ProfilerRatioX
If length > 0 ; if length < 0, the count is outside the viewport
If length > *Area\w: length = *Area\w: EndIf
Line(*Area\x, *Area\y + lineDraw, length, 1, color)
EndIf
max = 0
thick - 1
lineDraw + 1
EndIf
line + 1
Wend
If thick > 0
; draw last line
length = (max - *Area\countStart) * *Debugger\ProfilerRatioX
If length > 0 ; if length < 0, the count is outside the viewport
If length > *Area\w: length = *Area\w: EndIf
Line(*Area\x, *Area\y + lineDraw, length, 1, color)
EndIf
EndIf
EndIf
; DEBUGGING
; h = TextHeight("Gg")
; DrawText(*Area\x, *Area\y, "Range: "+Str(*Area\x)+", "+Str(*Area\y)+", "+Str(*Area\w)+", "+Str(*Area\h), 0, $FFFFFF)
; DrawText(*Area\x, *Area\y+h, "Lines: "+Str(*Area\lineStart)+", "+Str(*Area\lines), 0, $FFFFFF)
; DrawText(*Area\x, *Area\y+h*2, "Counts: "+Str(*Area\countStart)+", "+Str(*Area\counts), 0, $FFFFFF)
; DrawText(*Area\x, *Area\y+h*3, "RatioX: "+StrF(*Debugger\ProfilerRatioX), 0, $FFFFFF)
; DrawText(*Area\x, *Area\y+h*4, "RatioY: "+StrF(*Debugger\ProfilerRatioY), 0, $FFFFFF)
EndProcedure
Procedure Profiler_DrawAll(*Debugger.DebuggerData)
w = DesktopScaledX(GadgetWidth(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas]))
h = DesktopScaledY(GadgetHeight(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas]))
If StartDrawing(CanvasOutput(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas]))
Box(0, 0, w, h, $FFFFFF)
If *Debugger\ProfilerFiles And *Debugger\ProfilerData
*files.Debugger_ProfilerList = *Debugger\ProfilerFiles
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
DrawingMode(#PB_2DDrawing_Outlined)
Box(Area\x-1, Area\y-1, Area\w+2, Area\h+2, $000000)
Area\lineStart = GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY])
Area\countStart = GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX])
Area\lines = Area\h / *Debugger\ProfilerRatioY
Area\counts = Area\w / *Debugger\ProfilerRatioX
DrawingMode(#PB_2DDrawing_Default)
; draw the data
;
If *Debugger\NbIncludedFiles = 0
Profiler_DrawFile(*Debugger, @Area, 0, $FF0000)
Else
Gadget = *Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files]
; go backwards, so the top file entry draws on top as well
For i = *Debugger\NbIncludedFiles To 0 Step -1
If GetGadgetItemState(Gadget, i) & (#PB_ListIcon_Checked|#PB_ListIcon_Selected)
index = GetGadgetItemData(Gadget, i) ; get the real index
Profiler_DrawFile(*Debugger, @Area, index, *files\file[index]\Color)
EndIf
Next i
EndIf
; draw line numbers
;
maxline = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_Maximum)
stepvalue = Profiler_StepValue(20 / *Debugger\ProfilerRatioY) ; min 20 pixels between two entries
first = Int(Round((Area\lineStart+1) / stepvalue, 1) * stepvalue)
offset = Area\y + Int((first-Area\lineStart-1) * *Debugger\ProfilerRatioY + *Debugger\ProfilerRatioY/2)
i = 0
x = Area\x-4
y = 0
While y <= Area\y+Area\h And (first + i*stepvalue -1) <= maxline
y = offset + i * stepvalue * *Debugger\ProfilerRatioY
If y >= Area\y And y <= Area\y+Area\h
Line(x, y, 3, 1, $000000)
Profiler_DrawNumber(10, y - 4, (first + i*stepvalue), $000000, 0, *Debugger\ProfilerNumberLength)
EndIf
i + 1
Wend
; draw count numbers
;
maxcount = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_Maximum)
stepvalue = Profiler_StepValue((Len(Str(maxcount))*7+10) / *Debugger\ProfilerRatioX) ; min difference between 2 labels
If Area\countStart = 0
first = 0
Else
first = Int(Round(Area\countStart / stepvalue, 1) * stepvalue)
EndIf
offset = Area\x + Int((first-Area\countStart) * *Debugger\ProfilerRatioX)
i = 0
x = 0
y = Area\y+Area\h+1
While x <= Area\x+Area\w And (first + i*stepvalue) <= maxcount
x = offset + i * stepvalue * *Debugger\ProfilerRatioX
If x >= Area\x And x <= Area\x+Area\w
count = first + i*stepvalue
Line(x, y, 1, 3, $000000)
Profiler_DrawNumber(x - (Len(Str(count))*7 - 1)/2, y + 7, count, $000000)
EndIf
i + 1
Wend
Else
DrawText(10, 10, Language("Debugger","ProfilerNoData"), $000000, $FFFFFF)
EndIf
StopDrawing()
EndIf
EndProcedure
; Procedure Profiler_DrawPreview(*Debugger.DebuggerData)
;
; fullw = GadgetWidth(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Preview])
; fullh = GadgetHeight(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Preview])
;
; ; We re-create the image if the size changed (quicker than a resize, which does the same but additional blitting)
; ;
; If *Debugger\ProfilerPreview
; If fullw <> ImageWidth(*Debugger\ProfilerPreview) Or fullh <> ImageHeight(*Debugger\ProfilerPreview)
; FreeImage(*Debugger\ProfilerPreview)
; *Debugger\ProfilerPreview = 0
; EndIf
; EndIf
;
; If *Debugger\ProfilerPreview = 0 And fullw > 0 And fullh > 0
; *Debugger\ProfilerPreview = CreateImage(#PB_Any, fullw, fullh)
; EndIf
;
; If *Debugger\ProfilerPreview
; If StartDrawing(ImageOutput(*Debugger\ProfilerPreview))
; Box(0, 0, fullw, fullh, $FFFFFF)
;
; w = fullw - 4
; h = fullh - 4
;
; If *Debugger\ProfilerFiles And *Debugger\ProfilerData And w > 0 And h > 0
; *files.Debugger_ProfilerList = *Debugger\ProfilerFiles
; *lines.Local_Array = *Debugger\ProfilerData
;
; maxlines = *files\file[*Debugger\NbIncludedFiles]\Offset + *files\file[*Debugger\NbIncludedFiles]\Size
; maxcount = 1
; For i = 0 To maxlines-1
; maxcount = Max(maxcount, *lines\l[i])
; Next i
;
; RatioX.d = (w / maxcount) * 0.997
; RatioY.d = (h / maxlines) * 0.997
;
; If RatioY >= 1 ; lines must be drawn thicker than one pixel
;
; height = Round(RatioY, 1)
; For file = 0 To *Debugger\NbIncludedFiles
; color = *files\file[file]\Color
;
; For line = 0 To *files\file[file]\Size
; real = *files\file[file]\Offset + line
; length = *lines\l[real] * RatioX
;
; If length > 0
; Box(2, 2 + real * RatioY, length, height, color)
; If RatioY >= 3
; ; separate 2 line entries if there is enough space for this (looks better)
; Line(2, 2 + real * RatioY, w, 1, $FFFFFF)
; EndIf
; EndIf
;
; Next line
;
; Next file
;
;
; Else ; multiple lines are combined on one pixel
; thick.d = 0
; lineDraw = 0
; max = 0
;
; file = 0
; remaining = *files\file[0]\Size
; color = *files\file[0]\Color
;
; While line < maxlines
; thick + RatioY
; max = Max(max, *lines\l[line])
;
; If thick >= 1
; length = max * RatioX
;
; If length > 0
; Line(2, 2 + lineDraw, length, 1, color)
; EndIf
;
; max = 0
; thick - 1
; lineDraw + 1
; EndIf
;
; line + 1
; remaining - 1
;
; If remaining = 0 And line < maxlines
; file + 1
; remaining = *files\file[file]\Size
; color = *files\file[file]\Color
; EndIf
; Wend
;
; If thick > 0
; ; draw last line
; length = max * RatioX
;
; If length > 0
; Line(2, 2 + lineDraw, length, 1, color)
; EndIf
; EndIf
;
; EndIf
;
; EndIf
;
; ; draw the border now to avoid the need for any clipping above
; DrawingMode(#PB_2DDrawing_Outlined)
; Box(0, 0, fullw, fullh, $000000)
; Box(1, 1, fullw-2, fullh-2, $FFFFFF)
;
; StopDrawing()
; EndIf
;
; SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Preview], ImageID(*Debugger\ProfilerPreview))
; Else
; SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Preview], 0)
; EndIf
;
; EndProcedure
; Adjust the PageLength of the scrollbars to the current
; ratio and size
;
Procedure Profiler_UpdatePageLength(*Debugger.DebuggerData)
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
MaxCount = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_Maximum)
MaxLine = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_Maximum)
SetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_PageLength, Area\w / *Debugger\ProfilerRatioX)
SetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_PageLength, Area\h / *Debugger\ProfilerRatioY)
CountPage = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_PageLength)
LinePage = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_PageLength)
If CountPage > MaxCount
SetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_PageLength, MaxCount)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], 1)
ElseIf CountPage = MaxCount
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], 1)
Else
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], 0)
EndIf
If LinePage > MaxLine
SetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_PageLength, MaxLine)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], 1)
ElseIf LinePage = MaxLine
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], 1)
Else
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], 0)
EndIf
EndProcedure
; xor function, so 2x the same args erases it
;
Procedure Profiler_DrawSelect(*Debugger.DebuggerData, x1, y1, x2, y2)
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
Profiler_ClipToViewport(@x1, @y1, @Area)
Profiler_ClipToViewport(@x2, @y2, @Area)
If x1 > x2
Swap x1, x2
EndIf
If y1 > y2
Swap y1, y2
EndIf
If StartDrawing(CanvasOutput(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas]))
DrawingMode(#PB_2DDrawing_XOr | #PB_2DDrawing_Outlined)
Box(x1, y1, x2-x1+1, y2-y1+1, $FFFFFF)
If y1 <> y2
For x = x1 To x2 Step 5
Plot(x, y1, $FFFFFF)
Plot(x, y2, $FFFFFF)
Next x
EndIf
If x1 <> x2
For y = y1 To y2 Step 5
Plot(x1, y, $FFFFFF)
Plot(x2, y, $FFFFFF)
Next y
EndIf
StopDrawing()
EndIf
EndProcedure
; xor drawing
;
Procedure Profiler_DrawCross(*Debugger.DebuggerData, x, y)
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
; we only draw when we are inside the viewport
;
If x >= Area\x And x < Area\x+Area\w And y >= Area\y And y < Area\y+Area\h
If StartDrawing(CanvasOutput(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas]))
DrawingMode(#PB_2DDrawing_XOr | #PB_2DDrawing_Transparent)
; draw the lines
;
If y > Area\y + 6
Line(x, Area\y, 1, y - Area\y - 6, $FFFFFF)
For i = Area\y To y - 6 Step 5
Plot(x, i, $FFFFFF)
Next i
EndIf
If y < Area\y+Area\h - 6
Line(x, y+6, 1, Area\h - (y - Area\y) - 6, $FFFFFF)
For i = y+6 To Area\y+Area\h Step 5
Plot(x, i, $FFFFFF)
Next i
EndIf
If x > Area\x + 6
Line(Area\x, y, x - Area\x - 6, 1, $FFFFFF)
For i = Area\x To x - 6 Step 5
Plot(i, y, $FFFFFF)
Next i
EndIf
If x < Area\x+Area\w - 6
Line(x+6, y, Area\w - (x - Area\x) - 6, 1, $FFFFFF)
For i = x+6 To Area\x+Area\w Step 5
Plot(i, y, $FFFFFF)
Next i
EndIf
; draw the numbers
; (add 1 even for the count, as we display what is under, not next to the cursor!)
;
count = 1+GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX]) + Int(Round((x - Area\x) / *Debugger\ProfilerRatioX, 0))
line = 1+GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY]) + Int(Round((y - Area\y) / *Debugger\ProfilerRatioY, 0))
Profiler_DrawNumber(Area\x+Area\w-2-Len(Str(line))*7, y-12, line, $FFFFFF)
Profiler_DrawNumber(x-2-Len(Str(count))*7, Area\y+3, count, $FFFFFF)
StopDrawing()
EndIf
EndIf
EndProcedure
CompilerIf #CompileWindows
; To handle scrolling events in realtime one Windows. Not needed on Linux
;
Procedure Profiler_ScrollbarCallback(Window, Message, wParam, lParam)
Result = 0
*Debugger.DebuggerData = GetWindowLongPtr_(Window, #GWL_USERDATA)
If *Debugger
;
; call the original callback first, so the gadget state is properly updated.
;
Result = CallWindowProc_(*Debugger\ProfilerScrollCallback, Window, Message, wParam, lParam)
; now check our event
;
If Message = #WM_HSCROLL Or Message = #WM_VSCROLL
Profiler_DrawAll(*Debugger)
EndIf
Else
Result = DefWindowProc_(Window, Message, wParam, lParam)
EndIf
ProcedureReturn Result
EndProcedure
CompilerEndIf
Global Profiler_CaptureMode, Profiler_DownX, Profiler_DownY, Profiler_OldX, Profiler_OldY
Procedure Profiler_LButtonDown(*Debugger.DebuggerData, x, y)
; if we were in mode 3, we simply switch to the new mode now, else start capturing
If Profiler_CaptureMode = 3
Profiler_DrawCross(*Debugger, Profiler_OldX, Profiler_OldY)
EndIf
Profiler_DownX = x
Profiler_DownY = y
Profiler_OldX = Profiler_DownX
Profiler_OldY = Profiler_DownY
If GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Select]) = 0
Profiler_CaptureMode = 1
Else
Profiler_CaptureMode = 2
Profiler_DrawSelect(*Debugger, Profiler_DownX, Profiler_DownY, Profiler_OldX, Profiler_OldY)
EndIf
EndProcedure
Procedure Profiler_LButtonUp(*Debugger.DebuggerData)
If Profiler_CaptureMode = 1 Or Profiler_CaptureMode = 2
If Profiler_CaptureMode = 2
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
Profiler_ClipToViewport(@Profiler_DownX, @Profiler_DownY, @Area)
Profiler_ClipToViewport(@Profiler_OldX, @Profiler_OldY, @Area)
If Profiler_DownX > Profiler_OldX
Swap Profiler_DownX, Profiler_OldX
EndIf
If Profiler_DownY > Profiler_OldY
Swap Profiler_DownY, Profiler_OldY
EndIf
; needed for later moving
;
countStart = GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX]) + (Profiler_DownX - Area\x) / *Debugger\ProfilerRatioX
lineStart = GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY]) + (Profiler_DownY - Area\y) / *Debugger\ProfilerRatioY
; zoom (must be before the move for the pagelength to be correct)
;
If Profiler_OldX > Profiler_DownX+1 And Profiler_OldY > Profiler_DownY+1
*Debugger\ProfilerRatioX / ((Profiler_OldX-Profiler_DownX) / Area\w)
*Debugger\ProfilerRatioY / ((Profiler_OldY-Profiler_DownY) / Area\h)
If *Debugger\ProfilerRatioX > 30.0: *Debugger\ProfilerRatioX = 30.0: EndIf
If *Debugger\ProfilerRatioY > 30.0: *Debugger\ProfilerRatioY = 30.0: EndIf
EndIf
Profiler_UpdatePageLength(*Debugger)
; move the origin
;
maxStart = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_Maximum) - GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_PageLength)
If maxStart > 0
If countStart < 0
countStart = 0
ElseIf countStart > maxStart
countStart = maxStart
EndIf
SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], countStart)
EndIf
maxStart = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_Maximum) - GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_PageLength)
If maxStart > 0
If lineStart < 0
lineStart = 0
ElseIf lineStart > maxStart
lineStart = maxStart
EndIf
SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], lineStart)
EndIf
Profiler_DrawAll(*Debugger)
EndIf
Profiler_CaptureMode = 0
EndIf
EndProcedure
Procedure Profiler_MouseMove(*Debugger.DebuggerData, x, y)
If Profiler_CaptureMode = 0 And GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Cross])
; start cross display
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
If x >= Area\x And x <= Area\x + Area\w And y >= Area\y And y <= Area\y+Area\h
Profiler_CaptureMode = 3
Profiler_DrawCross(*Debugger, x, y)
EndIf
ElseIf Profiler_CaptureMode = 3 ; continue cross display
Profiler_DrawCross(*Debugger, Profiler_OldX, Profiler_OldY) ; erase old one
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
If x >= Area\x And x <= Area\x + Area\w And y >= Area\y And y <= Area\y+Area\h
Profiler_DrawCross(*Debugger, x, y)
Else
; stop the capture
Profiler_CaptureMode = 0
EndIf
ElseIf Profiler_CaptureMode = 1 ; drag
countStart = GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX]) - (x - Profiler_OldX) / *Debugger\ProfilerRatioX
maxStart = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_Maximum) - GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_PageLength)
If maxStart > 0
If countStart < 0
countStart = 0
ElseIf countStart > maxStart
countStart = maxStart
EndIf
SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], countStart)
EndIf
lineStart = GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY]) - (y - Profiler_OldY) / *Debugger\ProfilerRatioY
maxStart = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_Maximum) - GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_PageLength)
If maxStart > 0
If lineStart < 0
lineStart = 0
ElseIf lineStart > maxStart
lineStart = maxStart
EndIf
SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], lineStart)
EndIf
Profiler_DrawAll(*Debugger)
ElseIf Profiler_CaptureMode = 2 ; select
If Profiler_OldX <> x Or Profiler_OldY <> y
Profiler_DrawSelect(*Debugger, Profiler_DownX, Profiler_DownY, Profiler_OldX, Profiler_OldY) ; erase with xor
Profiler_DrawSelect(*Debugger, Profiler_DownX, Profiler_DownY, x, y)
EndIf
EndIf
Profiler_OldX = x
Profiler_OldY = y
EndProcedure
Procedure Profiler_RButtonDown(*Debugger.DebuggerData, x, y)
If Profiler_CaptureMode > 0
If Profiler_CaptureMode = 2
Profiler_DrawSelect(*Debugger, Profiler_DownX, Profiler_DownY, Profiler_OldX, Profiler_OldY) ; erase with xor
ElseIf Profiler_CaptureMode = 3
Profiler_DrawCross(*Debugger, Profiler_OldX, Profiler_OldY) ; erase old one
EndIf
Profiler_CaptureMode = 0
EndIf
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
If X >= Area\x And X < Area\X+Area\w And Y >= Area\y And Y < Area\y+Area\h
Profiler_CurrentLine = GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY]) + Int(Round((y - Area\y) / *Debugger\ProfilerRatioY, 0)) ; 0-based
If CreatePopupMenu(#POPUPMENU_Profiler)
MenuItem(#DEBUGGER_MENU_Zoomin, Language("Debugger","Zoomin"))
MenuItem(#DEBUGGER_MENU_Zoomout, Language("Debugger","Zoomout"))
MenuBar()
If *Debugger\NbIncludedFiles = 0
MenuItem(#DEBUGGER_MENU_File0, Language("Debugger","ViewLine"))
Else
OpenSubMenu(Language("Debugger","ViewLine")+" ...")
; add all files we are viewing
For file = 0 To *Debugger\NbIncludedFiles
If GetGadgetItemState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], file) & (#PB_ListIcon_Checked|#PB_ListIcon_Selected)
index = GetGadgetItemData(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], file) ; get the real index
MenuItem(#DEBUGGER_MENU_File0+index, GetDebuggerRelativeFile(*Debugger, index << #DEBUGGER_DebuggerLineFileOffset))
EndIf
Next file
CloseSubMenu()
EndIf
DisplayPopupMenu(#POPUPMENU_Profiler, WindowID(*Debugger\Windows[#DEBUGGER_WINDOW_Profiler]))
EndIf
EndIf
EndProcedure
; Update bounds for the displayed files and adjust scrollbars as needed
;
Procedure Profiler_UpdateBounds(*Debugger.DebuggerData)
If *Debugger\ProfilerFiles And *Debugger\ProfilerData
*files.Debugger_ProfilerList = *Debugger\ProfilerFiles
If *Debugger\NbIncludedFiles = 0 ; single file mode
MaxLine = *files\file[0]\Size
MaxCount = 1
*lines.Local_Array = *Debugger\ProfilerData
For i = 0 To MaxLine-1
MaxCount = Max(*lines\l[i], MaxCount)
Next i
Else ; multifile mode
MaxLine = 1
MaxCount = 1
Gadget = *Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files]
For file = 0 To *Debugger\NbIncludedFiles
If GetGadgetItemState(Gadget, file) & (#PB_ListIcon_Checked|#PB_ListIcon_Selected)
index = GetGadgetItemData(Gadget, file) ; get the real index
linecount = *files\file[index ]\Size
*lines.Local_Array = *Debugger\ProfilerData + *files\file[index ]\Offset * SizeOf(LONG)
For line = 0 To linecount-1
MaxCount = Max(MaxCount, *lines\l[line])
Next line
MaxLine = Max(MaxLine, linecount)
EndIf
Next file
EndIf
Profiler_CalculateViewport(*Debugger, @Area.ProfilerDrawing)
*Debugger\ProfilerRatioX = (Area\w / MaxCount) * 0.995
*Debugger\ProfilerRatioY = (Area\h / MaxLine) * 0.995
; If MaxLine < 500
; *Debugger\ProfilerRatioY = (Area\h / MaxLine) * 0.995
; ElseIf MaxLine < 1000
; *Debugger\ProfilerRatioY = (Area\h / MaxLine) * 2
; ElseIf MaxLine < 3000
; *Debugger\ProfilerRatioY = (Area\h / MaxLine) * 4
; Else
; *Debugger\ProfilerRatioY = (Area\h / MaxLine) * 10
; EndIf
If *Debugger\ProfilerRatioX > 30.0: *Debugger\ProfilerRatioX = 30.0: EndIf
If *Debugger\ProfilerRatioY > 30.0: *Debugger\ProfilerRatioY = 30.0: EndIf
SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], 0)
SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], 0)
SetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollX], #PB_ScrollBar_Maximum, MaxCount)
SetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_ScrollY], #PB_ScrollBar_Maximum, MaxLine)
Profiler_UpdatePageLength(*Debugger)
EndIf
EndProcedure
Procedure Profiler_UpdateStats(*Debugger.DebuggerData)
If *Debugger\NbIncludedFiles > 0 And *Debugger\ProfilerFiles And *Debugger\ProfilerData
*files.Debugger_ProfilerList = *Debugger\ProfilerFiles
Gadget = *Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files]
totalcount = 0 ; grrr, quad bugs. lets stay with long
For file = 0 To *Debugger\NbIncludedFiles
index = GetGadgetItemData(Gadget, file) ; get the real index
linecount = *files\file[index ]\Size
count = 0
*lines.Local_Array = *Debugger\ProfilerData + *files\file[index]\Offset * SizeOf(LONG)
For line = 0 To linecount-1
count + *lines\l[line]
Next line
totalcount + count
SetGadgetItemText(Gadget, file, Str(count), 1)
SetGadgetItemText(Gadget, file, StrD(count / linecount, 1), 2)
Next file
EndIf
EndProcedure
Procedure UpdateProfilerWindowState(*Debugger.DebuggerData)
If *Debugger\ProgramState = -1
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Start], 1)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Stop], 1)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Reset], 1)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Update], 1)
Else
If *Debugger\ProfilerRunning
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Start], 1)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Stop], 0)
Else
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Start], 0)
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Stop], 1)
EndIf
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Reset], 0)
If *Debugger\ProgramState <> 0 And *Debugger\ProgramState <> -2
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Update], 1)
; send the update command
;
Command.CommandInfo\Command = #COMMAND_GetProfilerData ; do an update as well...
SendDebuggerCommand(*Debugger, @Command)
Else
DisableGadget(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Update], 0)
EndIf
EndIf
EndProcedure
Procedure ProfilerWindowEvents(*Debugger.DebuggerData, EventID)
Static DragItem
If EventID = #PB_Event_GadgetDrop ; can only be the files gadget
If *Debugger\ProfilerFiles
*files.Debugger_ProfilerList = *Debugger\ProfilerFiles
Target = GetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files])
If Target = -1
Target = CountGadgetItems(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files])
EndIf
index = GetGadgetItemData(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], DragItem)
Text$ = GetGadgetItemText(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], DragItem, 0) + Chr(10) + GetGadgetItemText(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], DragItem, 1) + Chr(10) + GetGadgetItemText(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], DragItem, 2)
state = GetGadgetItemState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], DragItem)
RemoveGadgetItem(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], DragItem)
If DragItem < Target
Target - 1
EndIf
AddGadgetItem(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], Target, Text$, ImageID(*files\file[index]\ColorImage))
SetGadgetItemData(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], Target, index) ; preserve the index
If state & #PB_ListIcon_Checked
SetGadgetItemState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], Target, #PB_ListIcon_Checked)
EndIf
SetGadgetState(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Files], Target)
Profiler_DrawAll(*Debugger) ; redraw with the new order
;Profiler_DrawPreview(*Debugger)
EndIf
ElseIf EventID = #PB_Event_Menu
Select EventMenu()
Case #DEBUGGER_MENU_Zoomin
*Debugger\ProfilerRatioX * 1.15
*Debugger\ProfilerRatioY * 1.15
If *Debugger\ProfilerRatioX > 30.0: *Debugger\ProfilerRatioX = 30.0: EndIf
If *Debugger\ProfilerRatioY > 30.0: *Debugger\ProfilerRatioY = 30.0: EndIf
Profiler_UpdatePageLength(*Debugger)
Profiler_DrawAll(*Debugger)
Case #DEBUGGER_MENU_Zoomout
*Debugger\ProfilerRatioX * 0.85
*Debugger\ProfilerRatioY * 0.85
If *Debugger\ProfilerRatioX < 1e-5: *Debugger\ProfilerRatioX = 1e-5: EndIf
If *Debugger\ProfilerRatioY < 1e-2: *Debugger\ProfilerRatioY = 1e-2: EndIf
Profiler_UpdatePageLength(*Debugger)
Profiler_DrawAll(*Debugger)
Case #DEBUGGER_MENU_File0 To #DEBUGGER_MENU_File255
Line = MakeDebuggerLine(EventMenu() - #DEBUGGER_MENU_File0, Profiler_CurrentLine)
Debugger_ShowLine(*Debugger, Line)
EndSelect
ElseIf EventID = #PB_Event_Gadget
Select EventGadget()
Case *Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas]
x = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas], #PB_Canvas_MouseX)
y = GetGadgetAttribute(*Debugger\Gadgets[#DEBUGGER_GADGET_Profiler_Canvas], #PB_Canvas_MouseY)
Select EventType()
Case #PB_EventType_MouseEnter, #PB_EventType_MouseMove
Profiler_MouseMove(*Debugger, x, y)
Case #PB_EventType_LeftButtonDown
Profiler_LButtonDown(*Debugger, x, y)
Case #PB_EventType_LeftButtonUp
Profiler_LButtonUp(*Debugger)
Case #PB_EventType_RightButtonDown