]> git.cworth.org Git - apitrace/blob - trace_loader.hpp
Time scanning of the file and a few frame reads.
[apitrace] / trace_loader.hpp
1 #ifndef TRACE_LOADER_HPP
2 #define TRACE_LOADER_HPP
3
4 #include "trace_file.hpp"
5 #include "trace_parser.hpp"
6
7 #include <string>
8 #include <map>
9 #include <queue>
10 #include <vector>
11
12 namespace Trace  {
13
14 class Frame;
15
16 class Loader
17 {
18 public:
19     enum FrameMarker {
20         FrameMarker_SwapBuffers,
21         FrameMarker_Flush,
22         FrameMarker_Finish,
23         FrameMarker_Clear
24     };
25 public:
26     Loader();
27     ~Loader();
28
29     Loader::FrameMarker frameMarker() const;
30     void setFrameMarker(Loader::FrameMarker marker);
31
32     int numberOfFrames() const;
33     int numberOfCallsInFrame(int frameIdx) const;
34
35     bool open(const char *filename);
36     void close();
37
38     std::vector<Trace::Call*> frame(int idx);
39
40 private:
41     struct FrameOffset {
42         FrameOffset()
43             : numberOfCalls(0)
44         {}
45         FrameOffset(const File::Offset &s)
46             : start(s),
47               numberOfCalls(0)
48         {}
49
50         File::Offset start;
51         int numberOfCalls;
52         unsigned callNumber;
53     };
54     bool isCallAFrameMarker(const Trace::Call *call) const;
55
56 private:
57     Trace::Parser m_parser;
58     FrameMarker m_frameMarker;
59
60     std::map<int, Trace::Frame*> m_frameCache;
61     std::queue<Trace::Frame*> m_loadedFrames;
62
63     typedef std::map<int, FrameOffset> FrameOffsets;
64     FrameOffsets m_frameOffsets;
65
66     Trace::File *file;
67 };
68
69 }
70
71 #endif // TRACE_LOADER_HPP