basic-block-profiler.h 2.09 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_BASIC_BLOCK_PROFILER_H_
#define V8_BASIC_BLOCK_PROFILER_H_

8
#include <iosfwd>
9
#include <list>
10
#include <string>
11
#include <vector>
12

13
#include "src/base/macros.h"
14
#include "src/base/platform/mutex.h"
15
#include "src/globals.h"
16 17 18 19 20 21 22 23 24 25 26

namespace v8 {
namespace internal {

class BasicBlockProfiler {
 public:
  class Data {
   public:
    size_t n_blocks() const { return n_blocks_; }
    const uint32_t* counts() const { return &counts_[0]; }

27
    void SetCode(std::ostringstream* os);
28
    void SetFunctionName(std::unique_ptr<char[]> name);
29
    void SetSchedule(std::ostringstream* os);
30 31
    void SetBlockRpoNumber(size_t offset, int32_t block_rpo);
    intptr_t GetCounterAddress(size_t offset);
32 33 34

   private:
    friend class BasicBlockProfiler;
35 36
    friend std::ostream& operator<<(std::ostream& os,
                                    const BasicBlockProfiler::Data& s);
37 38

    explicit Data(size_t n_blocks);
39
    ~Data() = default;
40 41 42 43

    void ResetCounts();

    const size_t n_blocks_;
44
    std::vector<int32_t> block_rpo_numbers_;
45 46 47 48 49 50 51 52 53
    std::vector<uint32_t> counts_;
    std::string function_name_;
    std::string schedule_;
    std::string code_;
    DISALLOW_COPY_AND_ASSIGN(Data);
  };

  typedef std::list<Data*> DataList;

54
  BasicBlockProfiler() = default;
55 56
  ~BasicBlockProfiler();

57
  V8_EXPORT_PRIVATE static BasicBlockProfiler* Get();
58 59 60 61 62 63
  Data* NewData(size_t n_blocks);
  void ResetCounts();

  const DataList* data_list() { return &data_list_; }

 private:
64 65
  friend V8_EXPORT_PRIVATE std::ostream& operator<<(
      std::ostream& os, const BasicBlockProfiler& s);
66 67

  DataList data_list_;
68
  base::Mutex data_list_mutex_;
69 70 71 72

  DISALLOW_COPY_AND_ASSIGN(BasicBlockProfiler);
};

73 74
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
                                           const BasicBlockProfiler& s);
75
std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler::Data& s);
76 77 78 79 80

}  // namespace internal
}  // namespace v8

#endif  // V8_BASIC_BLOCK_PROFILER_H_