Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(932)

Unified Diff: test/cctest/test-cpu-profiler.cc

Issue 2396733002: [profiler] Tracing-based CPU profiler. (Closed)
Patch Set: Addressing comments + moving traced-value back to src/tracing Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/profiler/tracing-cpu-profiler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-cpu-profiler.cc
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc
index 2f92f54d37414fc9cba3de863db36987f619f0f7..7a3801ce34ee5f136c84444c759c77b21521b164 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -38,6 +38,9 @@
#include "test/cctest/cctest.h"
#include "test/cctest/profiler-extension.h"
+#include "include/libplatform/v8-tracing.h"
+#include "src/tracing/trace-event.h"
+
using i::CodeEntry;
using i::CpuProfile;
using i::CpuProfiler;
@@ -2098,3 +2101,79 @@ TEST(DeoptUntrackedFunction) {
iprofiler->DeleteProfile(iprofile);
}
+
+using v8::platform::tracing::TraceBuffer;
+using v8::platform::tracing::TraceConfig;
+using v8::platform::tracing::TraceObject;
+
+namespace {
+
+class CpuProfileEventChecker : public v8::platform::tracing::TraceWriter {
+ public:
+ void AppendTraceEvent(TraceObject* trace_event) override {
+ if (trace_event->name() != std::string("CpuProfile") &&
+ trace_event->name() != std::string("CpuProfileChunk"))
+ return;
+ CHECK(!profile_id_ || trace_event->id() == profile_id_);
+ CHECK_EQ(1, trace_event->num_args());
+ CHECK_EQ(TRACE_VALUE_TYPE_CONVERTABLE, trace_event->arg_types()[0]);
+ profile_id_ = trace_event->id();
+ v8::ConvertableToTraceFormat* arg =
+ trace_event->arg_convertables()[0].get();
+ arg->AppendAsTraceFormat(&result_json_);
+ }
+ void Flush() override {}
+
+ std::string result_json() const { return result_json_; }
+
+ private:
+ std::string result_json_;
+ uint64_t profile_id_ = 0;
+};
+
+} // namespace
+
+TEST(TracingCpuProfiler) {
+ v8::Platform* old_platform = i::V8::GetCurrentPlatform();
+ v8::Platform* default_platform = v8::platform::CreateDefaultPlatform();
+ i::V8::SetPlatformForTesting(default_platform);
+
+ v8::platform::tracing::TracingController tracing_controller;
+ v8::platform::SetTracingController(default_platform, &tracing_controller);
+
+ CpuProfileEventChecker* event_checker = new CpuProfileEventChecker();
+ TraceBuffer* ring_buffer =
+ TraceBuffer::CreateTraceBufferRingBuffer(1, event_checker);
+ tracing_controller.Initialize(ring_buffer);
+ TraceConfig* trace_config = new TraceConfig();
+ trace_config->AddIncludedCategory(
+ TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"));
+
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ {
+ tracing_controller.StartTracing(trace_config);
+ auto profiler = v8::TracingCpuProfiler::Create(env->GetIsolate());
+ CompileRun("function foo() { } foo();");
+ tracing_controller.StopTracing();
+ CompileRun("function bar() { } bar();");
+ }
+
+ const char* profile_checker =
+ "function checkProfile(profile) {\n"
+ " if (typeof profile['startTime'] !== 'number') return 'startTime';\n"
+ " return '';\n"
+ "}\n"
+ "checkProfile(";
+ std::string profile_json = event_checker->result_json();
+ CHECK_LT(0u, profile_json.length());
+ printf("Profile JSON: %s\n", profile_json.c_str());
+ std::string code = profile_checker + profile_json + ")";
+ v8::Local<v8::Value> result =
+ CompileRunChecked(CcTest::isolate(), code.c_str());
+ v8::String::Utf8Value value(result);
+ printf("Check result: %*s\n", value.length(), *value);
+ CHECK_EQ(0, value.length());
+
+ i::V8::SetPlatformForTesting(old_platform);
+}
« no previous file with comments | « src/profiler/tracing-cpu-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698