-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracing.hpp
59 lines (49 loc) · 1.75 KB
/
tracing.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2021 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "evmc/instructions.h"
#include <memory>
#include <ostream>
#include <string>
namespace evmone
{
using bytes_view = std::basic_string<uint8_t>;
class Tracer
{
friend class VM; // Has access the the m_next_tracer to traverse the list forward.
std::unique_ptr<Tracer> m_next_tracer;
public:
virtual ~Tracer() = default;
void notify_execution_start(
evmc_revision rev, const evmc_message& msg, bytes_view code) noexcept
{
on_execution_start(rev, msg, code);
if (m_next_tracer)
m_next_tracer->notify_execution_start(rev, msg, code);
}
void notify_execution_end(const evmc_result& result) noexcept // NOLINT(misc-no-recursion)
{
on_execution_end(result);
if (m_next_tracer)
m_next_tracer->notify_execution_end(result);
}
void notify_instruction_start(uint32_t pc) noexcept // NOLINT(misc-no-recursion)
{
on_instruction_start(pc);
if (m_next_tracer)
m_next_tracer->notify_instruction_start(pc);
}
private:
virtual void on_execution_start(
evmc_revision rev, const evmc_message& msg, bytes_view code) noexcept = 0;
virtual void on_instruction_start(uint32_t pc) noexcept = 0;
virtual void on_execution_end(const evmc_result& result) noexcept = 0;
};
/// Creates the "histogram" tracer which counts occurrences of individual opcodes during execution
/// and reports this data in CSV format.
///
/// @param out Report output stream.
/// @return Histogram tracer object.
EVMC_EXPORT std::unique_ptr<Tracer> create_histogram_tracer(std::ostream& out);
} // namespace evmone