basic-block-profiler.h 1.93 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/globals.h"
15 16 17 18 19 20 21 22 23 24 25

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]; }

26 27 28
    void SetCode(std::ostringstream* os);
    void SetFunctionName(std::ostringstream* os);
    void SetSchedule(std::ostringstream* os);
29
    void SetBlockId(size_t offset, size_t block_id);
30 31 32 33
    uint32_t* GetCounterAddress(size_t offset);

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

    explicit Data(size_t n_blocks);
    ~Data();

    void ResetCounts();

    const size_t n_blocks_;
43
    std::vector<size_t> block_ids_;
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    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;

  BasicBlockProfiler();
  ~BasicBlockProfiler();

  Data* NewData(size_t n_blocks);
  void ResetCounts();

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

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

  DataList data_list_;

  DISALLOW_COPY_AND_ASSIGN(BasicBlockProfiler);
};

70 71
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
                                           const BasicBlockProfiler& s);
72
std::ostream& operator<<(std::ostream& os, const BasicBlockProfiler::Data& s);
73 74 75 76 77

}  // namespace internal
}  // namespace v8

#endif  // V8_BASIC_BLOCK_PROFILER_H_