@@ -31,18 +31,33 @@ import UniformTypeIdentifiers
31
31
// then can focus on the bigger values.
32
32
// TODO: Sort by name and convert to count - can then see common counts
33
33
// so keep the json loaded in Swift. Can json be cloned and modded?
34
- // TODO: option to colesce to count and name with sort
34
+ // TODO: option to coalesce to count and name with sort
35
35
36
36
// Build traces
37
37
// TODO: parse totals from build traces, what CBA is doing
38
38
// TODO: present total time, and % of total in the nav panel
39
39
40
- // TODO: import zip, and run cba on contents, mmap and decompress each
41
- // can use incremental mode?
42
- // TODO: can't mmap web link, but can load zip off server with timings
40
+ // Perf traces
41
+ // TODO: ...
42
+
43
+ // TODO: track kram-profile memory use, jettison Data that isn't needed after have built up timings.
44
+ // can re-decompress from zip mmap.
45
+
46
+ // TODO: background process to compute duration and buildTimings across all files
47
+ // how to refresh the list as these are updated. Use Swift Task? Or could do on C++ side with TaskSystem.
48
+
49
+ // DONE: import zip
43
50
// DONE: add/update recent document list (need to hold onto dropped/opened folder)
44
- // TODO: save/load the duration and modstamps for File, and any other metadata (totals per section)
45
- // TODO: add jump to source, but path would need to be correct (sandbox block?)
51
+ // DONE: can't mmap web link, but can load zip off server with timings
52
+
53
+ // TODO: run cba on files, mmap and decompress each can use incremental mode?
54
+ // TODO: save/load the duration and modstamps for File at quit, and any other metadata (totals per section)
55
+ // TODO: add jump to source/header, but path would need to be correct (sandbox block?)
56
+
57
+ // Build traces
58
+ // TODO: OptFunction needs demangled. All backend strings are still mangled.
59
+ // Don’t need the library CBA uses just use api::__cxa_demangle() on macOS.
60
+ // https://github.com/llvm/llvm-project/issues/459
46
61
47
62
// TODO: across all files, many of the strings are the same. Could replace all strings
48
63
// with an index, compress, and zip archive with the index table. buid, perf, mem strings
@@ -78,14 +93,14 @@ import UniformTypeIdentifiers
78
93
79
94
// 4-bit, 12-bit, 16-bit, variable, pad to 4B
80
95
81
- // TODO : recent documents list doesn't survive relaunch, but only when app is rebuilt
96
+ // DONE : recent documents list doesn't survive relaunch, but only when app is rebuilt
82
97
// but still kind of annoying for development
83
98
84
99
// DONE: have a way to reload dropped folder
85
100
// DONE: track parent archives, folder, and loose drop files
86
101
// and when reload is hit, then reload all of that rebuild the list
87
102
// and then reload the selected file
88
- // TODO : zipHelper to deal with archives, can use Swift Data to mmap content if needed
103
+ // DONE : zipHelper to deal with archives, can use Swift Data to mmap content if needed
89
104
// mmap the zip, list out the files and locations, and then defalte the content somewhere
90
105
// only then can data be handed off toe Pefertto or CBA. And CBA needs all files.
91
106
// Maybe extend CBA to read a zip file. Can just use ZipHelper.
@@ -706,6 +721,9 @@ func updateFileBuildTimings(_ catapultProfile: CatapultProfile) -> [String:Build
706
721
// and then subtracting the immediate children.
707
722
// See what CBA and Perfetto do to establish this.
708
723
724
+ // Would be good to establish this nesting once and store the level
725
+ // with each event.d
726
+
709
727
// run through each file, and build a local map of name to size count
710
728
for i in 0 ..< catapultProfile. traceEvents!. count {
711
729
let event = catapultProfile. traceEvents![ i]
@@ -759,7 +777,7 @@ func mergeFileBuildTimings(files: [File]) -> [String:BuildTiming] {
759
777
760
778
func buildPerfettoJsonFromBuildTimings( buildTimings: [ String : BuildTiming ] ) -> String {
761
779
// now convert those timings back into a perfetto displayable report
762
- // So just need to buid up the json above into events on tracks
780
+ // So just need to build up the json above into events on tracks
763
781
var events : [ CatapultEvent ] = [ ]
764
782
765
783
// Also sort or assign a sort_index to the tracks. Sort biggest to smallest.
@@ -808,23 +826,27 @@ func buildPerfettoJsonFromBuildTimings(buildTimings: [String:BuildTiming]) -> St
808
826
}
809
827
}
810
828
811
- // TODO: sort this by the duration
812
829
events. sort {
830
+ // want threadnames first, could just prepend these to array?
831
+ if $0. ph! != $1. ph! {
832
+ return $0. ph! < $1. ph!
833
+ }
834
+
835
+ // then thread id
813
836
if $0. tid! != $1. tid! {
814
837
return $0. tid! < $1. tid!
815
838
}
816
839
840
+ // then duration
817
841
// has to be > to work as a single tid
818
842
if $0. dur != $1. dur! {
819
843
return $0. dur! > $1. dur!
820
844
}
821
845
846
+ // then name
822
847
return $0. name! < $1. name!
823
848
}
824
849
825
- // assign thread id, may not need names or tid
826
- // since Perfetto will just treat the events as subevents
827
-
828
850
let catapultProfile = CatapultProfile ( traceEvents: events)
829
851
830
852
do {
@@ -945,7 +967,6 @@ func updateThreadInfo(_ catapultProfile: CatapultProfile, _ file: inout File) {
945
967
}
946
968
947
969
file. threadInfo = text
948
- updateFileCache ( file: file)
949
970
}
950
971
951
972
func updateDuration( _ catapultProfile: CatapultProfile , _ file: inout File ) {
@@ -967,8 +988,6 @@ func updateDuration(_ catapultProfile: CatapultProfile, _ file: inout File) {
967
988
if startTime <= endTime {
968
989
// for now assume micros
969
990
file. duration = Double ( endTime - startTime) * 1e-6
970
-
971
- updateFileCache ( file: file)
972
991
}
973
992
}
974
993
@@ -1076,6 +1095,56 @@ func loadFileJS(_ path: String) -> String? {
1076
1095
file. buildTimings = updateFileBuildTimings ( catapultProfile)
1077
1096
}
1078
1097
1098
+ /* These are types CBA is looking at. It's not looking at any totals
1099
+ DebugType isn't in this.
1100
+
1101
+ if (StrEqual(name, "ExecuteCompiler"))
1102
+ event.type = BuildEventType::kCompiler;
1103
+ else if (StrEqual(name, "Frontend"))
1104
+ event.type = BuildEventType::kFrontend;
1105
+ else if (StrEqual(name, "Backend"))
1106
+ event.type = BuildEventType::kBackend;
1107
+ else if (StrEqual(name, "Source"))
1108
+ event.type = BuildEventType::kParseFile;
1109
+ else if (StrEqual(name, "ParseTemplate"))
1110
+ event.type = BuildEventType::kParseTemplate;
1111
+ else if (StrEqual(name, "ParseClass"))
1112
+ event.type = BuildEventType::kParseClass;
1113
+ else if (StrEqual(name, "InstantiateClass"))
1114
+ event.type = BuildEventType::kInstantiateClass;
1115
+ else if (StrEqual(name, "InstantiateFunction"))
1116
+ event.type = BuildEventType::kInstantiateFunction;
1117
+ else if (StrEqual(name, "OptModule"))
1118
+ event.type = BuildEventType::kOptModule;
1119
+ else if (StrEqual(name, "OptFunction"))
1120
+ event.type = BuildEventType::kOptFunction;
1121
+
1122
+ // here are totals that are in the file
1123
+ // Total ExecuteCompiler = Total Frontend + Total Backend
1124
+ // 2 frontend blocks though,
1125
+ // 1. Source, InstantiateFunction, CodeGenFunction, ...
1126
+ // 2. CodeGenFunction, DebugType, and big gaps
1127
+ //
1128
+ // 1 backend block
1129
+ // OptModule
1130
+
1131
+ "Total ExecuteCompiler" <- important
1132
+ "Total Frontend" <- important <- important
1133
+ "Total InstantiateFunction"
1134
+ "Total CodeGen Function"
1135
+ "Total Backend"
1136
+ "Total CodeGenPasses"
1137
+ "Total OptModule" <- important
1138
+ "Total OptFunction"
1139
+ "Total RunPass"
1140
+ "Total InstantiatePass"
1141
+ "Total Source"
1142
+ "Total ParseClass"
1143
+ "Total DebugType"
1144
+ "Total PerformPendingInstantiations"
1145
+ "Total Optimizer"
1146
+ */
1147
+
1079
1148
for i in 0 ..< catapultProfile. traceEvents!. count {
1080
1149
let event = catapultProfile. traceEvents![ i]
1081
1150
if event. name == " Source " ||
@@ -1097,16 +1166,34 @@ func loadFileJS(_ path: String) -> String? {
1097
1166
event. name == " CodeGen Function " ||
1098
1167
event. name == " RunPass "
1099
1168
{
1100
- // This is a name
1101
- let detail = event. args![ " detail " ] !. value as! String
1102
- catapultProfile. traceEvents![ i] . name = detail
1169
+ // backend symbols need demangle
1170
+ let isDemangleNeeded = event. name == " OptFunction "
1171
+
1172
+ if isDemangleNeeded {
1173
+ let detail = event. args![ " detail " ] !. value as! String
1174
+ let symbolName = String ( cString: demangleSymbolName ( detail) )
1175
+
1176
+ catapultProfile. traceEvents![ i] . name = symbolName
1177
+ }
1178
+ else {
1179
+ // This is a name
1180
+ let detail = event. args![ " detail " ] !. value as! String
1181
+ catapultProfile. traceEvents![ i] . name = detail
1182
+ }
1183
+ }
1184
+
1185
+ // These aren't renamed but are useful data for report
1186
+ // and are already calculated.
1187
+ else if event. name == " Total Backend " {
1188
+ file. totalBackend = event. dur!
1189
+ }
1190
+ else if event. name == " Total Ffrontend " {
1191
+ file. totalFrontend = event. dur!
1103
1192
}
1104
1193
}
1105
1194
1106
- // walk the file and compute the duration if we don't already have ti
1195
+ // walk the file and compute the duration if we don't already have it
1107
1196
if file. duration == 0.0 {
1108
-
1109
-
1110
1197
updateDuration ( catapultProfile, & file)
1111
1198
1112
1199
// For now, just log the per-thread info
@@ -1341,7 +1428,7 @@ struct kram_profileApp: App {
1341
1428
}
1342
1429
1343
1430
// This isn't so valuable to open a file, but opening a referenced header from build
1344
- // would be.
1431
+ // would be. But would to respond to/retrieve selection in JS side.
1345
1432
func openContainingFolder( _ str: String ) {
1346
1433
let url = URL ( string: str) !
1347
1434
NSWorkspace . shared. activateFileViewerSelecting ( [ url] ) ;
@@ -1382,7 +1469,6 @@ struct kram_profileApp: App {
1382
1469
1383
1470
let file = lookupFile ( selection: sel)
1384
1471
file. setLoadStamp ( )
1385
- updateFileCache ( file: file)
1386
1472
}
1387
1473
1388
1474
// Want to be able to lock the scale of the
0 commit comments