Skip to content

Commit 2972cb8

Browse files
committed
Timeline can load and ignore empty tracks in the timeline data
1 parent 6133c9c commit 2972cb8

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

CompileScore/Shared/Timeline/CompilerTimeline.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ private TimelineNode BuildTimelineTree(BinaryReader reader)
153153
{
154154
uint numEvents = reader.ReadUInt32();
155155

156+
if (numEvents == 0)
157+
{
158+
return null;
159+
}
160+
156161
TimelineNode root = new TimelineNode(CompilerData.CompileCategory.Thread.ToString(), 0, 0, CompilerData.CompileCategory.Thread);
157162

158163
TimelineNode parent = root;
@@ -226,6 +231,12 @@ private TimelineNode BuildTimelineRoot(BinaryReader reader, UnitValue unit)
226231
{
227232
TimelineNode tree = BuildTimelineTree(reader);
228233

234+
if ( tree == null )
235+
{
236+
//skip invalid and empty tracks
237+
continue;
238+
}
239+
229240
if (tree.Children.Count > 0 && tree.Children[0].Category == CompilerData.CompileCategory.ExecuteCompiler)
230241
{
231242
//skip the thread for the main track

DataExtractor/src/Extractors/ClangScore.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace Clang
1818

1919
namespace Utils
2020
{
21+
// -----------------------------------------------------------------------------------------------------------
22+
template <typename T> inline constexpr T Min( const T a, const T b ) { return a < b ? a : b; }
23+
2124
//------------------------------------------------------------------------------------------
2225
constexpr size_t StrLength(const char* str)
2326
{
@@ -275,21 +278,33 @@ namespace Clang
275278
// -----------------------------------------------------------------------------------------------------------
276279
void NormalizeStartTimes(const char* path, CompileUnitContext& context, ScoreTimeline& timeline)
277280
{
278-
TCompileEvents& events = timeline.tracks[0];
279-
280-
if (!events.empty())
281+
//Retrieve the first event start time
282+
U32 offset = 0u;
283+
for ( size_t i = 0, sz = timeline.tracks.size(); i < sz; ++i)
281284
{
282-
const U32 offset = events[0].start;
285+
const TCompileEvents& events = timeline.tracks[i];
286+
offset = events.empty() ? offset : Utils::Min( events[0].start, offset);
287+
}
283288

284-
//Base the start times on the .json creation time instead of relying on consistent in json wall clock time
285-
const U64 fileEndTime = IO::GetLastWriteTimeInMicros(path);
286-
const U64 fileStartTime = fileEndTime - events[0].duration;
287-
context.startTime[0] = fileStartTime + (context.startTime[0] - offset);
288-
context.startTime[1] = fileStartTime + (context.startTime[1] - offset);
289+
//Offset all events
290+
if ( offset > 0u )
291+
{
292+
for( size_t i = 0, sz = timeline.tracks.size(); i < sz; ++i )
293+
{
294+
TCompileEvents& events = timeline.tracks[i];
295+
if( !events.empty() )
296+
{
297+
//Base the start times on the .json creation time instead of relying on consistent in json wall clock time
298+
const U64 fileEndTime = IO::GetLastWriteTimeInMicros( path );
299+
const U64 fileStartTime = fileEndTime - events[ 0 ].duration;
300+
context.startTime[ 0 ] = fileStartTime + ( context.startTime[ 0 ] - offset );
301+
context.startTime[ 1 ] = fileStartTime + ( context.startTime[ 1 ] - offset );
289302

290-
for (CompileEvent& entry : events)
291-
{
292-
entry.start -= offset;
303+
for( CompileEvent& entry : events )
304+
{
305+
entry.start -= offset;
306+
}
307+
}
293308
}
294309
}
295310
}

0 commit comments

Comments
 (0)