process.h 1.46 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
#pragma once

#include <map>
#include <set>
#include <string>
6
7
8
#include <boost/iostreams/filtering_streambuf.hpp>

#include "events.h"
Antoine Kaufmann's avatar
Antoine Kaufmann committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

class sym_map {
  protected:
    bool filter_en;
    bool insmap_en;
    std::set<std::string> filter;

  public:
    std::map<uint64_t, std::string> map;
    std::map<uint64_t, std::string> map_ins;

    void add_filter(const std::string &sym);
    void load_file(const char *path, uint64_t offset = 0);

    inline const std::string *lookup(uint64_t addr)
    {
        auto it = map.find(addr);
        if (it == map.end())
            return nullptr;

        return &it->second;
    }
};
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

class log_parser {
  protected:
    std::istream *inf;

    std::ifstream *gz_file;
    boost::iostreams::filtering_streambuf<boost::iostreams::input> *gz_in;

    static const size_t block_size = 16 * 1024 * 1024;
    char *buf;
    size_t buf_len;
    size_t buf_pos;

    bool next_block();
    size_t try_line();
    virtual void process_line(char *line, size_t len) = 0;

  public:
    event *cur_event;

    log_parser();
    virtual ~log_parser();
    void open(const char *path);
    void open_gz(const char *path);

    bool next_event();
};

class gem5_parser : public log_parser {
  protected:
    sym_map &syms;

    virtual void process_line(char *line, size_t len);
    void process_msg(uint64_t ts, char *comp_name, size_t comp_name_len,
            char *msg, size_t msg_len);

  public:
    gem5_parser(sym_map &syms_);
    virtual ~gem5_parser();
};