2010-03-15 14:11:19 +00:00
|
|
|
// Copyright 2010 the V8 project authors. All rights reserved.
|
2013-03-07 11:12:26 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2010-03-15 14:11:19 +00:00
|
|
|
//
|
|
|
|
// Tests of profiles generator and utilities.
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "include/v8-profiler.h"
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2019-05-20 09:15:06 +00:00
|
|
|
#include "src/logging/log.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2015-09-28 19:34:08 +00:00
|
|
|
#include "src/profiler/cpu-profiler.h"
|
|
|
|
#include "src/profiler/profile-generator-inl.h"
|
2020-10-01 07:07:48 +00:00
|
|
|
#include "src/profiler/symbolizer.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/profiler-extension.h"
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2017-09-21 03:29:52 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace test_profile_generator {
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
TEST(ProfileNodeFindOrAddChild) {
|
2015-11-30 08:16:35 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
ProfileTree tree(CcTest::i_isolate());
|
2014-02-06 07:16:41 +00:00
|
|
|
ProfileNode* node = tree.root();
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry1(i::CodeEventListener::FUNCTION_TAG, "aaa");
|
2014-02-06 07:16:41 +00:00
|
|
|
ProfileNode* childNode1 = node->FindOrAddChild(&entry1);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(childNode1);
|
2014-02-06 07:16:41 +00:00
|
|
|
CHECK_EQ(childNode1, node->FindOrAddChild(&entry1));
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry2(i::CodeEventListener::FUNCTION_TAG, "bbb");
|
2014-02-06 07:16:41 +00:00
|
|
|
ProfileNode* childNode2 = node->FindOrAddChild(&entry2);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(childNode2);
|
2010-03-15 14:11:19 +00:00
|
|
|
CHECK_NE(childNode1, childNode2);
|
2014-02-06 07:16:41 +00:00
|
|
|
CHECK_EQ(childNode1, node->FindOrAddChild(&entry1));
|
|
|
|
CHECK_EQ(childNode2, node->FindOrAddChild(&entry2));
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry3(i::CodeEventListener::FUNCTION_TAG, "ccc");
|
2014-02-06 07:16:41 +00:00
|
|
|
ProfileNode* childNode3 = node->FindOrAddChild(&entry3);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(childNode3);
|
2010-03-15 14:11:19 +00:00
|
|
|
CHECK_NE(childNode1, childNode3);
|
|
|
|
CHECK_NE(childNode2, childNode3);
|
2014-02-06 07:16:41 +00:00
|
|
|
CHECK_EQ(childNode1, node->FindOrAddChild(&entry1));
|
|
|
|
CHECK_EQ(childNode2, node->FindOrAddChild(&entry2));
|
|
|
|
CHECK_EQ(childNode3, node->FindOrAddChild(&entry3));
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 08:26:10 +00:00
|
|
|
TEST(ProfileNodeFindOrAddChildWithLineNumber) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
ProfileTree tree(CcTest::i_isolate());
|
|
|
|
ProfileNode* root = tree.root();
|
|
|
|
CodeEntry a(i::CodeEventListener::FUNCTION_TAG, "a");
|
|
|
|
ProfileNode* a_node = root->FindOrAddChild(&a, -1);
|
|
|
|
|
|
|
|
// a --(22)--> child1
|
|
|
|
// --(23)--> child1
|
|
|
|
|
|
|
|
CodeEntry child1(i::CodeEventListener::FUNCTION_TAG, "child1");
|
|
|
|
ProfileNode* child1_node = a_node->FindOrAddChild(&child1, 22);
|
|
|
|
CHECK(child1_node);
|
|
|
|
CHECK_EQ(child1_node, a_node->FindOrAddChild(&child1, 22));
|
|
|
|
|
|
|
|
ProfileNode* child2_node = a_node->FindOrAddChild(&child1, 23);
|
|
|
|
CHECK(child2_node);
|
|
|
|
CHECK_NE(child1_node, child2_node);
|
|
|
|
}
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2010-09-20 09:29:12 +00:00
|
|
|
TEST(ProfileNodeFindOrAddChildForSameFunction) {
|
2015-11-30 08:16:35 +00:00
|
|
|
CcTest::InitializeVM();
|
2010-09-20 12:25:45 +00:00
|
|
|
const char* aaa = "aaa";
|
2015-11-30 08:16:35 +00:00
|
|
|
ProfileTree tree(CcTest::i_isolate());
|
2014-02-06 07:16:41 +00:00
|
|
|
ProfileNode* node = tree.root();
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry1(i::CodeEventListener::FUNCTION_TAG, aaa);
|
2014-02-06 07:16:41 +00:00
|
|
|
ProfileNode* childNode1 = node->FindOrAddChild(&entry1);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(childNode1);
|
2014-02-06 07:16:41 +00:00
|
|
|
CHECK_EQ(childNode1, node->FindOrAddChild(&entry1));
|
2010-09-20 09:29:12 +00:00
|
|
|
// The same function again.
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry2(i::CodeEventListener::FUNCTION_TAG, aaa);
|
2014-02-06 07:16:41 +00:00
|
|
|
CHECK_EQ(childNode1, node->FindOrAddChild(&entry2));
|
2010-09-20 09:29:12 +00:00
|
|
|
// Now with a different security token.
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry3(i::CodeEventListener::FUNCTION_TAG, aaa);
|
2014-02-06 07:16:41 +00:00
|
|
|
CHECK_EQ(childNode1, node->FindOrAddChild(&entry3));
|
2010-09-20 09:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ProfileTreeTestHelper {
|
|
|
|
public:
|
2010-03-30 11:38:39 +00:00
|
|
|
explicit ProfileTreeTestHelper(const ProfileTree* tree)
|
2010-03-15 14:11:19 +00:00
|
|
|
: tree_(tree) { }
|
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
ProfileNode* Walk(CodeEntry* entry1, CodeEntry* entry2 = nullptr,
|
|
|
|
CodeEntry* entry3 = nullptr) {
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node = tree_->root();
|
|
|
|
node = node->FindChild(entry1);
|
2017-10-13 16:33:03 +00:00
|
|
|
if (node == nullptr) return nullptr;
|
|
|
|
if (entry2 != nullptr) {
|
2010-03-15 14:11:19 +00:00
|
|
|
node = node->FindChild(entry2);
|
2017-10-13 16:33:03 +00:00
|
|
|
if (node == nullptr) return nullptr;
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
2017-10-13 16:33:03 +00:00
|
|
|
if (entry3 != nullptr) {
|
2010-03-15 14:11:19 +00:00
|
|
|
node = node->FindChild(entry3);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2010-03-30 11:38:39 +00:00
|
|
|
const ProfileTree* tree_;
|
2010-03-15 14:11:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ProfileTreeAddPathFromEnd) {
|
2015-11-30 08:16:35 +00:00
|
|
|
CcTest::InitializeVM();
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry1(i::CodeEventListener::FUNCTION_TAG, "aaa");
|
|
|
|
CodeEntry entry2(i::CodeEventListener::FUNCTION_TAG, "bbb");
|
|
|
|
CodeEntry entry3(i::CodeEventListener::FUNCTION_TAG, "ccc");
|
2015-11-30 08:16:35 +00:00
|
|
|
ProfileTree tree(CcTest::i_isolate());
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileTreeTestHelper helper(&tree);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!helper.Walk(&entry1));
|
|
|
|
CHECK(!helper.Walk(&entry2));
|
|
|
|
CHECK(!helper.Walk(&entry3));
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
CodeEntry* path[] = {nullptr, &entry3, nullptr, &entry2,
|
|
|
|
nullptr, nullptr, &entry1, nullptr};
|
2016-03-01 05:59:32 +00:00
|
|
|
std::vector<CodeEntry*> path_vec(path, path + arraysize(path));
|
2010-03-15 14:11:19 +00:00
|
|
|
tree.AddPathFromEnd(path_vec);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!helper.Walk(&entry2));
|
|
|
|
CHECK(!helper.Walk(&entry3));
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node1 = helper.Walk(&entry1);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node1);
|
|
|
|
CHECK_EQ(0u, node1->self_ticks());
|
|
|
|
CHECK(!helper.Walk(&entry1, &entry1));
|
|
|
|
CHECK(!helper.Walk(&entry1, &entry3));
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node2 = helper.Walk(&entry1, &entry2);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node2);
|
2010-03-15 14:11:19 +00:00
|
|
|
CHECK_NE(node1, node2);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(0u, node2->self_ticks());
|
|
|
|
CHECK(!helper.Walk(&entry1, &entry2, &entry1));
|
|
|
|
CHECK(!helper.Walk(&entry1, &entry2, &entry2));
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node3 = helper.Walk(&entry1, &entry2, &entry3);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node3);
|
2010-03-15 14:11:19 +00:00
|
|
|
CHECK_NE(node1, node3);
|
|
|
|
CHECK_NE(node2, node3);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(1u, node3->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
tree.AddPathFromEnd(path_vec);
|
|
|
|
CHECK_EQ(node1, helper.Walk(&entry1));
|
|
|
|
CHECK_EQ(node2, helper.Walk(&entry1, &entry2));
|
|
|
|
CHECK_EQ(node3, helper.Walk(&entry1, &entry2, &entry3));
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(0u, node1->self_ticks());
|
|
|
|
CHECK_EQ(0u, node2->self_ticks());
|
|
|
|
CHECK_EQ(2u, node3->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
CodeEntry* path2[] = {&entry2, &entry2, &entry1};
|
2016-03-01 05:59:32 +00:00
|
|
|
std::vector<CodeEntry*> path2_vec(path2, path2 + arraysize(path2));
|
2010-03-15 14:11:19 +00:00
|
|
|
tree.AddPathFromEnd(path2_vec);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!helper.Walk(&entry2));
|
|
|
|
CHECK(!helper.Walk(&entry3));
|
2010-03-15 14:11:19 +00:00
|
|
|
CHECK_EQ(node1, helper.Walk(&entry1));
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!helper.Walk(&entry1, &entry1));
|
|
|
|
CHECK(!helper.Walk(&entry1, &entry3));
|
2010-03-15 14:11:19 +00:00
|
|
|
CHECK_EQ(node2, helper.Walk(&entry1, &entry2));
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!helper.Walk(&entry1, &entry2, &entry1));
|
2010-03-15 14:11:19 +00:00
|
|
|
CHECK_EQ(node3, helper.Walk(&entry1, &entry2, &entry3));
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(2u, node3->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node4 = helper.Walk(&entry1, &entry2, &entry2);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node4);
|
2010-03-15 14:11:19 +00:00
|
|
|
CHECK_NE(node3, node4);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(1u, node4->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 08:26:10 +00:00
|
|
|
TEST(ProfileTreeAddPathFromEndWithLineNumbers) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
CodeEntry a(i::CodeEventListener::FUNCTION_TAG, "a");
|
|
|
|
CodeEntry b(i::CodeEventListener::FUNCTION_TAG, "b");
|
|
|
|
CodeEntry c(i::CodeEventListener::FUNCTION_TAG, "c");
|
|
|
|
ProfileTree tree(CcTest::i_isolate());
|
|
|
|
ProfileTreeTestHelper helper(&tree);
|
|
|
|
|
2020-10-01 07:16:08 +00:00
|
|
|
ProfileStackTrace path = {{&c, 5}, {&b, 3}, {&a, 1}};
|
2018-05-23 08:26:10 +00:00
|
|
|
tree.AddPathFromEnd(path, v8::CpuProfileNode::kNoLineNumberInfo, true,
|
|
|
|
v8::CpuProfilingMode::kCallerLineNumbers);
|
|
|
|
|
|
|
|
ProfileNode* a_node =
|
|
|
|
tree.root()->FindChild(&a, v8::CpuProfileNode::kNoLineNumberInfo);
|
|
|
|
tree.Print();
|
|
|
|
CHECK(a_node);
|
|
|
|
|
|
|
|
ProfileNode* b_node = a_node->FindChild(&b, 1);
|
|
|
|
CHECK(b_node);
|
|
|
|
|
|
|
|
ProfileNode* c_node = b_node->FindChild(&c, 3);
|
|
|
|
CHECK(c_node);
|
|
|
|
}
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
TEST(ProfileTreeCalculateTotalTicks) {
|
2015-11-30 08:16:35 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
ProfileTree empty_tree(CcTest::i_isolate());
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(0u, empty_tree.root()->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
empty_tree.root()->IncrementSelfTicks();
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(1u, empty_tree.root()->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry1(i::CodeEventListener::FUNCTION_TAG, "aaa");
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeEntry* e1_path[] = {&entry1};
|
2016-03-01 05:59:32 +00:00
|
|
|
std::vector<CodeEntry*> e1_path_vec(e1_path, e1_path + arraysize(e1_path));
|
2010-05-18 14:19:33 +00:00
|
|
|
|
2015-11-30 08:16:35 +00:00
|
|
|
ProfileTree single_child_tree(CcTest::i_isolate());
|
2015-02-11 07:26:59 +00:00
|
|
|
single_child_tree.AddPathFromEnd(e1_path_vec);
|
2010-05-18 14:19:33 +00:00
|
|
|
single_child_tree.root()->IncrementSelfTicks();
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(1u, single_child_tree.root()->self_ticks());
|
2010-05-18 14:19:33 +00:00
|
|
|
ProfileTreeTestHelper single_child_helper(&single_child_tree);
|
|
|
|
ProfileNode* node1 = single_child_helper.Walk(&entry1);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node1);
|
|
|
|
CHECK_EQ(1u, single_child_tree.root()->self_ticks());
|
|
|
|
CHECK_EQ(1u, node1->self_ticks());
|
2010-05-18 14:19:33 +00:00
|
|
|
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry2(i::CodeEventListener::FUNCTION_TAG, "bbb");
|
2015-02-11 07:26:59 +00:00
|
|
|
CodeEntry* e2_e1_path[] = {&entry2, &entry1};
|
2016-03-01 05:59:32 +00:00
|
|
|
std::vector<CodeEntry*> e2_e1_path_vec(e2_e1_path,
|
|
|
|
e2_e1_path + arraysize(e2_e1_path));
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2015-11-30 08:16:35 +00:00
|
|
|
ProfileTree flat_tree(CcTest::i_isolate());
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileTreeTestHelper flat_helper(&flat_tree);
|
2015-02-11 07:26:59 +00:00
|
|
|
flat_tree.AddPathFromEnd(e1_path_vec);
|
|
|
|
flat_tree.AddPathFromEnd(e1_path_vec);
|
|
|
|
flat_tree.AddPathFromEnd(e2_e1_path_vec);
|
|
|
|
flat_tree.AddPathFromEnd(e2_e1_path_vec);
|
|
|
|
flat_tree.AddPathFromEnd(e2_e1_path_vec);
|
2010-03-15 14:11:19 +00:00
|
|
|
// Results in {root,0,0} -> {entry1,0,2} -> {entry2,0,3}
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(0u, flat_tree.root()->self_ticks());
|
2010-05-18 14:19:33 +00:00
|
|
|
node1 = flat_helper.Walk(&entry1);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node1);
|
|
|
|
CHECK_EQ(2u, node1->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node2 = flat_helper.Walk(&entry1, &entry2);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node2);
|
|
|
|
CHECK_EQ(3u, node2->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
// Must calculate {root,5,0} -> {entry1,5,2} -> {entry2,3,3}
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(0u, flat_tree.root()->self_ticks());
|
|
|
|
CHECK_EQ(2u, node1->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
|
|
|
|
CodeEntry* e2_path[] = {&entry2};
|
2016-03-01 05:59:32 +00:00
|
|
|
std::vector<CodeEntry*> e2_path_vec(e2_path, e2_path + arraysize(e2_path));
|
2016-06-15 13:22:39 +00:00
|
|
|
CodeEntry entry3(i::CodeEventListener::FUNCTION_TAG, "ccc");
|
2010-03-15 14:11:19 +00:00
|
|
|
CodeEntry* e3_path[] = {&entry3};
|
2016-03-01 05:59:32 +00:00
|
|
|
std::vector<CodeEntry*> e3_path_vec(e3_path, e3_path + arraysize(e3_path));
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2015-11-30 08:16:35 +00:00
|
|
|
ProfileTree wide_tree(CcTest::i_isolate());
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileTreeTestHelper wide_helper(&wide_tree);
|
2015-02-11 07:26:59 +00:00
|
|
|
wide_tree.AddPathFromEnd(e1_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e1_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e2_e1_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e2_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e2_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e2_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e3_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e3_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e3_path_vec);
|
|
|
|
wide_tree.AddPathFromEnd(e3_path_vec);
|
2010-03-15 14:11:19 +00:00
|
|
|
// Results in -> {entry1,0,2} -> {entry2,0,1}
|
|
|
|
// {root,0,0} -> {entry2,0,3}
|
|
|
|
// -> {entry3,0,4}
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(0u, wide_tree.root()->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
node1 = wide_helper.Walk(&entry1);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node1);
|
|
|
|
CHECK_EQ(2u, node1->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node1_2 = wide_helper.Walk(&entry1, &entry2);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node1_2);
|
|
|
|
CHECK_EQ(1u, node1_2->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
node2 = wide_helper.Walk(&entry2);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node2);
|
|
|
|
CHECK_EQ(3u, node2->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
ProfileNode* node3 = wide_helper.Walk(&entry3);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(node3);
|
|
|
|
CHECK_EQ(4u, node3->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
// Calculates -> {entry1,3,2} -> {entry2,1,1}
|
|
|
|
// {root,10,0} -> {entry2,3,3}
|
|
|
|
// -> {entry3,4,4}
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(0u, wide_tree.root()->self_ticks());
|
|
|
|
CHECK_EQ(2u, node1->self_ticks());
|
|
|
|
CHECK_EQ(1u, node1_2->self_ticks());
|
|
|
|
CHECK_EQ(3u, node2->self_ticks());
|
|
|
|
CHECK_EQ(4u, node3->self_ticks());
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 22:28:05 +00:00
|
|
|
static inline i::Address ToAddress(int n) { return static_cast<i::Address>(n); }
|
2010-03-15 14:11:19 +00:00
|
|
|
|
2018-04-13 22:28:05 +00:00
|
|
|
static inline void* ToPointer(int n) { return reinterpret_cast<void*>(n); }
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2010-03-15 14:11:19 +00:00
|
|
|
TEST(CodeMapAddCode) {
|
2020-12-21 21:42:34 +00:00
|
|
|
StringsStorage strings;
|
|
|
|
CodeMap code_map(strings);
|
2018-05-11 18:02:24 +00:00
|
|
|
CodeEntry* entry1 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa");
|
|
|
|
CodeEntry* entry2 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "bbb");
|
|
|
|
CodeEntry* entry3 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "ccc");
|
|
|
|
CodeEntry* entry4 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "ddd");
|
|
|
|
code_map.AddCode(ToAddress(0x1500), entry1, 0x200);
|
|
|
|
code_map.AddCode(ToAddress(0x1700), entry2, 0x100);
|
|
|
|
code_map.AddCode(ToAddress(0x1900), entry3, 0x50);
|
|
|
|
code_map.AddCode(ToAddress(0x1950), entry4, 0x10);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!code_map.FindEntry(0));
|
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0x1500 - 1)));
|
2018-05-11 18:02:24 +00:00
|
|
|
CHECK_EQ(entry1, code_map.FindEntry(ToAddress(0x1500)));
|
|
|
|
CHECK_EQ(entry1, code_map.FindEntry(ToAddress(0x1500 + 0x100)));
|
|
|
|
CHECK_EQ(entry1, code_map.FindEntry(ToAddress(0x1500 + 0x200 - 1)));
|
|
|
|
CHECK_EQ(entry2, code_map.FindEntry(ToAddress(0x1700)));
|
|
|
|
CHECK_EQ(entry2, code_map.FindEntry(ToAddress(0x1700 + 0x50)));
|
|
|
|
CHECK_EQ(entry2, code_map.FindEntry(ToAddress(0x1700 + 0x100 - 1)));
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0x1700 + 0x100)));
|
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0x1900 - 1)));
|
2018-05-11 18:02:24 +00:00
|
|
|
CHECK_EQ(entry3, code_map.FindEntry(ToAddress(0x1900)));
|
|
|
|
CHECK_EQ(entry3, code_map.FindEntry(ToAddress(0x1900 + 0x28)));
|
|
|
|
CHECK_EQ(entry4, code_map.FindEntry(ToAddress(0x1950)));
|
|
|
|
CHECK_EQ(entry4, code_map.FindEntry(ToAddress(0x1950 + 0x7)));
|
|
|
|
CHECK_EQ(entry4, code_map.FindEntry(ToAddress(0x1950 + 0x10 - 1)));
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0x1950 + 0x10)));
|
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0xFFFFFFFF)));
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CodeMapMoveAndDeleteCode) {
|
2020-12-21 21:42:34 +00:00
|
|
|
StringsStorage strings;
|
|
|
|
CodeMap code_map(strings);
|
2018-05-11 18:02:24 +00:00
|
|
|
CodeEntry* entry1 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa");
|
|
|
|
CodeEntry* entry2 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "bbb");
|
|
|
|
code_map.AddCode(ToAddress(0x1500), entry1, 0x200);
|
|
|
|
code_map.AddCode(ToAddress(0x1700), entry2, 0x100);
|
|
|
|
CHECK_EQ(entry1, code_map.FindEntry(ToAddress(0x1500)));
|
|
|
|
CHECK_EQ(entry2, code_map.FindEntry(ToAddress(0x1700)));
|
2011-09-14 11:47:03 +00:00
|
|
|
code_map.MoveCode(ToAddress(0x1500), ToAddress(0x1700)); // Deprecate bbb.
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0x1500)));
|
2018-05-11 18:02:24 +00:00
|
|
|
CHECK_EQ(entry1, code_map.FindEntry(ToAddress(0x1700)));
|
|
|
|
CodeEntry* entry3 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "ccc");
|
|
|
|
code_map.AddCode(ToAddress(0x1750), entry3, 0x100);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0x1700)));
|
2018-05-11 18:02:24 +00:00
|
|
|
CHECK_EQ(entry3, code_map.FindEntry(ToAddress(0x1750)));
|
2010-03-15 14:11:19 +00:00
|
|
|
}
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2020-10-27 10:02:27 +00:00
|
|
|
TEST(CodeMapClear) {
|
2020-12-21 21:42:34 +00:00
|
|
|
StringsStorage strings;
|
|
|
|
CodeMap code_map(strings);
|
2020-10-27 10:02:27 +00:00
|
|
|
CodeEntry* entry1 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "aaa");
|
|
|
|
CodeEntry* entry2 = new CodeEntry(i::CodeEventListener::FUNCTION_TAG, "bbb");
|
|
|
|
code_map.AddCode(ToAddress(0x1500), entry1, 0x200);
|
|
|
|
code_map.AddCode(ToAddress(0x1700), entry2, 0x100);
|
|
|
|
|
|
|
|
code_map.Clear();
|
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0x1500)));
|
|
|
|
CHECK(!code_map.FindEntry(ToAddress(0x1700)));
|
|
|
|
|
|
|
|
// Check that Clear() doesn't cause issues if called twice.
|
|
|
|
code_map.Clear();
|
|
|
|
}
|
|
|
|
|
2010-04-12 07:23:43 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TestSetup {
|
|
|
|
public:
|
|
|
|
TestSetup()
|
|
|
|
: old_flag_prof_browser_mode_(i::FLAG_prof_browser_mode) {
|
|
|
|
i::FLAG_prof_browser_mode = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestSetup() {
|
|
|
|
i::FLAG_prof_browser_mode = old_flag_prof_browser_mode_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool old_flag_prof_browser_mode_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-05-17 09:27:26 +00:00
|
|
|
TEST(SymbolizeTickSample) {
|
2010-04-12 07:23:43 +00:00
|
|
|
TestSetup test_setup;
|
2020-12-21 21:42:34 +00:00
|
|
|
StringsStorage strings;
|
|
|
|
CodeMap code_map(strings);
|
2020-10-01 07:07:48 +00:00
|
|
|
Symbolizer symbolizer(&code_map);
|
2016-06-22 16:43:46 +00:00
|
|
|
CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
|
|
|
|
CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
|
|
|
|
CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
|
2020-10-01 07:07:48 +00:00
|
|
|
symbolizer.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
|
|
|
|
symbolizer.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
|
|
|
|
symbolizer.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
// We are building the following calls tree:
|
|
|
|
// -> aaa - sample1
|
|
|
|
// aaa -> bbb -> ccc - sample2
|
|
|
|
// -> ccc -> aaa - sample3
|
|
|
|
TickSample sample1;
|
2018-04-13 22:28:05 +00:00
|
|
|
sample1.pc = ToPointer(0x1600);
|
|
|
|
sample1.tos = ToPointer(0x1500);
|
|
|
|
sample1.stack[0] = ToPointer(0x1510);
|
2010-03-19 09:46:53 +00:00
|
|
|
sample1.frames_count = 1;
|
2020-10-01 07:07:48 +00:00
|
|
|
Symbolizer::SymbolizedSample symbolized =
|
|
|
|
symbolizer.SymbolizeTickSample(sample1);
|
|
|
|
ProfileStackTrace& stack_trace = symbolized.stack_trace;
|
|
|
|
CHECK_EQ(2, stack_trace.size());
|
2020-10-01 07:16:08 +00:00
|
|
|
CHECK_EQ(entry1, stack_trace[0].code_entry);
|
|
|
|
CHECK_EQ(entry1, stack_trace[1].code_entry);
|
2020-10-01 07:07:48 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
TickSample sample2;
|
2018-04-13 22:28:05 +00:00
|
|
|
sample2.pc = ToPointer(0x1925);
|
|
|
|
sample2.tos = ToPointer(0x1900);
|
|
|
|
sample2.stack[0] = ToPointer(0x1780);
|
|
|
|
sample2.stack[1] = ToPointer(0x10000); // non-existent.
|
|
|
|
sample2.stack[2] = ToPointer(0x1620);
|
2010-03-19 09:46:53 +00:00
|
|
|
sample2.frames_count = 3;
|
2020-10-01 07:07:48 +00:00
|
|
|
symbolized = symbolizer.SymbolizeTickSample(sample2);
|
|
|
|
stack_trace = symbolized.stack_trace;
|
|
|
|
CHECK_EQ(4, stack_trace.size());
|
2020-10-01 07:16:08 +00:00
|
|
|
CHECK_EQ(entry3, stack_trace[0].code_entry);
|
|
|
|
CHECK_EQ(entry2, stack_trace[1].code_entry);
|
|
|
|
CHECK_EQ(nullptr, stack_trace[2].code_entry);
|
|
|
|
CHECK_EQ(entry1, stack_trace[3].code_entry);
|
2020-10-01 07:07:48 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
TickSample sample3;
|
2018-04-13 22:28:05 +00:00
|
|
|
sample3.pc = ToPointer(0x1510);
|
|
|
|
sample3.tos = ToPointer(0x1500);
|
|
|
|
sample3.stack[0] = ToPointer(0x1910);
|
|
|
|
sample3.stack[1] = ToPointer(0x1610);
|
2010-03-19 09:46:53 +00:00
|
|
|
sample3.frames_count = 2;
|
2020-10-01 07:07:48 +00:00
|
|
|
symbolized = symbolizer.SymbolizeTickSample(sample3);
|
|
|
|
stack_trace = symbolized.stack_trace;
|
|
|
|
CHECK_EQ(3, stack_trace.size());
|
2020-10-01 07:16:08 +00:00
|
|
|
CHECK_EQ(entry1, stack_trace[0].code_entry);
|
|
|
|
CHECK_EQ(entry3, stack_trace[1].code_entry);
|
|
|
|
CHECK_EQ(entry1, stack_trace[2].code_entry);
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
2010-03-30 11:38:39 +00:00
|
|
|
|
2017-08-29 12:40:31 +00:00
|
|
|
static void CheckNodeIds(const ProfileNode* node, unsigned* expectedId) {
|
2013-04-02 07:48:25 +00:00
|
|
|
CHECK_EQ((*expectedId)++, node->id());
|
2017-08-29 12:40:31 +00:00
|
|
|
for (const ProfileNode* child : *node->children()) {
|
|
|
|
CheckNodeIds(child, expectedId);
|
2013-04-02 07:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(SampleIds) {
|
|
|
|
TestSetup test_setup;
|
2016-10-28 20:17:44 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
CpuProfilesCollection profiles(isolate);
|
|
|
|
CpuProfiler profiler(isolate);
|
2016-07-08 15:00:23 +00:00
|
|
|
profiles.set_cpu_profiler(&profiler);
|
2019-05-22 00:06:41 +00:00
|
|
|
profiles.StartProfiling("", {CpuProfilingMode::kLeafNodeLineNumbers});
|
2020-12-21 21:42:34 +00:00
|
|
|
StringsStorage strings;
|
|
|
|
CodeMap code_map(strings);
|
2020-10-01 07:07:48 +00:00
|
|
|
Symbolizer symbolizer(&code_map);
|
2016-06-22 16:43:46 +00:00
|
|
|
CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
|
|
|
|
CodeEntry* entry2 = new CodeEntry(i::Logger::FUNCTION_TAG, "bbb");
|
|
|
|
CodeEntry* entry3 = new CodeEntry(i::Logger::FUNCTION_TAG, "ccc");
|
2020-10-01 07:07:48 +00:00
|
|
|
symbolizer.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
|
|
|
|
symbolizer.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
|
|
|
|
symbolizer.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
|
2013-04-02 07:48:25 +00:00
|
|
|
|
|
|
|
// We are building the following calls tree:
|
|
|
|
// -> aaa #3 - sample1
|
|
|
|
// (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2
|
|
|
|
// -> ccc #6 -> aaa #7 - sample3
|
|
|
|
TickSample sample1;
|
2016-02-19 18:49:14 +00:00
|
|
|
sample1.timestamp = v8::base::TimeTicks::HighResolutionNow();
|
2018-04-13 22:28:05 +00:00
|
|
|
sample1.pc = ToPointer(0x1600);
|
|
|
|
sample1.stack[0] = ToPointer(0x1510);
|
2013-04-02 07:48:25 +00:00
|
|
|
sample1.frames_count = 1;
|
2020-10-01 07:07:48 +00:00
|
|
|
auto symbolized = symbolizer.SymbolizeTickSample(sample1);
|
|
|
|
profiles.AddPathToCurrentProfiles(sample1.timestamp, symbolized.stack_trace,
|
|
|
|
symbolized.src_line, true,
|
|
|
|
base::TimeDelta());
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
TickSample sample2;
|
2016-02-19 18:49:14 +00:00
|
|
|
sample2.timestamp = v8::base::TimeTicks::HighResolutionNow();
|
2018-04-13 22:28:05 +00:00
|
|
|
sample2.pc = ToPointer(0x1925);
|
|
|
|
sample2.stack[0] = ToPointer(0x1780);
|
|
|
|
sample2.stack[1] = ToPointer(0x10000); // non-existent.
|
|
|
|
sample2.stack[2] = ToPointer(0x1620);
|
2013-04-02 07:48:25 +00:00
|
|
|
sample2.frames_count = 3;
|
2020-10-01 07:07:48 +00:00
|
|
|
symbolized = symbolizer.SymbolizeTickSample(sample2);
|
|
|
|
profiles.AddPathToCurrentProfiles(sample2.timestamp, symbolized.stack_trace,
|
|
|
|
symbolized.src_line, true,
|
|
|
|
base::TimeDelta());
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
TickSample sample3;
|
2016-02-19 18:49:14 +00:00
|
|
|
sample3.timestamp = v8::base::TimeTicks::HighResolutionNow();
|
2018-04-13 22:28:05 +00:00
|
|
|
sample3.pc = ToPointer(0x1510);
|
|
|
|
sample3.stack[0] = ToPointer(0x1910);
|
|
|
|
sample3.stack[1] = ToPointer(0x1610);
|
2013-04-02 07:48:25 +00:00
|
|
|
sample3.frames_count = 2;
|
2020-10-01 07:07:48 +00:00
|
|
|
symbolized = symbolizer.SymbolizeTickSample(sample3);
|
|
|
|
profiles.AddPathToCurrentProfiles(sample3.timestamp, symbolized.stack_trace,
|
|
|
|
symbolized.src_line, true,
|
|
|
|
base::TimeDelta());
|
2013-04-02 07:48:25 +00:00
|
|
|
|
2013-07-30 07:01:16 +00:00
|
|
|
CpuProfile* profile = profiles.StopProfiling("");
|
2015-01-30 09:29:25 +00:00
|
|
|
unsigned nodeId = 1;
|
2013-04-02 07:48:25 +00:00
|
|
|
CheckNodeIds(profile->top_down()->root(), &nodeId);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(7u, nodeId - 1);
|
2013-04-02 07:48:25 +00:00
|
|
|
|
|
|
|
CHECK_EQ(3, profile->samples_count());
|
2015-01-30 09:29:25 +00:00
|
|
|
unsigned expected_id[] = {3, 5, 7};
|
2013-04-02 07:48:25 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2019-02-07 22:52:20 +00:00
|
|
|
CHECK_EQ(expected_id[i], profile->sample(i).node->id());
|
2013-04-02 07:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 06:05:32 +00:00
|
|
|
namespace {
|
|
|
|
class DiscardedSamplesDelegateImpl : public v8::DiscardedSamplesDelegate {
|
|
|
|
public:
|
|
|
|
DiscardedSamplesDelegateImpl() : DiscardedSamplesDelegate() {}
|
|
|
|
void Notify() override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MockPlatform : public TestPlatform {
|
|
|
|
public:
|
|
|
|
MockPlatform()
|
|
|
|
: old_platform_(i::V8::GetCurrentPlatform()),
|
|
|
|
mock_task_runner_(new MockTaskRunner()) {
|
|
|
|
// Now that it's completely constructed, make this the current platform.
|
|
|
|
i::V8::SetPlatformForTesting(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When done, explicitly revert to old_platform_.
|
|
|
|
~MockPlatform() override { i::V8::SetPlatformForTesting(old_platform_); }
|
|
|
|
|
|
|
|
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
|
|
|
|
v8::Isolate*) override {
|
|
|
|
return mock_task_runner_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int posted_count() { return mock_task_runner_->posted_count(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
class MockTaskRunner : public v8::TaskRunner {
|
|
|
|
public:
|
|
|
|
void PostTask(std::unique_ptr<v8::Task> task) override {
|
|
|
|
task->Run();
|
|
|
|
posted_count_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostDelayedTask(std::unique_ptr<Task> task,
|
|
|
|
double delay_in_seconds) override {
|
|
|
|
task_ = std::move(task);
|
|
|
|
delay_ = delay_in_seconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostIdleTask(std::unique_ptr<IdleTask> task) override {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IdleTasksEnabled() override { return false; }
|
|
|
|
|
|
|
|
int posted_count() { return posted_count_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int posted_count_ = 0;
|
|
|
|
double delay_ = -1;
|
|
|
|
std::unique_ptr<Task> task_;
|
|
|
|
};
|
|
|
|
|
|
|
|
v8::Platform* old_platform_;
|
|
|
|
std::shared_ptr<MockTaskRunner> mock_task_runner_;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(MaxSamplesCallback) {
|
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
CpuProfilesCollection profiles(isolate);
|
|
|
|
CpuProfiler profiler(isolate);
|
|
|
|
profiles.set_cpu_profiler(&profiler);
|
|
|
|
MockPlatform* mock_platform = new MockPlatform();
|
|
|
|
std::unique_ptr<DiscardedSamplesDelegateImpl> impl =
|
|
|
|
std::make_unique<DiscardedSamplesDelegateImpl>(
|
|
|
|
DiscardedSamplesDelegateImpl());
|
|
|
|
profiles.StartProfiling("",
|
|
|
|
{v8::CpuProfilingMode::kLeafNodeLineNumbers, 1, 1,
|
|
|
|
MaybeLocal<v8::Context>()},
|
|
|
|
std::move(impl));
|
|
|
|
|
|
|
|
StringsStorage strings;
|
|
|
|
CodeMap code_map(strings);
|
|
|
|
Symbolizer symbolizer(&code_map);
|
|
|
|
TickSample sample1;
|
|
|
|
sample1.timestamp = v8::base::TimeTicks::HighResolutionNow();
|
|
|
|
sample1.pc = ToPointer(0x1600);
|
|
|
|
sample1.stack[0] = ToPointer(0x1510);
|
|
|
|
sample1.frames_count = 1;
|
|
|
|
auto symbolized = symbolizer.SymbolizeTickSample(sample1);
|
|
|
|
profiles.AddPathToCurrentProfiles(sample1.timestamp, symbolized.stack_trace,
|
|
|
|
symbolized.src_line, true,
|
|
|
|
base::TimeDelta());
|
|
|
|
CHECK_EQ(0, mock_platform->posted_count());
|
|
|
|
TickSample sample2;
|
|
|
|
sample2.timestamp = v8::base::TimeTicks::HighResolutionNow();
|
|
|
|
sample2.pc = ToPointer(0x1925);
|
|
|
|
sample2.stack[0] = ToPointer(0x1780);
|
|
|
|
sample2.frames_count = 2;
|
|
|
|
symbolized = symbolizer.SymbolizeTickSample(sample2);
|
|
|
|
profiles.AddPathToCurrentProfiles(sample2.timestamp, symbolized.stack_trace,
|
|
|
|
symbolized.src_line, true,
|
|
|
|
base::TimeDelta());
|
|
|
|
CHECK_EQ(1, mock_platform->posted_count());
|
|
|
|
TickSample sample3;
|
|
|
|
sample3.timestamp = v8::base::TimeTicks::HighResolutionNow();
|
|
|
|
sample3.pc = ToPointer(0x1510);
|
|
|
|
sample3.frames_count = 3;
|
|
|
|
symbolized = symbolizer.SymbolizeTickSample(sample3);
|
|
|
|
profiles.AddPathToCurrentProfiles(sample3.timestamp, symbolized.stack_trace,
|
|
|
|
symbolized.src_line, true,
|
|
|
|
base::TimeDelta());
|
|
|
|
CHECK_EQ(1, mock_platform->posted_count());
|
|
|
|
|
|
|
|
// Teardown
|
|
|
|
profiles.StopProfiling("");
|
|
|
|
delete mock_platform;
|
|
|
|
}
|
|
|
|
|
2013-04-02 07:48:25 +00:00
|
|
|
TEST(NoSamples) {
|
|
|
|
TestSetup test_setup;
|
2016-10-28 20:17:44 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
|
|
|
CpuProfilesCollection profiles(isolate);
|
|
|
|
CpuProfiler profiler(isolate);
|
2016-07-08 15:00:23 +00:00
|
|
|
profiles.set_cpu_profiler(&profiler);
|
2019-05-09 19:20:21 +00:00
|
|
|
profiles.StartProfiling("");
|
2020-12-21 21:42:34 +00:00
|
|
|
StringsStorage strings;
|
|
|
|
CodeMap code_map(strings);
|
2020-10-01 07:07:48 +00:00
|
|
|
Symbolizer symbolizer(&code_map);
|
2016-06-22 16:43:46 +00:00
|
|
|
CodeEntry* entry1 = new CodeEntry(i::Logger::FUNCTION_TAG, "aaa");
|
2020-10-01 07:07:48 +00:00
|
|
|
symbolizer.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
|
2013-04-02 07:48:25 +00:00
|
|
|
|
|
|
|
// We are building the following calls tree:
|
|
|
|
// (root)#1 -> aaa #2 -> aaa #3 - sample1
|
|
|
|
TickSample sample1;
|
2018-04-13 22:28:05 +00:00
|
|
|
sample1.pc = ToPointer(0x1600);
|
|
|
|
sample1.stack[0] = ToPointer(0x1510);
|
2013-04-02 07:48:25 +00:00
|
|
|
sample1.frames_count = 1;
|
2020-10-01 07:07:48 +00:00
|
|
|
auto symbolized = symbolizer.SymbolizeTickSample(sample1);
|
|
|
|
profiles.AddPathToCurrentProfiles(v8::base::TimeTicks::HighResolutionNow(),
|
|
|
|
symbolized.stack_trace, symbolized.src_line,
|
|
|
|
true, base::TimeDelta());
|
2013-04-02 07:48:25 +00:00
|
|
|
|
2013-07-30 07:01:16 +00:00
|
|
|
CpuProfile* profile = profiles.StopProfiling("");
|
2015-01-30 09:29:25 +00:00
|
|
|
unsigned nodeId = 1;
|
2013-04-02 07:48:25 +00:00
|
|
|
CheckNodeIds(profile->top_down()->root(), &nodeId);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK_EQ(3u, nodeId - 1);
|
2013-04-02 07:48:25 +00:00
|
|
|
|
2020-10-01 07:07:48 +00:00
|
|
|
CHECK_EQ(1, profile->samples_count());
|
2013-04-02 07:48:25 +00:00
|
|
|
}
|
|
|
|
|
2010-06-01 13:52:49 +00:00
|
|
|
static const ProfileNode* PickChild(const ProfileNode* parent,
|
|
|
|
const char* name) {
|
2017-08-29 12:40:31 +00:00
|
|
|
for (const ProfileNode* child : *parent->children()) {
|
2010-06-01 13:52:49 +00:00
|
|
|
if (strcmp(child->entry()->name(), name) == 0) return child;
|
|
|
|
}
|
2017-10-13 16:33:03 +00:00
|
|
|
return nullptr;
|
2010-06-01 13:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(RecordStackTraceAtStartProfiling) {
|
2010-12-07 11:31:57 +00:00
|
|
|
// This test does not pass with inlining enabled since inlined functions
|
|
|
|
// don't appear in the stack trace.
|
2015-10-15 12:01:52 +00:00
|
|
|
i::FLAG_turbo_inlining = false;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-01-16 17:31:37 +00:00
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext({PROFILER_EXTENSION_ID});
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::Context::Scope context_scope(env);
|
2016-07-08 15:00:23 +00:00
|
|
|
std::unique_ptr<i::CpuProfiler> iprofiler(
|
|
|
|
new i::CpuProfiler(CcTest::i_isolate()));
|
|
|
|
i::ProfilerExtension::set_profiler(iprofiler.get());
|
2010-06-01 13:52:49 +00:00
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"function c() { startProfiling(); }\n"
|
|
|
|
"function b() { c(); }\n"
|
|
|
|
"function a() { b(); }\n"
|
|
|
|
"a();\n"
|
|
|
|
"stopProfiling();");
|
2016-07-08 15:00:23 +00:00
|
|
|
CHECK_EQ(1, iprofiler->GetProfilesCount());
|
|
|
|
CpuProfile* profile = iprofiler->GetProfile(0);
|
2010-06-01 13:52:49 +00:00
|
|
|
const ProfileTree* topDown = profile->top_down();
|
|
|
|
const ProfileNode* current = topDown->root();
|
2010-12-07 14:10:41 +00:00
|
|
|
const_cast<ProfileNode*>(current)->Print(0);
|
2010-06-01 13:52:49 +00:00
|
|
|
// The tree should look like this:
|
|
|
|
// (root)
|
2014-08-05 07:08:39 +00:00
|
|
|
// ""
|
2010-06-01 13:52:49 +00:00
|
|
|
// a
|
|
|
|
// b
|
|
|
|
// c
|
2010-12-07 14:10:41 +00:00
|
|
|
// There can also be:
|
|
|
|
// startProfiling
|
|
|
|
// if the sampler managed to get a tick.
|
2014-08-05 07:08:39 +00:00
|
|
|
current = PickChild(current, "");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<ProfileNode*>(current));
|
2010-06-01 13:52:49 +00:00
|
|
|
current = PickChild(current, "a");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<ProfileNode*>(current));
|
2010-06-01 13:52:49 +00:00
|
|
|
current = PickChild(current, "b");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<ProfileNode*>(current));
|
2010-06-01 13:52:49 +00:00
|
|
|
current = PickChild(current, "c");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<ProfileNode*>(current));
|
2017-08-29 12:40:31 +00:00
|
|
|
CHECK(current->children()->empty() || current->children()->size() == 1);
|
|
|
|
if (current->children()->size() == 1) {
|
2010-12-07 14:10:41 +00:00
|
|
|
current = PickChild(current, "startProfiling");
|
2017-08-29 12:40:31 +00:00
|
|
|
CHECK(current->children()->empty());
|
2010-12-07 14:10:41 +00:00
|
|
|
}
|
2010-06-01 13:52:49 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 14:16:01 +00:00
|
|
|
|
|
|
|
TEST(Issue51919) {
|
2016-06-15 09:59:00 +00:00
|
|
|
CpuProfilesCollection collection(CcTest::i_isolate());
|
2016-07-08 15:00:23 +00:00
|
|
|
CpuProfiler profiler(CcTest::i_isolate());
|
|
|
|
collection.set_cpu_profiler(&profiler);
|
2010-08-31 14:16:01 +00:00
|
|
|
i::EmbeddedVector<char*,
|
|
|
|
CpuProfilesCollection::kMaxSimultaneousProfiles> titles;
|
|
|
|
for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) {
|
|
|
|
i::Vector<char> title = i::Vector<char>::New(16);
|
2014-06-13 16:43:27 +00:00
|
|
|
i::SNPrintF(title, "%d", i);
|
2020-10-26 18:12:10 +00:00
|
|
|
CHECK_EQ(CpuProfilingStatus::kStarted,
|
|
|
|
collection.StartProfiling(title.begin()));
|
2019-04-29 11:06:49 +00:00
|
|
|
titles[i] = title.begin();
|
2010-08-31 14:16:01 +00:00
|
|
|
}
|
2020-10-26 18:12:10 +00:00
|
|
|
CHECK_EQ(CpuProfilingStatus::kErrorTooManyProfilers,
|
|
|
|
collection.StartProfiling("maximum"));
|
2010-08-31 14:16:01 +00:00
|
|
|
for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i)
|
|
|
|
i::DeleteArray(titles[i]);
|
|
|
|
}
|
2013-07-02 06:14:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const v8::CpuProfileNode* PickChild(const v8::CpuProfileNode* parent,
|
|
|
|
const char* name) {
|
|
|
|
for (int i = 0; i < parent->GetChildrenCount(); ++i) {
|
|
|
|
const v8::CpuProfileNode* child = parent->GetChild(i);
|
2017-08-24 21:49:48 +00:00
|
|
|
v8::String::Utf8Value function_name(CcTest::isolate(),
|
|
|
|
child->GetFunctionName());
|
2013-07-02 06:14:01 +00:00
|
|
|
if (strcmp(*function_name, name) == 0) return child;
|
|
|
|
}
|
2017-10-13 16:33:03 +00:00
|
|
|
return nullptr;
|
2013-07-02 06:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ProfileNodeScriptId) {
|
|
|
|
// This test does not pass with inlining enabled since inlined functions
|
|
|
|
// don't appear in the stack trace.
|
2015-10-15 12:01:52 +00:00
|
|
|
i::FLAG_turbo_inlining = false;
|
2013-07-02 06:14:01 +00:00
|
|
|
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-01-16 17:31:37 +00:00
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext({PROFILER_EXTENSION_ID});
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::Context::Scope context_scope(env);
|
2016-07-08 15:00:23 +00:00
|
|
|
std::unique_ptr<CpuProfiler> iprofiler(new CpuProfiler(CcTest::i_isolate()));
|
|
|
|
i::ProfilerExtension::set_profiler(iprofiler.get());
|
2013-07-02 06:14:01 +00:00
|
|
|
|
2015-10-08 09:48:05 +00:00
|
|
|
v8::Local<v8::Script> script_a =
|
|
|
|
v8_compile(v8_str("function a() { startProfiling(); }\n"));
|
2019-06-21 13:32:50 +00:00
|
|
|
script_a->Run(env).ToLocalChecked();
|
2015-10-08 09:48:05 +00:00
|
|
|
v8::Local<v8::Script> script_b =
|
|
|
|
v8_compile(v8_str("function b() { a(); }\n"
|
|
|
|
"b();\n"
|
|
|
|
"stopProfiling();\n"));
|
2019-06-21 13:32:50 +00:00
|
|
|
script_b->Run(env).ToLocalChecked();
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(1, iprofiler->GetProfilesCount());
|
2014-01-17 10:52:00 +00:00
|
|
|
const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
|
2013-07-02 06:14:01 +00:00
|
|
|
const v8::CpuProfileNode* current = profile->GetTopDownRoot();
|
|
|
|
reinterpret_cast<ProfileNode*>(
|
|
|
|
const_cast<v8::CpuProfileNode*>(current))->Print(0);
|
|
|
|
// The tree should look like this:
|
|
|
|
// (root)
|
2014-08-05 07:08:39 +00:00
|
|
|
// ""
|
2013-07-02 06:14:01 +00:00
|
|
|
// b
|
|
|
|
// a
|
|
|
|
// There can also be:
|
|
|
|
// startProfiling
|
|
|
|
// if the sampler managed to get a tick.
|
2014-08-05 07:08:39 +00:00
|
|
|
current = PickChild(current, "");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<v8::CpuProfileNode*>(current));
|
2013-07-02 06:14:01 +00:00
|
|
|
|
|
|
|
current = PickChild(current, "b");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<v8::CpuProfileNode*>(current));
|
2014-06-05 13:02:18 +00:00
|
|
|
CHECK_EQ(script_b->GetUnboundScript()->GetId(), current->GetScriptId());
|
2013-07-02 06:14:01 +00:00
|
|
|
|
|
|
|
current = PickChild(current, "a");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<v8::CpuProfileNode*>(current));
|
2014-06-05 13:02:18 +00:00
|
|
|
CHECK_EQ(script_a->GetUnboundScript()->GetId(), current->GetScriptId());
|
2013-07-02 06:14:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-07 11:42:30 +00:00
|
|
|
static const char* line_number_test_source_existing_functions =
|
|
|
|
"function foo_at_the_first_line() {\n"
|
|
|
|
"}\n"
|
|
|
|
"foo_at_the_first_line();\n"
|
|
|
|
"function lazy_func_at_forth_line() {}\n";
|
|
|
|
|
|
|
|
static const char* line_number_test_source_profile_time_functions =
|
|
|
|
"// Empty first line\n"
|
|
|
|
"function bar_at_the_second_line() {\n"
|
|
|
|
" foo_at_the_first_line();\n"
|
|
|
|
"}\n"
|
|
|
|
"bar_at_the_second_line();\n"
|
|
|
|
"function lazy_func_at_6th_line() {}";
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
int GetFunctionLineNumber(CpuProfiler* profiler, LocalContext* env,
|
2020-12-17 16:02:56 +00:00
|
|
|
i::Isolate* isolate, const char* name) {
|
2020-10-01 07:07:48 +00:00
|
|
|
CodeMap* code_map = profiler->symbolizer()->code_map();
|
2015-10-23 12:26:49 +00:00
|
|
|
i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(
|
2015-10-08 09:48:05 +00:00
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
2019-09-10 01:19:59 +00:00
|
|
|
(*env)->Global()->Get(env->local(), v8_str(name)).ToLocalChecked())));
|
2018-07-27 09:08:25 +00:00
|
|
|
CodeEntry* func_entry =
|
2020-12-17 16:02:56 +00:00
|
|
|
code_map->FindEntry(func->abstract_code(isolate).InstructionStart());
|
2017-12-18 16:19:23 +00:00
|
|
|
if (!func_entry) FATAL("%s", name);
|
2013-07-07 11:42:30 +00:00
|
|
|
return func_entry->line_number();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LineNumber) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext env;
|
2013-09-19 09:17:13 +00:00
|
|
|
i::Isolate* isolate = CcTest::i_isolate();
|
2013-07-07 11:42:30 +00:00
|
|
|
TestSetup test_setup;
|
|
|
|
|
|
|
|
i::HandleScope scope(isolate);
|
|
|
|
|
|
|
|
CompileRun(line_number_test_source_existing_functions);
|
|
|
|
|
2016-07-08 15:00:23 +00:00
|
|
|
CpuProfiler profiler(isolate);
|
|
|
|
profiler.StartProfiling("LineNumber");
|
2013-07-07 11:42:30 +00:00
|
|
|
|
|
|
|
CompileRun(line_number_test_source_profile_time_functions);
|
|
|
|
|
2016-07-08 15:00:23 +00:00
|
|
|
profiler.processor()->StopSynchronously();
|
2013-07-07 11:42:30 +00:00
|
|
|
|
2016-11-02 11:17:01 +00:00
|
|
|
bool is_lazy = i::FLAG_lazy;
|
2020-12-17 16:02:56 +00:00
|
|
|
CHECK_EQ(1, GetFunctionLineNumber(&profiler, &env, isolate,
|
|
|
|
"foo_at_the_first_line"));
|
|
|
|
CHECK_EQ(is_lazy ? 0 : 4, GetFunctionLineNumber(&profiler, &env, isolate,
|
|
|
|
"lazy_func_at_forth_line"));
|
|
|
|
CHECK_EQ(2, GetFunctionLineNumber(&profiler, &env, isolate,
|
|
|
|
"bar_at_the_second_line"));
|
|
|
|
CHECK_EQ(is_lazy ? 0 : 6, GetFunctionLineNumber(&profiler, &env, isolate,
|
|
|
|
"lazy_func_at_6th_line"));
|
2013-07-07 11:42:30 +00:00
|
|
|
|
2016-07-08 15:00:23 +00:00
|
|
|
profiler.StopProfiling("LineNumber");
|
2013-07-07 11:42:30 +00:00
|
|
|
}
|
2013-09-05 13:20:51 +00:00
|
|
|
|
|
|
|
TEST(BailoutReason) {
|
2018-10-22 11:45:45 +00:00
|
|
|
#ifndef V8_LITE_MODE
|
2017-02-22 08:45:09 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
i::FLAG_always_opt = false;
|
2017-07-13 16:26:18 +00:00
|
|
|
i::FLAG_opt = true;
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-01-16 17:31:37 +00:00
|
|
|
v8::Local<v8::Context> env = CcTest::NewContext({PROFILER_EXTENSION_ID});
|
2014-01-17 10:52:00 +00:00
|
|
|
v8::Context::Scope context_scope(env);
|
2016-07-08 15:00:23 +00:00
|
|
|
std::unique_ptr<CpuProfiler> iprofiler(new CpuProfiler(CcTest::i_isolate()));
|
|
|
|
i::ProfilerExtension::set_profiler(iprofiler.get());
|
2013-09-05 13:20:51 +00:00
|
|
|
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(0, iprofiler->GetProfilesCount());
|
2017-02-22 08:45:09 +00:00
|
|
|
v8::Local<v8::Function> function = CompileRun(
|
|
|
|
"function Debugger() {\n"
|
|
|
|
" startProfiling();\n"
|
|
|
|
"}"
|
|
|
|
"Debugger")
|
|
|
|
.As<v8::Function>();
|
|
|
|
i::Handle<i::JSFunction> i_function =
|
|
|
|
i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*function));
|
2017-07-28 09:36:42 +00:00
|
|
|
USE(i_function);
|
2017-02-22 08:45:09 +00:00
|
|
|
|
|
|
|
CompileRun(
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(Debugger);"
|
2017-02-22 08:45:09 +00:00
|
|
|
"%OptimizeFunctionOnNextCall(Debugger);"
|
2017-07-28 09:36:42 +00:00
|
|
|
"%NeverOptimizeFunction(Debugger);"
|
2017-02-22 08:45:09 +00:00
|
|
|
"Debugger();"
|
|
|
|
"stopProfiling()");
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK_EQ(1, iprofiler->GetProfilesCount());
|
2014-01-17 10:52:00 +00:00
|
|
|
const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
|
2013-12-18 08:59:09 +00:00
|
|
|
CHECK(profile);
|
2013-09-05 13:20:51 +00:00
|
|
|
const v8::CpuProfileNode* current = profile->GetTopDownRoot();
|
|
|
|
reinterpret_cast<ProfileNode*>(
|
|
|
|
const_cast<v8::CpuProfileNode*>(current))->Print(0);
|
|
|
|
// The tree should look like this:
|
|
|
|
// (root)
|
2014-08-05 07:08:39 +00:00
|
|
|
// ""
|
2017-07-28 09:36:42 +00:00
|
|
|
// kOptimizationDisabledForTest
|
2014-08-05 07:08:39 +00:00
|
|
|
current = PickChild(current, "");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<v8::CpuProfileNode*>(current));
|
2013-09-05 13:20:51 +00:00
|
|
|
|
2015-07-02 09:22:46 +00:00
|
|
|
current = PickChild(current, "Debugger");
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(const_cast<v8::CpuProfileNode*>(current));
|
2018-12-19 13:17:05 +00:00
|
|
|
CHECK(
|
|
|
|
!strcmp("Optimization is always disabled", current->GetBailoutReason()));
|
2018-10-22 11:45:45 +00:00
|
|
|
#endif // V8_LITE_MODE
|
2013-09-05 13:20:51 +00:00
|
|
|
}
|
2017-09-21 03:29:52 +00:00
|
|
|
|
2019-04-03 00:07:48 +00:00
|
|
|
TEST(NodeSourceTypes) {
|
|
|
|
ProfileTree tree(CcTest::i_isolate());
|
|
|
|
CodeEntry function_entry(CodeEventListener::FUNCTION_TAG, "function");
|
|
|
|
tree.AddPathFromEnd({&function_entry});
|
|
|
|
CodeEntry builtin_entry(CodeEventListener::BUILTIN_TAG, "builtin");
|
|
|
|
tree.AddPathFromEnd({&builtin_entry});
|
|
|
|
CodeEntry callback_entry(CodeEventListener::CALLBACK_TAG, "callback");
|
|
|
|
tree.AddPathFromEnd({&callback_entry});
|
|
|
|
CodeEntry regex_entry(CodeEventListener::REG_EXP_TAG, "regex");
|
|
|
|
tree.AddPathFromEnd({®ex_entry});
|
|
|
|
CodeEntry stub_entry(CodeEventListener::STUB_TAG, "stub");
|
|
|
|
tree.AddPathFromEnd({&stub_entry});
|
|
|
|
|
|
|
|
tree.AddPathFromEnd({CodeEntry::gc_entry()});
|
|
|
|
tree.AddPathFromEnd({CodeEntry::idle_entry()});
|
|
|
|
tree.AddPathFromEnd({CodeEntry::program_entry()});
|
|
|
|
tree.AddPathFromEnd({CodeEntry::unresolved_entry()});
|
|
|
|
|
|
|
|
auto* root = tree.root();
|
|
|
|
CHECK(root);
|
|
|
|
CHECK_EQ(root->source_type(), v8::CpuProfileNode::kInternal);
|
|
|
|
|
|
|
|
auto* function_node = PickChild(root, "function");
|
|
|
|
CHECK(function_node);
|
|
|
|
CHECK_EQ(function_node->source_type(), v8::CpuProfileNode::kScript);
|
|
|
|
|
|
|
|
auto* builtin_node = PickChild(root, "builtin");
|
|
|
|
CHECK(builtin_node);
|
|
|
|
CHECK_EQ(builtin_node->source_type(), v8::CpuProfileNode::kBuiltin);
|
|
|
|
|
|
|
|
auto* callback_node = PickChild(root, "callback");
|
|
|
|
CHECK(callback_node);
|
|
|
|
CHECK_EQ(callback_node->source_type(), v8::CpuProfileNode::kCallback);
|
|
|
|
|
|
|
|
auto* regex_node = PickChild(root, "regex");
|
|
|
|
CHECK(regex_node);
|
|
|
|
CHECK_EQ(regex_node->source_type(), v8::CpuProfileNode::kInternal);
|
|
|
|
|
|
|
|
auto* stub_node = PickChild(root, "stub");
|
|
|
|
CHECK(stub_node);
|
|
|
|
CHECK_EQ(stub_node->source_type(), v8::CpuProfileNode::kInternal);
|
|
|
|
|
|
|
|
auto* gc_node = PickChild(root, "(garbage collector)");
|
|
|
|
CHECK(gc_node);
|
|
|
|
CHECK_EQ(gc_node->source_type(), v8::CpuProfileNode::kInternal);
|
|
|
|
|
|
|
|
auto* idle_node = PickChild(root, "(idle)");
|
|
|
|
CHECK(idle_node);
|
|
|
|
CHECK_EQ(idle_node->source_type(), v8::CpuProfileNode::kInternal);
|
|
|
|
|
|
|
|
auto* program_node = PickChild(root, "(program)");
|
|
|
|
CHECK(program_node);
|
|
|
|
CHECK_EQ(program_node->source_type(), v8::CpuProfileNode::kInternal);
|
|
|
|
|
|
|
|
auto* unresolved_node = PickChild(root, "(unresolved function)");
|
|
|
|
CHECK(unresolved_node);
|
|
|
|
CHECK_EQ(unresolved_node->source_type(), v8::CpuProfileNode::kUnresolved);
|
|
|
|
}
|
|
|
|
|
2017-09-21 03:29:52 +00:00
|
|
|
} // namespace test_profile_generator
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|