process.h 3.02 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright 2021 Max Planck Institute for Software Systems, and
 * National University of Singapore
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

Antoine Kaufmann's avatar
Antoine Kaufmann committed
25
26
#pragma once

27
#include <boost/coroutine2/all.hpp>
28
#include <boost/iostreams/filtering_streambuf.hpp>
Antoine Kaufmann's avatar
Antoine Kaufmann committed
29
#include <map>
30
#include <memory>
Antoine Kaufmann's avatar
Antoine Kaufmann committed
31
32
#include <set>
#include <string>
33

Antoine Kaufmann's avatar
Antoine Kaufmann committed
34
#include "trace/events.h"
Antoine Kaufmann's avatar
Antoine Kaufmann committed
35

36
37
typedef boost::coroutines2::asymmetric_coroutine<std::shared_ptr<event>> coro_t;

Antoine Kaufmann's avatar
Antoine Kaufmann committed
38
class sym_map {
39
40
41
42
 protected:
  bool filter_en;
  bool insmap_en;
  std::set<std::string> filter;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
43

44
45
46
 public:
  std::map<uint64_t, std::string> map;
  std::map<uint64_t, std::string> map_ins;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
47

48
  sym_map();
49

50
51
  void add_filter(const std::string &sym);
  void load_file(const char *path, uint64_t offset = 0);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
52

53
54
55
56
  inline const std::string *lookup(uint64_t addr) {
    auto it = map.find(addr);
    if (it == map.end())
      return nullptr;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
57

58
59
    return &it->second;
  }
Antoine Kaufmann's avatar
Antoine Kaufmann committed
60
};
61
62

class log_parser {
63
64
 protected:
  std::istream *inf;
65

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

69
70
71
72
  static const size_t block_size = 16 * 1024 * 1024;
  char *buf;
  size_t buf_len;
  size_t buf_pos;
73

74
75
76
  coro_t::push_type *sink;
  bool got_event;

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

81
82
83
  bool next_event();
  void yield(std::shared_ptr<event> ev);

84
85
 public:
  const char *label;
86

87
88
89
90
  log_parser();
  virtual ~log_parser();
  void open(const char *path);
  void open_gz(const char *path);
91

92
  void read_coro(coro_t::push_type &sink_);
93
94
95
};

class gem5_parser : public log_parser {
96
97
 protected:
  sym_map &syms;
98
  std::shared_ptr<EHostInstr> prevInstr;
99

100
101
102
  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);
103

104
 public:
105
  explicit gem5_parser(sym_map &syms_);
106
  virtual ~gem5_parser();
107
};
108
109

class nicbm_parser : public log_parser {
110
111
 protected:
  virtual void process_line(char *line, size_t len);
112

113
114
 public:
  virtual ~nicbm_parser();
115
};