summaryrefslogtreecommitdiffstats
path: root/Tools/compareTraces/TraceReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/compareTraces/TraceReader.cpp')
-rw-r--r--Tools/compareTraces/TraceReader.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/Tools/compareTraces/TraceReader.cpp b/Tools/compareTraces/TraceReader.cpp
new file mode 100644
index 0000000..b4b9681
--- /dev/null
+++ b/Tools/compareTraces/TraceReader.cpp
@@ -0,0 +1,46 @@
+#include "stdafx.h"
+#include "TraceReader.h"
+using namespace Tracing;
+
+const sTraceItem& TraceReader::operator[]( size_t idx ) const
+{
+ if( idx >= countItems )
+ throw E_BOUNDS;
+ return items[ idx ];
+}
+
+CStringA TraceReader::getName( const sTraceItem& item ) const
+{
+ const size_t idx = item.stringIndex;
+ if( idx >= countStrings )
+ throw E_BOUNDS;
+ const char* const source = stringData + stringIndex[ idx ];
+ CStringA res;
+ res.Format( source, item.formatArgs[ 0 ], item.formatArgs[ 1 ], item.formatArgs[ 2 ], item.formatArgs[ 3 ] );
+ return res;
+}
+
+HRESULT TraceReader::open( LPCTSTR path )
+{
+ CHECK( file.Create( path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING ) );
+ CHECK( mapping.MapFile( file ) );
+
+ const uint8_t* rsi = mapping;
+ const sFileHeader& header = *(const sFileHeader*)rsi;
+ if( header.magic != header.correctMagic )
+ return E_INVALIDARG;
+ countItems = header.countItems;
+ countStrings = header.countStrings;
+
+ rsi += sizeof( sFileHeader );
+ payloadPointer = rsi;
+
+ rsi += header.bytesPayload;
+ stringIndex = (const uint32_t*)( rsi );
+ stringData = (const char*)( rsi + countStrings * 4 );
+
+ rsi += header.bytesStrings;
+ items = (const sTraceItem*)rsi;
+
+ return S_OK;
+} \ No newline at end of file