Skip to content

Commit dcf27dc

Browse files
authored
Support other types of files Perfetto already supports including .gz compressed traces, Chromium F12 DevTools Perf Profile Export, and legacy chrome://tracing .json files (#89)
1 parent 1c8870c commit dcf27dc

File tree

1 file changed

+114
-34
lines changed

1 file changed

+114
-34
lines changed

PerfettoCds/Pipeline/PerfettoDataSource.cs

Lines changed: 114 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@
88

99
namespace PerfettoCds
1010
{
11+
public static class PerfettoCds
12+
{
13+
public static string[] PerfettoCopyrightLicense = new string[]
14+
{
15+
"Built using Google Perfetto 4\n" +
16+
"Copyright (C) 2020 The Android Open Source Project\n" +
17+
"\n" +
18+
"Licensed under the Apache License, Version 2.0 (the \"License\");\n" +
19+
"you may not use this file except in compliance with the License.\n" +
20+
"You may obtain a copy of the License at\n" +
21+
"\n" +
22+
"http://www.apache.org/licenses/LICENSE-2.0\n" +
23+
"\n" +
24+
"Unless required by applicable law or agreed to in writing, software\n" +
25+
"distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
26+
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
27+
"See the License for the specific language governing permissions and\n" +
28+
"limitations under the License.\n"
29+
};
30+
}
31+
1132
[ProcessingSource("9fc8515e-9206-4690-b14a-3e7b54745c5f", "PerfettoTraceDataSource", "Processes Perfetto trace files")]
1233
[FileDataSource(".perfetto-trace", "Perfetto trace files")]
1334
public sealed class PerfettoDataSource : ProcessingSource
@@ -30,23 +51,7 @@ public override ProcessingSourceInfo GetAboutInfo()
3051
{
3152
ProjectInfo = new ProjectInfo() { Uri = "https://aka.ms/linuxperftools" },
3253
CopyrightNotice = "Copyright (C) " + DateTime.UtcNow.Year,
33-
AdditionalInformation = new[]
34-
{
35-
"Built using Google Perfetto 4\n" +
36-
"Copyright (C) 2020 The Android Open Source Project\n" +
37-
"\n" +
38-
"Licensed under the Apache License, Version 2.0 (the \"License\");\n" +
39-
"you may not use this file except in compliance with the License.\n" +
40-
"You may obtain a copy of the License at\n" +
41-
"\n" +
42-
"http://www.apache.org/licenses/LICENSE-2.0\n" +
43-
"\n" +
44-
"Unless required by applicable law or agreed to in writing, software\n" +
45-
"distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
46-
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
47-
"See the License for the specific language governing permissions and\n" +
48-
"limitations under the License.\n"
49-
},
54+
AdditionalInformation = PerfettoCds.PerfettoCopyrightLicense,
5055
};
5156
}
5257

@@ -90,23 +95,7 @@ public override ProcessingSourceInfo GetAboutInfo()
9095
{
9196
ProjectInfo = new ProjectInfo() { Uri = "https://aka.ms/linuxperftools" },
9297
CopyrightNotice = "Copyright (C) " + DateTime.UtcNow.Year,
93-
AdditionalInformation = new[]
94-
{
95-
"Built using Google Perfetto 4\n" +
96-
"Copyright (C) 2020 The Android Open Source Project\n" +
97-
"\n" +
98-
"Licensed under the Apache License, Version 2.0 (the \"License\");\n" +
99-
"you may not use this file except in compliance with the License.\n" +
100-
"You may obtain a copy of the License at\n" +
101-
"\n" +
102-
"http://www.apache.org/licenses/LICENSE-2.0\n" +
103-
"\n" +
104-
"Unless required by applicable law or agreed to in writing, software\n" +
105-
"distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
106-
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
107-
"See the License for the specific language governing permissions and\n" +
108-
"limitations under the License.\n"
109-
},
98+
AdditionalInformation = PerfettoCds.PerfettoCopyrightLicense,
11099
};
111100
}
112101

@@ -127,4 +116,95 @@ protected override void SetApplicationEnvironmentCore(IApplicationEnvironment ap
127116
this.applicationEnvironment = applicationEnvironment;
128117
}
129118
}
119+
120+
[ProcessingSource("DAAF538C-8482-4CDA-A477-7A4BD5F1EFEA", "ChromiumDevToolsExportDataSource", "Processes .json Chromium DevTools Perf profile export")]
121+
[FileDataSource(".json", "Chromium DevTools Perf profile export")]
122+
public sealed class ChromiumDevToolsExportDataSource : ProcessingSource
123+
{
124+
private IApplicationEnvironment applicationEnvironment;
125+
126+
protected override ICustomDataProcessor CreateProcessorCore(IEnumerable<IDataSource> dataSources, IProcessorEnvironment processorEnvironment, ProcessorOptions options)
127+
{
128+
var filePath = dataSources.First().Uri.LocalPath;
129+
var parser = new PerfettoSourceParser(filePath);
130+
return new PerfettoDataProcessor(parser,
131+
options,
132+
this.applicationEnvironment,
133+
processorEnvironment);
134+
}
135+
136+
public override ProcessingSourceInfo GetAboutInfo()
137+
{
138+
return new ProcessingSourceInfo()
139+
{
140+
ProjectInfo = new ProjectInfo() { Uri = "https://aka.ms/linuxperftools" },
141+
CopyrightNotice = "Copyright (C) " + DateTime.UtcNow.Year,
142+
AdditionalInformation = PerfettoCds.PerfettoCopyrightLicense,
143+
};
144+
}
145+
146+
protected override bool IsDataSourceSupportedCore(IDataSource dataSource)
147+
{
148+
if (dataSource.IsDirectory())
149+
{
150+
return false;
151+
}
152+
153+
var ext = Path.GetExtension(dataSource.Uri.LocalPath);
154+
155+
return dataSource.IsFile() && StringComparer.OrdinalIgnoreCase.Equals(".json", ext);
156+
}
157+
158+
protected override void SetApplicationEnvironmentCore(IApplicationEnvironment applicationEnvironment)
159+
{
160+
this.applicationEnvironment = applicationEnvironment;
161+
}
162+
}
163+
164+
[ProcessingSource("E352CC69-5991-45E0-B329-4C4071BA7CFD", "GZipPerfettoDataSource", "Processes .gz json from chrome://tracing legacy UI")]
165+
[FileDataSource(".gz", ".gz chrome://tracing legacy UI or other Perfetto .gz")]
166+
public sealed class GZipPerfettoDataSource : ProcessingSource
167+
{
168+
private IApplicationEnvironment applicationEnvironment;
169+
170+
protected override ICustomDataProcessor CreateProcessorCore(IEnumerable<IDataSource> dataSources, IProcessorEnvironment processorEnvironment, ProcessorOptions options)
171+
{
172+
var filePath = dataSources.First().Uri.LocalPath;
173+
var parser = new PerfettoSourceParser(filePath);
174+
return new PerfettoDataProcessor(parser,
175+
options,
176+
this.applicationEnvironment,
177+
processorEnvironment);
178+
}
179+
180+
public override ProcessingSourceInfo GetAboutInfo()
181+
{
182+
return new ProcessingSourceInfo()
183+
{
184+
ProjectInfo = new ProjectInfo() { Uri = "https://aka.ms/linuxperftools" },
185+
CopyrightNotice = "Copyright (C) " + DateTime.UtcNow.Year,
186+
AdditionalInformation = PerfettoCds.PerfettoCopyrightLicense,
187+
};
188+
}
189+
190+
protected override bool IsDataSourceSupportedCore(IDataSource dataSource)
191+
{
192+
if (dataSource.IsDirectory())
193+
{
194+
return false;
195+
}
196+
197+
var ext = Path.GetExtension(dataSource.Uri.LocalPath);
198+
199+
return dataSource.IsFile() && StringComparer.OrdinalIgnoreCase.Equals(".gz", ext) &&
200+
( dataSource.Uri.LocalPath.EndsWith(".json.gz") ||
201+
dataSource.Uri.LocalPath.EndsWith("pftrace.gz") ||
202+
dataSource.Uri.LocalPath.EndsWith("perfetto-trace.gz") );
203+
}
204+
205+
protected override void SetApplicationEnvironmentCore(IApplicationEnvironment applicationEnvironment)
206+
{
207+
this.applicationEnvironment = applicationEnvironment;
208+
}
209+
}
130210
}

0 commit comments

Comments
 (0)