forked from CobaltFusion/DebugViewPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnyFileReader.cpp
More file actions
88 lines (76 loc) · 2.43 KB
/
Copy pathAnyFileReader.cpp
File metadata and controls
88 lines (76 loc) · 2.43 KB
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
// (C) Copyright Gert-Jan de Vos and Jan Wilmans 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <cassert>
#include "DebugViewppLib/FileIO.h"
#include "DebugViewppLib/AnyFileReader.h"
#include "DebugViewppLib/LineBuffer.h"
#include "DebugViewppLib/Line.h"
#include "CobaltFusion/Str.h"
namespace fusion {
namespace debugviewpp {
AnyFileReader::AnyFileReader(Timer& timer, ILineBuffer& linebuffer, FileType::type filetype, const std::wstring& filename, bool keeptailing) :
FileReader(timer, linebuffer, filetype, filename, keeptailing),
m_linenumber(0),
m_filenameOnly(std::filesystem::path(m_filename).filename().wstring())
{
}
uint64_t FileTimeToUInt64(const FILETIME& ft)
{
ULARGE_INTEGER value;
value.LowPart = ft.dwLowDateTime;
value.HighPart = ft.dwHighDateTime;
return value.QuadPart;
}
double GetDifference(FILETIME ft1, FILETIME ft2)
{
return (FileTimeToUInt64(ft2) - FileTimeToUInt64(ft1)) * 100e-9;
}
// used to create a relative time from the systemtime when only systemtime is stored in Sysinternals DbgView files.
// the reverse (creating system-time from relative times) makes no sense.
void AnyFileReader::GetRelativeTime(Line& line)
{
if (line.time != 0.0)
{ // if relative time is already filled in do nothing
return;
}
if (m_linenumber == 1)
{
m_firstFiletime = line.systemTime;
return;
}
line.time = GetDifference(m_firstFiletime, line.systemTime);
}
void AnyFileReader::AddLine(const std::string& data)
{
++m_linenumber;
Line line;
switch (m_fileType)
{
case FileType::Unknown:
case FileType::AsciiText:
return FileReader::AddLine(data);
case FileType::Sysinternals:
ReadSysInternalsLogFileMessage(data, line, m_converter);
GetRelativeTime(line);
break;
case FileType::DebugViewPP1:
case FileType::DebugViewPP2:
if (m_linenumber == 1) // ignore the header line
{
return;
}
ReadLogFileMessage(data, line);
break;
default:
assert(false && "Unknown Filetype in AnyFileReader");
}
Add(line.time, line.systemTime, line.pid, line.processName, line.message);
}
void AnyFileReader::PreProcess(Line& line) const
{
line.processName = Str(m_filenameOnly).str();
}
} // namespace debugviewpp
} // namespace fusion