diff options
author | Matheus Marchini <matheus@sthima.com> | 2018-06-04 09:33:17 -0700 |
---|---|---|
committer | Matheus Marchini <matheus@sthima.com> | 2018-06-22 09:42:46 -0700 |
commit | b3627560a94eaf51262cc041aebc9ef150b5fcbc (patch) | |
tree | 6f8cdb5e15f0bc7e686b018f952b21556cc6b91b /deps/v8/test/cctest | |
parent | 8689c785379293adc04ec2a3d47ed08a580fe521 (diff) | |
download | android-node-v8-b3627560a94eaf51262cc041aebc9ef150b5fcbc.tar.gz android-node-v8-b3627560a94eaf51262cc041aebc9ef150b5fcbc.tar.bz2 android-node-v8-b3627560a94eaf51262cc041aebc9ef150b5fcbc.zip |
deps: backport aa6ce3e from upstream V8
Original commit message:
[log][api] introduce public CodeEventListener API
Introduce a new public API called CodeEventListener to allow
embedders to better support external profilers and other diagnostic
tools without relying on unsupported methods like --perf-basic-prof.
Bug: v8:7694
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I063cc965394d59401358757634c9ea84c11517e9
Co-authored-by: Daniel Beckert <daniel@sthima.com.br>
Reviewed-on: https://chromium-review.googlesource.com/1028770
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53382}
Refs: https://github.com/v8/v8/commit/aa6ce3ee617b2f324bea3a5d8e3263aee
PR-URL: https://github.com/nodejs/node/pull/21126
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'deps/v8/test/cctest')
-rw-r--r-- | deps/v8/test/cctest/test-log.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/deps/v8/test/cctest/test-log.cc b/deps/v8/test/cctest/test-log.cc index c9a521fcae..3f8b0a5178 100644 --- a/deps/v8/test/cctest/test-log.cc +++ b/deps/v8/test/cctest/test-log.cc @@ -35,6 +35,7 @@ #endif // __linux__ #include <unordered_set> +#include <vector> #include "src/api.h" #include "src/log-utils.h" #include "src/log.h" @@ -251,6 +252,38 @@ class ScopedLoggerInitializer { DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); }; +class TestCodeEventHandler : public v8::CodeEventHandler { + public: + explicit TestCodeEventHandler(v8::Isolate* isolate) + : v8::CodeEventHandler(isolate) {} + + const char* FindLine(const char* prefix, const char* suffix = nullptr, + const char* start = nullptr) { + if (!log_.length()) return NULL; + const char* c_log = log_.c_str(); + if (start == nullptr) start = c_log; + const char* end = c_log + log_.length(); + return FindLogLine(start, end, prefix, suffix); + } + + void Handle(v8::CodeEvent* code_event) override { + const char* code_type = + v8::CodeEvent::GetCodeEventTypeName(code_event->GetCodeType()); + char function_name[1000]; + strncpy(function_name, code_type, 1000); + function_name[strlen(code_type)] = ' '; + code_event->GetFunctionName()->WriteUtf8( + function_name + strlen(code_type) + 1, 1000); + function_name[strlen(function_name) + 1] = '\0'; + function_name[strlen(function_name)] = '\n'; + + log_ += std::string(function_name); + } + + private: + std::string log_; +}; + } // namespace TEST(FindLogLine) { @@ -801,6 +834,48 @@ TEST(LogInterpretedFramesNativeStack) { isolate->Dispose(); } +TEST(ExternalCodeEventListener) { + i::FLAG_log = false; + i::FLAG_prof = false; + + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); + + { + v8::HandleScope scope(isolate); + v8::Isolate::Scope isolate_scope(isolate); + v8::Local<v8::Context> context = v8::Context::New(isolate); + context->Enter(); + + TestCodeEventHandler code_event_handler(isolate); + + const char* source_text_before_start = + "function testCodeEventListenerBeforeStart(a,b) { return a + b };" + "testCodeEventListenerBeforeStart('1', 1);"; + CompileRun(source_text_before_start); + + CHECK_NULL(code_event_handler.FindLine("LazyCompile", + "testCodeEventListenerBeforeStart")); + + code_event_handler.Enable(); + + CHECK_NOT_NULL(code_event_handler.FindLine( + "LazyCompile", "testCodeEventListenerBeforeStart")); + + const char* source_text_after_start = + "function testCodeEventListenerAfterStart(a,b) { return a + b };" + "testCodeEventListenerAfterStart('1', 1);"; + CompileRun(source_text_after_start); + + CHECK_NOT_NULL(code_event_handler.FindLine( + "LazyCompile", "testCodeEventListenerAfterStart")); + + context->Exit(); + } + isolate->Dispose(); +} + TEST(TraceMaps) { SETUP_FLAGS(); i::FLAG_trace_maps = true; |