blob: 2e7ac9c8040d2b9cd963dec7d53ec427c2d38c20 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_BASIC_BLOCK_PROFILER_H_
6#define V8_BASIC_BLOCK_PROFILER_H_
7
8#include <iosfwd>
9#include <list>
10#include <string>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000011#include <vector>
Emily Bernierd0a1eb72015-03-24 16:35:39 -040012
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013#include "src/base/macros.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040014
15namespace v8 {
16namespace internal {
17
Emily Bernierd0a1eb72015-03-24 16:35:39 -040018class BasicBlockProfiler {
19 public:
20 class Data {
21 public:
22 size_t n_blocks() const { return n_blocks_; }
23 const uint32_t* counts() const { return &counts_[0]; }
24
25 void SetCode(std::ostringstream* os);
26 void SetFunctionName(std::ostringstream* os);
27 void SetSchedule(std::ostringstream* os);
28 void SetBlockId(size_t offset, size_t block_id);
29 uint32_t* GetCounterAddress(size_t offset);
30
31 private:
32 friend class BasicBlockProfiler;
33 friend std::ostream& operator<<(std::ostream& os,
34 const BasicBlockProfiler::Data& s);
35
36 explicit Data(size_t n_blocks);
37 ~Data();
38
39 void ResetCounts();
40
41 const size_t n_blocks_;
42 std::vector<size_t> block_ids_;
43 std::vector<uint32_t> counts_;
44 std::string function_name_;
45 std::string schedule_;
46 std::string code_;
47 DISALLOW_COPY_AND_ASSIGN(Data);
48 };
49
50 typedef std::list<Data*> DataList;
51
52 BasicBlockProfiler();
53 ~BasicBlockProfiler();
54
55 Data* NewData(size_t n_blocks);
56 void ResetCounts();
57
58 const DataList* data_list() { return &data_list_; }
59
60 private:
61 friend std::ostream& operator<<(std::ostream& os,
62 const BasicBlockProfiler& s);
63
64 DataList data_list_;
65
66 DISALLOW_COPY_AND_ASSIGN(BasicBlockProfiler);
67};
68
69std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler& s);
70std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler::Data& s);
71
72} // namespace internal
73} // namespace v8
74
75#endif // V8_BASIC_BLOCK_PROFILER_H_