/ libevmjit / ExecStats.h
ExecStats.h
 1  #pragma once
 2  
 3  #include <memory>
 4  #include <vector>
 5  #include <string>
 6  #include <chrono>
 7  
 8  namespace dev
 9  {
10  namespace evmjit
11  {
12  
13  enum class ExecState
14  {
15  	Started,
16  	CacheLoad,
17  	CacheWrite,
18  	Compilation,
19  	Optimization,
20  	CodeGen,
21  	Execution,
22  	Return,
23  	Finished
24  };
25  
26  class JITListener
27  {
28  public:
29  	JITListener() = default;
30  	JITListener(JITListener const&) = delete;
31  	JITListener& operator=(JITListener) = delete;
32  	virtual ~JITListener() {}
33  
34  	virtual void executionStarted() {}
35  	virtual void executionEnded() {}
36  
37  	virtual void stateChanged(ExecState) {}
38  };
39  
40  class ExecStats : public JITListener
41  {
42  public:
43  	using clock = std::chrono::high_resolution_clock;
44  	using duration = clock::duration;
45  	using time_point = clock::time_point;
46  
47  	std::string id;
48  	duration time[(int)ExecState::Finished] = {};
49  
50  	void stateChanged(ExecState _state) override;
51  
52  private:
53  	ExecState m_state = {};
54  	time_point m_tp = {};
55  
56  };
57  
58  
59  class StatsCollector
60  {
61  public:
62  	std::vector<std::unique_ptr<ExecStats>> stats;
63  
64  	~StatsCollector();
65  };
66  
67  }
68  }