Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1 | // 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> |
| 11 | |
| 12 | #include "src/v8.h" |
| 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
| 17 | class Schedule; |
| 18 | class Graph; |
| 19 | |
| 20 | class BasicBlockProfiler { |
| 21 | public: |
| 22 | class Data { |
| 23 | public: |
| 24 | size_t n_blocks() const { return n_blocks_; } |
| 25 | const uint32_t* counts() const { return &counts_[0]; } |
| 26 | |
| 27 | void SetCode(std::ostringstream* os); |
| 28 | void SetFunctionName(std::ostringstream* os); |
| 29 | void SetSchedule(std::ostringstream* os); |
| 30 | void SetBlockId(size_t offset, size_t block_id); |
| 31 | uint32_t* GetCounterAddress(size_t offset); |
| 32 | |
| 33 | private: |
| 34 | friend class BasicBlockProfiler; |
| 35 | friend std::ostream& operator<<(std::ostream& os, |
| 36 | const BasicBlockProfiler::Data& s); |
| 37 | |
| 38 | explicit Data(size_t n_blocks); |
| 39 | ~Data(); |
| 40 | |
| 41 | void ResetCounts(); |
| 42 | |
| 43 | const size_t n_blocks_; |
| 44 | std::vector<size_t> block_ids_; |
| 45 | std::vector<uint32_t> counts_; |
| 46 | std::string function_name_; |
| 47 | std::string schedule_; |
| 48 | std::string code_; |
| 49 | DISALLOW_COPY_AND_ASSIGN(Data); |
| 50 | }; |
| 51 | |
| 52 | typedef std::list<Data*> DataList; |
| 53 | |
| 54 | BasicBlockProfiler(); |
| 55 | ~BasicBlockProfiler(); |
| 56 | |
| 57 | Data* NewData(size_t n_blocks); |
| 58 | void ResetCounts(); |
| 59 | |
| 60 | const DataList* data_list() { return &data_list_; } |
| 61 | |
| 62 | private: |
| 63 | friend std::ostream& operator<<(std::ostream& os, |
| 64 | const BasicBlockProfiler& s); |
| 65 | |
| 66 | DataList data_list_; |
| 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(BasicBlockProfiler); |
| 69 | }; |
| 70 | |
| 71 | std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler& s); |
| 72 | std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler::Data& s); |
| 73 | |
| 74 | } // namespace internal |
| 75 | } // namespace v8 |
| 76 | |
| 77 | #endif // V8_BASIC_BLOCK_PROFILER_H_ |