1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef _TRACE_READER |
6 | #define _TRACE_READER |
7 | |
8 | #include <string> |
9 | #include <vector> |
10 | #include "event_man.h" |
11 | |
12 | typedef struct tagMapsEntry{ |
13 | long offset; /*offset in trace file*/ |
14 | double time; /*unit is millisecond*/ |
15 | }MapsEntry; |
16 | |
17 | |
18 | /////////////////////////////////////////////////////////////////////////////// |
19 | // TraceReader |
20 | // |
21 | class TraceReader{ |
22 | public: |
23 | TraceReader(void); |
24 | ~TraceReader(void); |
25 | bool Open(const char* filename, bool zstd = false); |
26 | bool BuildEventTable(std::vector<EventEntry>* table); |
27 | bool BuildMapsTable(std::vector<MapsEntry>* table); |
28 | bool Seek(long offset/*relative to file begin*/); |
29 | long Current(void) { return ftell(fin);}; |
30 | |
31 | /*NOTE: block-size-field occupied 4bytes*/ |
32 | int ReadBlock(std::string& out); |
33 | |
34 | /*NOTE: no block-size-field field*/ |
35 | int ReadBlock(void* buf, int size); |
36 | |
37 | template <typename T> bool ReadValue(T* ptr) { |
38 | return fread(ptr, 1, sizeof(T), fin) == sizeof(T); |
39 | } |
40 | |
41 | private: |
42 | FILE* fin; |
43 | long fsize; |
44 | }; |
45 | |
46 | #endif /*end #ifndef _TRACE_READER*/ |
47 | |