| Ben Murdoch | 62ed631 | 2017-06-06 11:06:27 +0100 | [diff] [blame] | 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 <vector> |
| 9 | |
| 10 | #include "src/debug/debug-interface.h" |
| 11 | #include "src/objects.h" |
| 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
| 16 | // Forward declaration. |
| 17 | class Isolate; |
| 18 | |
| 19 | struct CoverageFunction { |
| 20 | CoverageFunction(int s, int e, uint32_t c, Handle<String> n) |
| 21 | : start(s), end(e), count(c), name(n) {} |
| 22 | int start; |
| 23 | int end; |
| 24 | uint32_t count; |
| 25 | Handle<String> name; |
| 26 | }; |
| 27 | |
| 28 | struct CoverageScript { |
| 29 | // Initialize top-level function in case it has been garbage-collected. |
| 30 | CoverageScript(Isolate* isolate, Handle<Script> s) : script(s) {} |
| 31 | Handle<Script> script; |
| 32 | // Functions are sorted by start position, from outer to inner function. |
| 33 | std::vector<CoverageFunction> functions; |
| 34 | }; |
| 35 | |
| 36 | class Coverage : public std::vector<CoverageScript> { |
| 37 | public: |
| 38 | // Allocate a new Coverage object and populate with result. |
| 39 | // The ownership is transferred to the caller. |
| 40 | static Coverage* Collect(Isolate* isolate, bool reset_count); |
| 41 | |
| 42 | // Enable precise code coverage. This disables optimization and makes sure |
| 43 | // invocation count is not affected by GC. |
| 44 | static void TogglePrecise(Isolate* isolate, bool enable); |
| 45 | |
| 46 | private: |
| 47 | Coverage() {} |
| 48 | }; |
| 49 | |
| 50 | } // namespace internal |
| 51 | } // namespace v8 |
| 52 | |
| 53 | #endif // V8_DEBUG_DEBUG_COVERAGE_H_ |