/
html_format.m
1854 lines (1672 loc) · 54.3 KB
/
html_format.m
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) 2001-2002 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
%
% Author: zs.
%
% This module contains code that sets the format of the HTML tables
% we generate for individual queries.
:- module html_format.
:- interface.
:- import_module profile, interface, measurements, top_procs.
:- import_module std_util, bool, list.
:- func table_start(preferences) = string.
:- func table_end(preferences) = string.
:- func page_banner(cmd, preferences) = string.
:- func page_footer(cmd, preferences, deep) = string.
:- func toggle_cost_criteria_in_top_procs_cmd(preferences, deep, display_limit,
cost_kind, include_descendants, measurement_scope) = string.
:- func criteria_to_description(order_criteria) = string.
:- func cost_criteria_to_description(cost_kind, include_descendants,
measurement_scope) = string.
:- type id_fields
---> source_proc
; rank_module
; rank_proc
; proc.
:- type totals_disposition
---> totals_meaningful
; totals_not_meaningful.
:- type header_wrap_func == (func(string, order_criteria) = string).
:- func fields_header(preferences, id_fields, totals_disposition,
header_wrap_func) = string.
:- func header_row(string, preferences, id_fields, totals_disposition) = string.
:- func separator_row(preferences, id_fields, totals_disposition) = string.
:- type sub_lines(T)
---> sub_lines(
sub_line_type :: T,
sub_line_list :: list(line_group(T, unit))
).
:- type one_id ---> one_id.
:- type two_id ---> two_id.
:- type one_id_sub_lines == sub_lines(one_id).
:- type two_id_sub_lines == sub_lines(two_id).
:- type one_id_line == line_group(one_id, unit).
:- type two_id_line == line_group(two_id, unit).
:- type one_id_line_group == line_group(one_id, one_id_sub_lines).
:- type two_id_line_group == line_group(two_id, two_id_sub_lines).
:- type one_two_id_line_group == line_group(one_id, two_id_sub_lines).
% This function takes a context description (which may be empty)
% and a HTML string describing all fields on in row but the first,
% and returns the HTML for the full row.
:- func add_context(string, line_group(one_id, LL)) = line_group(two_id, LL).
% This adds the context from the line group to the HTML as the first
% field of the resulting line group.
:- func add_self_context(line_group(one_id, LL)) = line_group(two_id, LL).
:- func add_ranks(list(line_group(one_id, LL))) = list(line_group(two_id, LL)).
:- func line_to_one_id_subline_group(line_group(FL, unit))
= line_group(FL, one_id_sub_lines).
:- func line_to_two_id_subline_group(line_group(FL, unit))
= line_group(FL, two_id_sub_lines).
:- func one_id_line_to_html(preferences, deep, totals_disposition,
one_id_line) = string.
:- func one_id_line_group_to_html(preferences, deep, totals_disposition,
one_id_line_group) = string.
:- func two_id_line_to_html(preferences, deep, totals_disposition,
two_id_line) = string.
:- func two_id_line_group_to_html(preferences, deep, totals_disposition,
two_id_line_group) = string.
:- func own_and_desc_to_html(own_prof_info, inherit_prof_info,
preferences, deep, totals_disposition) = string.
:- pred lookup_ticks_per_sec(profile_stats::in, int::out, bool::out) is det.
:- func proc_dynamic_name(deep, proc_dynamic_ptr) = string.
:- func proc_static_name(deep, proc_static_ptr) = string.
:- pred proc_dynamic_context(deep::in, proc_dynamic_ptr::in,
string::out, int::out) is det.
:- pred proc_static_context(deep::in, proc_static_ptr::in,
string::out, int::out) is det.
:- pred call_site_context(deep::in, call_site_static_ptr::in,
string::out, int::out) is det.
:- pred proc_static_to_line_group_info(preferences::in, deep::in,
proc_static_ptr::in, string::out, int::out, string::out, string::out)
is det.
:- func proc_static_to_html_ref(preferences, deep, proc_static_ptr) = string.
:- func module_name_to_html_ref(preferences, deep, string) = string.
:- func clique_ptr_to_html_ref(preferences, deep, string, clique_ptr) = string.
:- func deep_cmd_pref_to_url(preferences, deep, cmd) = string.
:- func plural(int) = string.
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module top_procs.
:- import_module int, float, char, string, map, require.
%-----------------------------------------------------------------------------%
page_banner(_Cmd, Pref) =
"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01//EN""\n" ++
"""http://www.w3.org/TR/html4/strict.dtd"">\n" ++
"<HTML>\n" ++
"<HEAD>\n" ++
"<TITLE>Page created by the Mercury Deep Profiler.</TITLE>\n" ++
banner_style(Pref) ++
"</HEAD>\n" ++
"<BODY>\n".
:- func banner_style(preferences) = string.
banner_style(Pref) = HTML :-
Fields = Pref ^ pref_fields,
GroupNum0 = 0,
IdStyle = string__format(" TD.id { %s }\n",
[s(select_colgroup_background(Pref, GroupNum0))]),
GroupNum1 = GroupNum0 + 1,
( Fields ^ port_fields = no_port ->
PortStyle = "",
GroupNum2 = GroupNum1
;
PortStyle = string__format(" TD.port { %s }\n",
[s(select_colgroup_background(Pref, GroupNum1))]),
GroupNum2 = GroupNum1 + 1
),
( Fields ^ time_fields = no_time ->
TimeStyle = "",
GroupNum3 = GroupNum2
;
TimeStyle = string__format(" TD.time { %s }\n",
[s(select_colgroup_background(Pref, GroupNum2))]),
GroupNum3 = GroupNum2 + 1
),
( Fields ^ alloc_fields = no_alloc ->
AllocStyle = "",
GroupNum4 = GroupNum3
;
AllocStyle = string__format(" TD.alloc { %s }\n",
[s(select_colgroup_background(Pref, GroupNum3))]),
GroupNum4 = GroupNum3 + 1
),
( Fields ^ memory_fields = no_memory ->
MemoryStyle = ""
;
MemoryStyle = string__format(" TD.memory { %s }\n",
[s(select_colgroup_background(Pref, GroupNum4))])
),
HTML =
"<STYLE TYPE=""text/css"">\n" ++
IdStyle ++
PortStyle ++
TimeStyle ++
AllocStyle ++
MemoryStyle ++
"</STYLE>\n".
:- func select_colgroup_background(preferences, int) = string.
select_colgroup_background(Pref, N) = HTML :-
(
Pref ^ pref_colour = column_groups,
( N /\ 1 = 0 ->
Background = even_background
;
Background = odd_background
),
string__format("background: %s", [s(Background)], HTML)
;
Pref ^ pref_colour = none,
HTML = ""
).
:- func even_background = string.
:- func odd_background = string.
even_background = "rgb(255, 255, 240)".
odd_background = "rgb(240, 240, 255)".
%-----------------------------------------------------------------------------%
table_start(Pref) = HTML :-
(
Pref ^ pref_box = nobox,
HTML = "\n<TABLE width=100%>\n"
;
Pref ^ pref_box = box,
HTML = "\n<TABLE width=100% border=1>\n"
).
table_end(_) = "</TABLE>\n".
%-----------------------------------------------------------------------------%
page_footer(Cmd, Pref, Deep) =
"<p>\n" ++
footer_pref_toggles(Cmd, Pref, Deep) ++
"<br>\n" ++
string__format("<A HREF=""%s"">Menu</A>\n",
[s(deep_cmd_pref_to_url(Pref, Deep, menu))]) ++
string__format("<A HREF=""%s"">Restart</A>\n",
[s(deep_cmd_pref_to_url(Pref, Deep, restart))]) ++
string__format("<A HREF=""%s"">Quit</A>\n",
[s(deep_cmd_pref_to_url(Pref, Deep, quit))]) ++
"</BODY>\n" ++
"</HTML>\n".
:- func footer_pref_toggles(cmd, preferences, deep) = string.
footer_pref_toggles(Cmd, Pref, Deep) = AllToggles :-
RelevantToggles = command_relevant_toggles(Cmd),
( list__member(toggle_fields, RelevantToggles) ->
FieldToggle = footer_field_toggle(Cmd, Pref, Deep)
;
FieldToggle = ""
),
( list__member(toggle_ancestor_limit, RelevantToggles) ->
AncestorToggle =
footer_ancestor_toggle(Cmd, Pref, Deep) ++
"<br>\n"
;
AncestorToggle = ""
),
( list__member(toggle_order_criteria, RelevantToggles) ->
OrderToggle =
footer_order_criteria_toggle(Cmd, Pref, Deep) ++
"<br>\n"
;
OrderToggle = ""
),
( list__member(toggle_summarize, RelevantToggles) ->
SummarizeToggle = footer_summarize_toggle(Cmd, Pref, Deep)
;
SummarizeToggle = ""
),
( list__member(toggle_contour, RelevantToggles) ->
ContourToggle = footer_contour_toggle(Cmd, Pref, Deep)
;
ContourToggle = ""
),
( list__member(toggle_time_format, RelevantToggles) ->
TimeFormatToggle = footer_time_format_toggle(Cmd, Pref, Deep)
;
TimeFormatToggle = ""
),
( list__member(toggle_colour, RelevantToggles) ->
ColourToggle = footer_colour_toggle(Cmd, Pref, Deep)
;
ColourToggle = ""
),
( list__member(toggle_box, RelevantToggles) ->
BoxToggle = footer_box_toggle(Cmd, Pref, Deep)
;
BoxToggle = ""
),
AllToggles =
FieldToggle ++
AncestorToggle ++
OrderToggle ++
SummarizeToggle ++
ContourToggle ++
TimeFormatToggle ++
ColourToggle ++
BoxToggle.
%-----------------------------------------------------------------------------%
:- type toggle_kind
---> toggle_fields
; toggle_box
; toggle_colour
; toggle_ancestor_limit
; toggle_summarize
; toggle_order_criteria
; toggle_contour
; toggle_time_format.
:- func command_relevant_toggles(cmd) = list(toggle_kind).
command_relevant_toggles(quit) = [].
command_relevant_toggles(restart) = [].
command_relevant_toggles(timeout(_)) = [].
command_relevant_toggles(menu) = [].
command_relevant_toggles(root(_)) =
command_relevant_toggles(clique(1)). % The clique num doesn't matter.
command_relevant_toggles(clique(_)) =
[toggle_fields, toggle_box, toggle_colour, toggle_ancestor_limit,
toggle_summarize, toggle_order_criteria, toggle_time_format].
command_relevant_toggles(proc(_)) =
[toggle_fields, toggle_box, toggle_colour, toggle_summarize,
toggle_order_criteria, toggle_time_format].
command_relevant_toggles(proc_callers(_, _, _)) =
[toggle_fields, toggle_box, toggle_colour, toggle_order_criteria,
toggle_contour, toggle_time_format].
command_relevant_toggles(modules) =
[toggle_fields, toggle_box, toggle_colour, toggle_order_criteria,
toggle_time_format].
command_relevant_toggles(module(_)) =
[toggle_fields, toggle_box, toggle_colour, toggle_order_criteria,
toggle_time_format].
command_relevant_toggles(top_procs(_, _, _, _)) =
[toggle_fields, toggle_box, toggle_colour, toggle_time_format].
command_relevant_toggles(proc_static(_)) = [].
command_relevant_toggles(proc_dynamic(_)) = [].
command_relevant_toggles(call_site_static(_)) = [].
command_relevant_toggles(call_site_dynamic(_)) = [].
command_relevant_toggles(raw_clique(_)) = [].
:- func footer_field_toggle(cmd, preferences, deep) = string.
footer_field_toggle(Cmd, Pref, Deep) = HTML :-
Fields = Pref ^ pref_fields,
( Fields ^ port_fields = no_port ->
Port1Toggle = ""
;
Port1Fields = Fields ^ port_fields := no_port,
Port1Pref = Pref ^ pref_fields := Port1Fields,
Port1Msg = "No port counts",
Port1Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Port1Pref, Deep, Cmd)),
s(Port1Msg)])
),
( Fields ^ port_fields = port ->
Port2Toggle = ""
;
Port2Fields = Fields ^ port_fields := port,
Port2Pref = Pref ^ pref_fields := Port2Fields,
Port2Msg = "Port counts",
Port2Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Port2Pref, Deep, Cmd)),
s(Port2Msg)])
),
( Fields ^ time_fields = no_time ->
Time1Toggle = ""
;
Time1Fields = Fields ^ time_fields := no_time,
Time1Pref = Pref ^ pref_fields := Time1Fields,
Time1Msg = "No time info",
Time1Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Time1Pref, Deep, Cmd)),
s(Time1Msg)])
),
( Fields ^ time_fields = ticks ->
Time2Toggle = ""
;
Time2Fields = Fields ^ time_fields := ticks,
Time2Pref = Pref ^ pref_fields := Time2Fields,
Time2Msg = "Ticks",
Time2Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Time2Pref, Deep, Cmd)),
s(Time2Msg)])
),
( Fields ^ time_fields = time ->
Time3Toggle = ""
;
Time3Fields = Fields ^ time_fields := time,
Time3Pref = Pref ^ pref_fields := Time3Fields,
Time3Msg = "Ticks and times",
Time3Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Time3Pref, Deep, Cmd)),
s(Time3Msg)])
),
( Fields ^ time_fields = ticks_and_time ->
Time4Toggle = ""
;
Time4Fields = Fields ^ time_fields := ticks_and_time,
Time4Pref = Pref ^ pref_fields := Time4Fields,
Time4Msg = "Ticks and times",
Time4Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Time4Pref, Deep, Cmd)),
s(Time4Msg)])
),
( Fields ^ time_fields = time_and_percall ->
Time5Toggle = ""
;
Time5Fields = Fields ^ time_fields := time_and_percall,
Time5Pref = Pref ^ pref_fields := Time5Fields,
Time5Msg = "Times and per-call times",
Time5Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Time5Pref, Deep, Cmd)),
s(Time5Msg)])
),
( Fields ^ time_fields = ticks_and_time_and_percall ->
Time6Toggle = ""
;
Time6Fields = Fields ^ time_fields :=
ticks_and_time_and_percall,
Time6Pref = Pref ^ pref_fields := Time6Fields,
Time6Msg = "Ticks and times and per-call times",
Time6Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Time6Pref, Deep, Cmd)),
s(Time6Msg)])
),
( Fields ^ alloc_fields = no_alloc ->
Alloc1Toggle = ""
;
Alloc1Fields = Fields ^ alloc_fields := no_alloc,
Alloc1Pref = Pref ^ pref_fields := Alloc1Fields,
Alloc1Msg = "No allocations",
Alloc1Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Alloc1Pref, Deep, Cmd)),
s(Alloc1Msg)])
),
( Fields ^ alloc_fields = alloc ->
Alloc2Toggle = ""
;
Alloc2Fields = Fields ^ alloc_fields := alloc,
Alloc2Pref = Pref ^ pref_fields := Alloc2Fields,
Alloc2Msg = "Allocations",
Alloc2Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Alloc2Pref, Deep, Cmd)),
s(Alloc2Msg)])
),
( Fields ^ alloc_fields = alloc_and_percall ->
Alloc3Toggle = ""
;
Alloc3Fields = Fields ^ alloc_fields := alloc_and_percall,
Alloc3Pref = Pref ^ pref_fields := Alloc3Fields,
Alloc3Msg = "Allocations and per-call allocations",
Alloc3Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Alloc3Pref, Deep, Cmd)),
s(Alloc3Msg)])
),
( Fields ^ memory_fields = no_memory ->
Memory1Toggle = ""
;
Memory1Fields = Fields ^ memory_fields := no_memory,
Memory1Pref = Pref ^ pref_fields := Memory1Fields,
Memory1Msg = "No memory info",
Memory1Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Memory1Pref, Deep, Cmd)),
s(Memory1Msg)])
),
( Fields ^ memory_fields = memory(words) ->
Memory2Toggle = ""
;
Memory2Fields = Fields ^ memory_fields := memory(words),
Memory2Pref = Pref ^ pref_fields := Memory2Fields,
Memory2Msg = "Words",
Memory2Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Memory2Pref, Deep, Cmd)),
s(Memory2Msg)])
),
( Fields ^ memory_fields = memory(bytes) ->
Memory3Toggle = ""
;
Memory3Fields = Fields ^ memory_fields := memory(bytes),
Memory3Pref = Pref ^ pref_fields := Memory3Fields,
Memory3Msg = "Bytes",
Memory3Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Memory3Pref, Deep, Cmd)),
s(Memory3Msg)])
),
( Fields ^ memory_fields = memory_and_percall(words) ->
Memory4Toggle = ""
;
Memory4Fields = Fields ^ memory_fields :=
memory_and_percall(words),
Memory4Pref = Pref ^ pref_fields := Memory4Fields,
Memory4Msg = "Words and per-call words",
Memory4Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Memory4Pref, Deep, Cmd)),
s(Memory4Msg)])
),
( Fields ^ memory_fields = memory_and_percall(bytes) ->
Memory5Toggle = ""
;
Memory5Fields = Fields ^ memory_fields :=
memory_and_percall(bytes),
Memory5Pref = Pref ^ pref_fields := Memory5Fields,
Memory5Msg = "Bytes and per-call bytes",
Memory5Toggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Memory5Pref, Deep, Cmd)),
s(Memory5Msg)])
),
( Fields = default_fields ->
DefaultMsg = "Restore defaults",
DefaultPref = Pref ^ pref_fields := default_fields,
DefaultToggle = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(DefaultPref, Deep, Cmd)),
s(DefaultMsg)])
;
DefaultToggle = ""
),
HTML =
"Toggle fields:\n" ++
DefaultToggle ++
Port1Toggle ++ Port2Toggle ++
Time1Toggle ++ Time2Toggle ++ Time3Toggle ++
Time4Toggle ++ Time5Toggle ++ Time6Toggle ++
"<br>\n" ++
Alloc1Toggle ++ Alloc2Toggle ++ Alloc3Toggle ++
Memory1Toggle ++ Memory2Toggle ++ Memory3Toggle ++
Memory4Toggle ++ Memory5Toggle ++
"<br>\n".
:- func footer_ancestor_toggle(cmd, preferences, deep) = string.
footer_ancestor_toggle(Cmd, Pref, Deep) = HTML :-
(
Pref ^ pref_anc = no,
Display1 = yes,
Display2 = yes,
Msg1 = "One ancestor",
Pref1 = Pref ^ pref_anc := yes(1),
Msg2 = "Two ancestors",
Pref2 = Pref ^ pref_anc := yes(2),
Msg3 = "Three ancestors",
Pref3 = Pref ^ pref_anc := yes(3),
Msg4 = "Five ancestors",
Pref4 = Pref ^ pref_anc := yes(5),
Msg5 = "Ten ancestors",
Pref5 = Pref ^ pref_anc := yes(10)
;
Pref ^ pref_anc = yes(OldAncestorLimit),
( OldAncestorLimit > 2 ->
Display1 = yes
;
Display1 = no
),
( OldAncestorLimit > 1 ->
Display2 = yes
;
Display2 = no
),
Msg1 = "Halve ancestors",
Pref1 = Pref ^ pref_anc := yes(OldAncestorLimit // 2),
Msg2 = "Remove an ancestor",
Pref2 = Pref ^ pref_anc := yes(OldAncestorLimit - 1),
Msg3 = "Add an ancestor",
Pref3 = Pref ^ pref_anc := yes(OldAncestorLimit + 1),
Msg4 = "Double ancestors",
Pref4 = Pref ^ pref_anc := yes(OldAncestorLimit * 2),
Msg5 = "Unlimited ancestors",
Pref5 = Pref ^ pref_anc := no
),
Toggle1 = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref1, Deep, Cmd)), s(Msg1)]),
Toggle2 = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref2, Deep, Cmd)), s(Msg2)]),
Toggle3 = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref3, Deep, Cmd)), s(Msg3)]),
Toggle4 = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref4, Deep, Cmd)), s(Msg4)]),
Toggle5 = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref5, Deep, Cmd)), s(Msg5)]),
(
Display1 = yes,
MaybeToggle1 = Toggle1
;
Display1 = no,
MaybeToggle1 = ""
),
(
Display2 = yes,
MaybeToggle2 = Toggle2
;
Display2 = no,
MaybeToggle2 = ""
),
HTML =
"Toggle ancestors:\n" ++
MaybeToggle1 ++ MaybeToggle2 ++ Toggle3 ++ Toggle4 ++ Toggle5.
:- func footer_box_toggle(cmd, preferences, deep) = string.
footer_box_toggle(Cmd, Pref, Deep) = HTML :-
(
Pref ^ pref_box = nobox,
Pref1 = Pref ^ pref_box := box,
Msg1 = "Box"
;
Pref ^ pref_box = box,
Pref1 = Pref ^ pref_box := nobox,
Msg1 = "Unbox"
),
HTML = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref1, Deep, Cmd)), s(Msg1)]).
:- func footer_colour_toggle(cmd, preferences, deep) = string.
footer_colour_toggle(Cmd, Pref, Deep) = HTML :-
(
Pref ^ pref_colour = none,
Pref1 = Pref ^ pref_colour := column_groups,
Msg1 = "Colour column groups"
;
Pref ^ pref_colour = column_groups,
Pref1 = Pref ^ pref_colour := none,
Msg1 = "Fade column groups"
),
HTML = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref1, Deep, Cmd)), s(Msg1)]).
:- func footer_summarize_toggle(cmd, preferences, deep) = string.
footer_summarize_toggle(Cmd, Pref, Deep) = HTML :-
(
Pref ^ pref_summarize = summarize,
Pref1 = Pref ^ pref_summarize := dont_summarize,
Msg1 = "Expand higher order calls"
;
Pref ^ pref_summarize = dont_summarize,
Pref1 = Pref ^ pref_summarize := summarize,
Msg1 = "Summarize higher order calls"
),
HTML = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref1, Deep, Cmd)), s(Msg1)]).
:- func footer_contour_toggle(cmd, preferences, deep) = string.
footer_contour_toggle(Cmd, Pref, Deep) = HTML :-
(
Pref ^ pref_contour = no_contour,
Pref1 = Pref ^ pref_contour := apply_contour,
Msg1 = "Apply contour exclusion"
;
Pref ^ pref_contour = apply_contour,
Pref1 = Pref ^ pref_contour := no_contour,
Msg1 = "Don't apply contour exclusion"
),
HTML = string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref1, Deep, Cmd)), s(Msg1)]).
:- func footer_time_format_toggle(cmd, preferences, deep) = string.
footer_time_format_toggle(Cmd, Pref, Deep) = HTML :-
(
Pref ^ pref_time = no_scale,
Pref1 = Pref ^ pref_time := scale_by_millions,
Msg1 = "Time in s, us",
Pref2 = Pref ^ pref_time := scale_by_thousands,
Msg2 = "Time in s, ms, us, ns"
;
Pref ^ pref_time = scale_by_millions,
Pref1 = Pref ^ pref_time := no_scale,
Msg1 = "Time in s",
Pref2 = Pref ^ pref_time := scale_by_thousands,
Msg2 = "Time in s, ms, us, ns"
;
Pref ^ pref_time = scale_by_thousands,
Pref1 = Pref ^ pref_time := no_scale,
Msg1 = "Time in s",
Pref2 = Pref ^ pref_time := scale_by_millions,
Msg2 = "Time in s, us"
),
HTML =
string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref1, Deep, Cmd)),
s(Msg1)]) ++
string__format("<A HREF=""%s"">%s</A>\n",
[s(deep_cmd_pref_to_url(Pref2, Deep, Cmd)),
s(Msg2)]).
%-----------------------------------------------------------------------------%
:- func footer_order_criteria_toggle(cmd, preferences, deep) = string.
footer_order_criteria_toggle(Cmd, Pref, Deep) =
toggle_criteria(Pref ^ pref_criteria,
update_criteria_in_prefs(Pref, Deep, Cmd),
update_cost_criteria_in_prefs(Pref, Deep, Cmd)).
toggle_cost_criteria_in_top_procs_cmd(Pref, Deep, Limit,
CostKind, InclDesc, Scope) =
toggle_cost_criteria(CostKind, InclDesc, Scope,
update_cost_criteria_in_top_procs_cmd(Pref, Deep, Limit)).
%-----------------------------------------------------------------------------%
:- type update_criteria_func ==
(func(order_criteria) = string).
:- type update_cost_criteria_func ==
(func(cost_kind, include_descendants, measurement_scope) = string).
:- func toggle_criteria(order_criteria,
update_criteria_func, update_cost_criteria_func) = string.
toggle_criteria(Criteria, UpdateCriteria, UpdateCostCriteria) = HTML :-
(
Criteria = by_context,
Criteria1 = by_name,
Msg1 = "Sort by name",
Criteria2 = by_cost(default_cost_kind,
default_incl_desc, default_scope),
Msg2 = "Sort by cost"
;
Criteria = by_name,
Criteria1 = by_context,
Msg1 = "Sort by context",
Criteria2 = by_cost(default_cost_kind,
default_incl_desc, default_scope),
Msg2 = "Sort by cost"
;
Criteria = by_cost(_, _, _),
Criteria1 = by_context,
Msg1 = "Sort by context",
Criteria2 = by_name,
Msg2 = "Sort by name"
),
Toggle1 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(Criteria1)), s(Msg1)]),
Toggle2 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(Criteria2)), s(Msg2)]),
( Criteria = by_cost(CostKind, InclDesc, Scope) ->
ToggleRest = toggle_cost_criteria(CostKind, InclDesc, Scope,
UpdateCostCriteria)
;
ToggleRest = ""
),
HTML =
"Toggle ordering criteria:\n" ++
Toggle1 ++ Toggle2 ++ ToggleRest.
:- func toggle_cost_criteria(cost_kind, include_descendants, measurement_scope,
update_cost_criteria_func) = string.
toggle_cost_criteria(CostKind, InclDesc, Scope, UpdateCriteria) = Toggles :-
( CostKind \= calls ->
Msg1 = "Sort by calls",
Toggle1 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(calls, InclDesc, Scope)),
s(Msg1)])
;
Toggle1 = ""
),
( CostKind \= time ->
Msg2 = "Sort by time",
Toggle2 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(time, InclDesc, Scope)),
s(Msg2)])
;
Toggle2 = ""
),
( CostKind \= allocs ->
Msg3 = "Sort by allocations",
Toggle3 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(allocs, InclDesc, Scope)),
s(Msg3)])
;
Toggle3 = ""
),
( CostKind \= words ->
Msg4 = "Sort by words",
Toggle4 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(words, InclDesc, Scope)),
s(Msg4)])
;
Toggle4 = ""
),
(
InclDesc = self,
Msg5 = "Include descendants",
Toggle5 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(CostKind, self_and_desc, Scope)),
s(Msg5)])
;
InclDesc = self_and_desc,
Msg5 = "Exclude descendants",
Toggle5 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(CostKind, self, Scope)),
s(Msg5)])
),
(
Scope = per_call,
Msg6 = "Count overall cost",
Toggle6 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(CostKind, InclDesc, overall)),
s(Msg6)])
;
Scope = overall,
Msg6 = "Count per-call cost",
Toggle6 = string__format("<A HREF=""%s"">%s</A>\n",
[s(UpdateCriteria(CostKind, InclDesc, per_call)),
s(Msg6)])
),
Toggles = Toggle1 ++ Toggle2 ++ Toggle3 ++ Toggle4
++ Toggle5 ++ Toggle6.
%-----------------------------------------------------------------------------%
:- func update_criteria_in_prefs(preferences, deep, cmd, order_criteria)
= string.
update_criteria_in_prefs(Pref0, Deep, Cmd, Criteria) = HTML :-
Pref = Pref0 ^ pref_criteria := Criteria,
HTML = deep_cmd_pref_to_url(Pref, Deep, Cmd).
:- func update_cost_criteria_in_prefs(preferences, deep, cmd,
cost_kind, include_descendants, measurement_scope) = string.
update_cost_criteria_in_prefs(Pref0, Deep, Cmd, CostKind, InclDesc, Scope)
= HTML :-
Pref = Pref0 ^ pref_criteria := by_cost(CostKind, InclDesc, Scope),
HTML = deep_cmd_pref_to_url(Pref, Deep, Cmd).
:- func update_cost_criteria_in_top_procs_cmd(preferences, deep, display_limit,
cost_kind, include_descendants, measurement_scope) = string.
update_cost_criteria_in_top_procs_cmd(Pref, Deep, Limit,
CostKind, InclDesc, Scope) = HTML :-
Cmd = top_procs(Limit, CostKind, InclDesc, Scope),
HTML = deep_cmd_pref_to_url(Pref, Deep, Cmd).
%-----------------------------------------------------------------------------%
criteria_to_description(by_context) = "ordered by context".
criteria_to_description(by_name) = "ordered by name".
criteria_to_description(by_cost(CostKind, InclDesc, Scope)) =
cost_criteria_to_description(CostKind, InclDesc, Scope).
cost_criteria_to_description(CostKind, InclDesc, Scope) = Desc :-
Desc =
"ordered by " ++
incl_desc_to_description(InclDesc) ++ " " ++
cost_kind_to_description(CostKind) ++ " " ++
scope_to_description(Scope).
:- func cost_kind_to_description(cost_kind) = string.
cost_kind_to_description(calls) = "number of calls".
cost_kind_to_description(time) = "time".
cost_kind_to_description(allocs) = "memory allocations".
cost_kind_to_description(words) = "words allocated".
:- func incl_desc_to_description(include_descendants) = string.
incl_desc_to_description(self) = "self".
incl_desc_to_description(self_and_desc) = "total".
:- func scope_to_description(measurement_scope) = string.
scope_to_description(per_call) = "per call".
scope_to_description(overall) = "overall".
%-----------------------------------------------------------------------------%
% The predicates fields_header, table_width and own_and_desc_to_html
% all make decisions about what columns each row in the table will have.
% They therefore have similar control structures, and a change in one
% may require changes in the others as well.
fields_header(Pref, IdFields, TotalsDisp, WrapFunc) = HTML :-
Fields = Pref ^ pref_fields,
ProcName = WrapFunc("Procedure", by_name),
ModuleName = WrapFunc("Module", by_name),
(
IdFields = source_proc,
Source = WrapFunc("Source", by_context),
FirstRow0 =
"<TR>\n" ++
string__format("<TH ALIGN=LEFT ROWSPAN=2>%s\n",
[s(Source)]) ++
string__format("<TH ALIGN=LEFT ROWSPAN=2>%s\n",
[s(ProcName)])
;
IdFields = rank_proc,
FirstRow0 =
"<TR>\n" ++
"<TH ALIGN=LEFT ROWSPAN=2>Rank\n" ++
string__format("<TH ALIGN=LEFT ROWSPAN=2>%s\n",
[s(ProcName)])
;
IdFields = rank_module,
FirstRow0 =
"<TR>\n" ++
"<TH ALIGN=LEFT ROWSPAN=2>Rank\n" ++
string__format("<TH ALIGN=LEFT ROWSPAN=2>%s\n",
[s(ModuleName)])
;
IdFields = proc,
FirstRow0 =
"<TR>\n" ++
string__format("<TH ALIGN=LEFT ROWSPAN=2>%s\n",
[s(ProcName)])
),
SecondRow0 = "<TR>\n",
( show_port_counts(Fields) = yes ->
Calls = WrapFunc("Calls", by_cost(calls, self, overall)),
FirstRow1 = FirstRow0 ++
"<TH COLSPAN=4>Port counts\n",
SecondRow1 = SecondRow0 ++
string__format("<TH ALIGN=RIGHT>%s\n",
[s(Calls)]) ++
"<TH ALIGN=RIGHT>Exits\n" ++
"<TH ALIGN=RIGHT>Fails\n" ++
"<TH ALIGN=RIGHT>Redos\n"
;
FirstRow1 = FirstRow0,
SecondRow1 = SecondRow0
),
( show_quanta(Fields) = yes ->
TicksSelfOverall = WrapFunc("Self",
by_cost(time, self, overall)),
TicksSelfHeading =
string__format("<TH ALIGN=RIGHT>%s\n",
[s(TicksSelfOverall)]),
TicksSelfFields = 1
;
TicksSelfHeading = "",
TicksSelfFields = 0
),
( show_times(Fields) = yes ->
( show_quanta(Fields) = yes ->
TimeSelfOverall = WrapFunc("Time",
by_cost(time, self, overall))
;
TimeSelfOverall = WrapFunc("Self",
by_cost(time, self, overall))
),
TimeSelfHeading =
string__format("<TH ALIGN=RIGHT>%s\n",
[s(TimeSelfOverall)]),
TimeSelfFields = 1
;
TimeSelfHeading = "",
TimeSelfFields = 0
),
( ( show_quanta(Fields) = yes ; show_times(Fields) = yes ) ->
TimeSelfPercentHeading = "<TH ALIGN=RIGHT>%\n",
TimeSelfPercentFields = 1
;
TimeSelfPercentHeading = "",
TimeSelfPercentFields = 0
),
( show_per_times(Fields) = yes ->
TimeSelfPerCall = WrapFunc("/call",
by_cost(time, self, per_call)),
TimeSelfPerCallHeading =
string__format("<TH ALIGN=RIGHT>%s\n",
[s(TimeSelfPerCall)]),
TimeSelfPerCallFields = 1
;
TimeSelfPerCallHeading = "",
TimeSelfPerCallFields = 0
),
( TotalsDisp = totals_meaningful, show_quanta(Fields) = yes ->
TicksTotalOverall = WrapFunc("Total",
by_cost(time, self_and_desc, overall)),
TicksTotalHeading =
string__format("<TH ALIGN=RIGHT>%s\n",
[s(TicksTotalOverall)]),
TicksTotalFields = 1
;
TicksTotalHeading = "",
TicksTotalFields = 0
),
( TotalsDisp = totals_meaningful, show_times(Fields) = yes ->
( show_quanta(Fields) = yes ->
TimeTotalOverall = WrapFunc("Time",
by_cost(time, self_and_desc, overall))
;
TimeTotalOverall = WrapFunc("Total",
by_cost(time, self_and_desc, overall))
),
TimeTotalHeading =
string__format("<TH ALIGN=RIGHT>%s\n",
[s(TimeTotalOverall)]),
TimeTotalFields = 1
;
TimeTotalHeading = "",
TimeTotalFields = 0
),
(
TotalsDisp = totals_meaningful,
( show_quanta(Fields) = yes ; show_times(Fields) = yes )
->
TimeTotalPercentHeading = "<TH ALIGN=RIGHT>%\n",
TimeTotalPercentFields = 1
;
TimeTotalPercentHeading = "",