v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
debug-coverage.h
Go to the documentation of this file.
1// Copyright 2017 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_DEBUG_DEBUG_COVERAGE_H_
6#define V8_DEBUG_DEBUG_COVERAGE_H_
7
8#include <memory>
9#include <vector>
10
12#include "src/handles/handles.h"
13
14namespace v8 {
15namespace internal {
16
17// Forward declaration.
18class Isolate;
19
21 CoverageBlock(int s, int e, uint32_t c) : start(s), end(e), count(c) {}
23
24 int start;
25 int end;
26 uint32_t count;
27};
28
30 CoverageFunction(int s, int e, uint32_t c, Handle<String> n)
31 : start(s), end(e), count(c), name(n), has_block_coverage(false) {}
32
34 bool HasBlocks() const { return !blocks.empty(); }
35
36 int start;
37 int end;
38 uint32_t count;
40 // Blocks are sorted by start position, from outer to inner blocks.
41 std::vector<CoverageBlock> blocks;
43};
44
46 // Initialize top-level function in case it has been garbage-collected.
47 explicit CoverageScript(Handle<Script> s) : script(s) {}
49 // Functions are sorted by start position, from outer to inner function.
50 std::vector<CoverageFunction> functions;
51};
52
53class Coverage : public std::vector<CoverageScript> {
54 public:
55 // Collecting precise coverage only works if the modes kPreciseCount or
56 // kPreciseBinary is selected. The invocation count is reset on collection.
57 // In case of kPreciseCount, an updated count since last collection is
58 // returned. In case of kPreciseBinary, a count of 1 is returned if a
59 // function has been executed for the first time since last collection.
60 static std::unique_ptr<Coverage> CollectPrecise(Isolate* isolate);
61 // Collecting best effort coverage always works, but may be imprecise
62 // depending on selected mode. The invocation count is not reset.
63 static std::unique_ptr<Coverage> CollectBestEffort(Isolate* isolate);
64
65 // Select code coverage mode.
66 V8_EXPORT_PRIVATE static void SelectMode(Isolate* isolate,
68
69 private:
70 static std::unique_ptr<Coverage> Collect(
71 Isolate* isolate, v8::debug::CoverageMode collectionMode);
72
73 Coverage() = default;
74};
75
76} // namespace internal
77} // namespace v8
78
79#endif // V8_DEBUG_DEBUG_COVERAGE_H_
static std::unique_ptr< Coverage > CollectPrecise(Isolate *isolate)
static V8_EXPORT_PRIVATE void SelectMode(Isolate *isolate, debug::CoverageMode mode)
static std::unique_ptr< Coverage > Collect(Isolate *isolate, v8::debug::CoverageMode collectionMode)
static std::unique_ptr< Coverage > CollectBestEffort(Isolate *isolate)
constexpr int kNoSourcePosition
Definition globals.h:850
#define V8_EXPORT_PRIVATE
Definition macros.h:460
CoverageBlock(int s, int e, uint32_t c)
std::vector< CoverageBlock > blocks
CoverageFunction(int s, int e, uint32_t c, Handle< String > n)
std::vector< CoverageFunction > functions
CoverageScript(Handle< Script > s)