The code I took from gist (I assume it is yours) was crashing when I ran it to see the stats (localtime returns null).
I investigated the problem, it was checking that the file time is less than some value and it fails.
I realized that I was running -stats using your version of the tool on a file generated by the original version.
The time values generated by the original seems to be much larger than the ones generated by your version.
The original uses win32 function to get the file time in 100-nano seconds while yours is using time function which returns milliseconds.
So you version is actually OK (if you don't care about compatibility).
But yours has the same bug as the original when running -stats on a file with one entry.
However, Both versions (yours and the original) are crashing whenever you invoke -stats on a file that has one entry (after running -begin/-end once):
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 | double FirstDayAt = 0;
double LastDayAt = 0;
double DaySpan = 0;
graph TotalGraph = {0};
graph RecentGraph = {0};
WithErrors.FastestMs = 0xFFFFFFFF;
NoErrors.FastestMs = 0xFFFFFFFF;
// NOTE
// if this condition is false (when EntryCount is one)
// FirstDayAt will stay zero
if(Array.EntryCount >= 2)
{
double MilliD = MillisecondDifference(Array.Entries[Array.EntryCount - 1].StartDate, Array.Entries[0].StartDate);
DaySpanCount = (int unsigned)(MilliD / (1000.0 * 60.0 * 60.0 * 24.0));
FirstDayAt = (double)DayIndex(Array.Entries[0].StartDate);
LastDayAt = (double)DayIndex(Array.Entries[Array.EntryCount - 1].StartDate);
DaySpan = (LastDayAt - FirstDayAt);
}
DaySpan += 1;
for(EntryIndex = 0;
EntryIndex < Array.EntryCount;
++EntryIndex, ++Entry)
{
if(Entry->Flags & TFEF_Complete)
{
stat_group *Group = (Entry->Flags & TFEF_NoErrors) ? &NoErrors : &WithErrors;
int unsigned ThisDayIndex = DayIndex(Entry->StartDate);
if(LastDayIndex != ThisDayIndex)
{
LastDayIndex = ThisDayIndex;
++DaysWithTimingCount;
}
UpdateStatGroup(Group, Entry);
UpdateStatGroup(&AllStats, Entry);
AllMs += (double)Entry->MillisecondsElapsed;
{
//
// The GraphIndex is bogus (very large) because FirstDayAt is zero
// And the crash happens inside UpdateStatGroup
//
int GraphIndex = (int)(((double)(ThisDayIndex-FirstDayAt)/DaySpan)*(double)GRAPH_WIDTH);
UpdateStatGroup(TotalGraph.Buckets + GraphIndex, Entry);
}
|