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

Unified Diff: test/cctest/test-profile-generator.cc

Issue 2083005: CPU profiler: add secure profiles by filtering out functions using security tokens. (Closed)
Patch Set: Reworded comment Created 10 years, 7 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 | « test/cctest/test-log-stack-tracer.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-profile-generator.cc
diff --git a/test/cctest/test-profile-generator.cc b/test/cctest/test-profile-generator.cc
index e5850c9c618c18235b3fdf51b4463a70fb0abd46..b438d252e0a8dd45f12153c1f930e73f2d803b16 100644
--- a/test/cctest/test-profile-generator.cc
+++ b/test/cctest/test-profile-generator.cc
@@ -19,22 +19,64 @@ using i::ProfileTree;
using i::ProfileGenerator;
using i::SampleRateCalculator;
using i::TickSample;
+using i::TokenEnumerator;
using i::Vector;
+namespace v8 {
+namespace internal {
+
+class TokenEnumeratorTester {
+ public:
+ static i::List<bool>* token_removed(TokenEnumerator* te) {
+ return &te->token_removed_;
+ }
+};
+
+} } // namespace v8::internal
+
+TEST(TokenEnumerator) {
+ TokenEnumerator te;
+ CHECK_EQ(CodeEntry::kNoSecurityToken, te.GetTokenId(NULL));
+ v8::HandleScope hs;
+ v8::Local<v8::String> token1(v8::String::New("1"));
+ CHECK_EQ(0, te.GetTokenId(*v8::Utils::OpenHandle(*token1)));
+ CHECK_EQ(0, te.GetTokenId(*v8::Utils::OpenHandle(*token1)));
+ v8::Local<v8::String> token2(v8::String::New("2"));
+ CHECK_EQ(1, te.GetTokenId(*v8::Utils::OpenHandle(*token2)));
+ CHECK_EQ(1, te.GetTokenId(*v8::Utils::OpenHandle(*token2)));
+ CHECK_EQ(0, te.GetTokenId(*v8::Utils::OpenHandle(*token1)));
+ {
+ v8::HandleScope hs;
+ v8::Local<v8::String> token3(v8::String::New("3"));
+ CHECK_EQ(2, te.GetTokenId(*v8::Utils::OpenHandle(*token3)));
+ CHECK_EQ(1, te.GetTokenId(*v8::Utils::OpenHandle(*token2)));
+ CHECK_EQ(0, te.GetTokenId(*v8::Utils::OpenHandle(*token1)));
+ }
+ CHECK(!i::TokenEnumeratorTester::token_removed(&te)->at(2));
+ i::Heap::CollectAllGarbage(false);
+ CHECK(i::TokenEnumeratorTester::token_removed(&te)->at(2));
+ CHECK_EQ(1, te.GetTokenId(*v8::Utils::OpenHandle(*token2)));
+ CHECK_EQ(0, te.GetTokenId(*v8::Utils::OpenHandle(*token1)));
+}
+
+
TEST(ProfileNodeFindOrAddChild) {
ProfileNode node(NULL, NULL);
- CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
+ CodeEntry entry1(
+ i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken);
ProfileNode* childNode1 = node.FindOrAddChild(&entry1);
CHECK_NE(NULL, childNode1);
CHECK_EQ(childNode1, node.FindOrAddChild(&entry1));
- CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
+ CodeEntry entry2(
+ i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken);
ProfileNode* childNode2 = node.FindOrAddChild(&entry2);
CHECK_NE(NULL, childNode2);
CHECK_NE(childNode1, childNode2);
CHECK_EQ(childNode1, node.FindOrAddChild(&entry1));
CHECK_EQ(childNode2, node.FindOrAddChild(&entry2));
- CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
+ CodeEntry entry3(
+ i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken);
ProfileNode* childNode3 = node.FindOrAddChild(&entry3);
CHECK_NE(NULL, childNode3);
CHECK_NE(childNode1, childNode3);
@@ -75,9 +117,12 @@ class ProfileTreeTestHelper {
} // namespace
TEST(ProfileTreeAddPathFromStart) {
- CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
- CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
- CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
+ CodeEntry entry1(
+ i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken);
+ CodeEntry entry2(
+ i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken);
+ CodeEntry entry3(
+ i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken);
ProfileTree tree;
ProfileTreeTestHelper helper(&tree);
CHECK_EQ(NULL, helper.Walk(&entry1));
@@ -142,9 +187,12 @@ TEST(ProfileTreeAddPathFromStart) {
TEST(ProfileTreeAddPathFromEnd) {
- CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
- CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
- CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
+ CodeEntry entry1(
+ i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken);
+ CodeEntry entry2(
+ i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken);
+ CodeEntry entry3(
+ i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken);
ProfileTree tree;
ProfileTreeTestHelper helper(&tree);
CHECK_EQ(NULL, helper.Walk(&entry1));
@@ -222,11 +270,30 @@ TEST(ProfileTreeCalculateTotalTicks) {
CHECK_EQ(1, empty_tree.root()->total_ticks());
CHECK_EQ(1, empty_tree.root()->self_ticks());
- CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
- CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
+ CodeEntry entry1(
+ i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken);
CodeEntry* e1_path[] = {&entry1};
Vector<CodeEntry*> e1_path_vec(
e1_path, sizeof(e1_path) / sizeof(e1_path[0]));
+
+ ProfileTree single_child_tree;
+ single_child_tree.AddPathFromStart(e1_path_vec);
+ single_child_tree.root()->IncrementSelfTicks();
+ CHECK_EQ(0, single_child_tree.root()->total_ticks());
+ CHECK_EQ(1, single_child_tree.root()->self_ticks());
+ ProfileTreeTestHelper single_child_helper(&single_child_tree);
+ ProfileNode* node1 = single_child_helper.Walk(&entry1);
+ CHECK_NE(NULL, node1);
+ CHECK_EQ(0, node1->total_ticks());
+ CHECK_EQ(1, node1->self_ticks());
+ single_child_tree.CalculateTotalTicks();
+ CHECK_EQ(2, single_child_tree.root()->total_ticks());
+ CHECK_EQ(1, single_child_tree.root()->self_ticks());
+ CHECK_EQ(1, node1->total_ticks());
+ CHECK_EQ(1, node1->self_ticks());
+
+ CodeEntry entry2(
+ i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken);
CodeEntry* e1_e2_path[] = {&entry1, &entry2};
Vector<CodeEntry*> e1_e2_path_vec(
e1_e2_path, sizeof(e1_e2_path) / sizeof(e1_e2_path[0]));
@@ -241,7 +308,7 @@ TEST(ProfileTreeCalculateTotalTicks) {
// Results in {root,0,0} -> {entry1,0,2} -> {entry2,0,3}
CHECK_EQ(0, flat_tree.root()->total_ticks());
CHECK_EQ(0, flat_tree.root()->self_ticks());
- ProfileNode* node1 = flat_helper.Walk(&entry1);
+ node1 = flat_helper.Walk(&entry1);
CHECK_NE(NULL, node1);
CHECK_EQ(0, node1->total_ticks());
CHECK_EQ(2, node1->self_ticks());
@@ -261,7 +328,8 @@ TEST(ProfileTreeCalculateTotalTicks) {
CodeEntry* e2_path[] = {&entry2};
Vector<CodeEntry*> e2_path_vec(
e2_path, sizeof(e2_path) / sizeof(e2_path[0]));
- CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
+ CodeEntry entry3(
+ i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken);
CodeEntry* e3_path[] = {&entry3};
Vector<CodeEntry*> e3_path_vec(
e3_path, sizeof(e3_path) / sizeof(e3_path[0]));
@@ -316,16 +384,119 @@ TEST(ProfileTreeCalculateTotalTicks) {
}
+TEST(ProfileTreeFilteredClone) {
+ ProfileTree source_tree;
+ const int token0 = 0, token1 = 1, token2 = 2;
+ CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0, token0);
+ CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0, token1);
+ CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0, token0);
+ CodeEntry entry4(
+ i::Logger::FUNCTION_TAG, "", "ddd", "", 0,
+ CodeEntry::kInheritsSecurityToken);
+
+ {
+ CodeEntry* e1_e2_path[] = {&entry1, &entry2};
+ Vector<CodeEntry*> e1_e2_path_vec(
+ e1_e2_path, sizeof(e1_e2_path) / sizeof(e1_e2_path[0]));
+ source_tree.AddPathFromStart(e1_e2_path_vec);
+ CodeEntry* e2_e4_path[] = {&entry2, &entry4};
+ Vector<CodeEntry*> e2_e4_path_vec(
+ e2_e4_path, sizeof(e2_e4_path) / sizeof(e2_e4_path[0]));
+ source_tree.AddPathFromStart(e2_e4_path_vec);
+ CodeEntry* e3_e1_path[] = {&entry3, &entry1};
+ Vector<CodeEntry*> e3_e1_path_vec(
+ e3_e1_path, sizeof(e3_e1_path) / sizeof(e3_e1_path[0]));
+ source_tree.AddPathFromStart(e3_e1_path_vec);
+ CodeEntry* e3_e2_path[] = {&entry3, &entry2};
+ Vector<CodeEntry*> e3_e2_path_vec(
+ e3_e2_path, sizeof(e3_e2_path) / sizeof(e3_e2_path[0]));
+ source_tree.AddPathFromStart(e3_e2_path_vec);
+ source_tree.CalculateTotalTicks();
+ // Results in -> {entry1,0,1,0} -> {entry2,1,1,1}
+ // {root,0,4,-1} -> {entry2,0,1,1} -> {entry4,1,1,inherits}
+ // -> {entry3,0,2,0} -> {entry1,1,1,0}
+ // -> {entry2,1,1,1}
+ CHECK_EQ(4, source_tree.root()->total_ticks());
+ CHECK_EQ(0, source_tree.root()->self_ticks());
+ }
+
+ {
+ ProfileTree token0_tree;
+ token0_tree.FilteredClone(&source_tree, token0);
+ // Should be -> {entry1,1,1,0}
+ // {root,1,4,-1} -> {entry3,1,2,0} -> {entry1,1,1,0}
+ // [self ticks from filtered nodes are attributed to their parents]
+ CHECK_EQ(4, token0_tree.root()->total_ticks());
+ CHECK_EQ(1, token0_tree.root()->self_ticks());
+ ProfileTreeTestHelper token0_helper(&token0_tree);
+ ProfileNode* node1 = token0_helper.Walk(&entry1);
+ CHECK_NE(NULL, node1);
+ CHECK_EQ(1, node1->total_ticks());
+ CHECK_EQ(1, node1->self_ticks());
+ CHECK_EQ(NULL, token0_helper.Walk(&entry2));
+ ProfileNode* node3 = token0_helper.Walk(&entry3);
+ CHECK_NE(NULL, node3);
+ CHECK_EQ(2, node3->total_ticks());
+ CHECK_EQ(1, node3->self_ticks());
+ ProfileNode* node3_1 = token0_helper.Walk(&entry3, &entry1);
+ CHECK_NE(NULL, node3_1);
+ CHECK_EQ(1, node3_1->total_ticks());
+ CHECK_EQ(1, node3_1->self_ticks());
+ CHECK_EQ(NULL, token0_helper.Walk(&entry3, &entry2));
+ }
+
+ {
+ ProfileTree token1_tree;
+ token1_tree.FilteredClone(&source_tree, token1);
+ // Should be
+ // {root,1,4,-1} -> {entry2,2,3,1} -> {entry4,1,1,inherits}
+ // [child nodes referring to the same entry get merged and
+ // their self times summed up]
+ CHECK_EQ(4, token1_tree.root()->total_ticks());
+ CHECK_EQ(1, token1_tree.root()->self_ticks());
+ ProfileTreeTestHelper token1_helper(&token1_tree);
+ CHECK_EQ(NULL, token1_helper.Walk(&entry1));
+ CHECK_EQ(NULL, token1_helper.Walk(&entry3));
+ ProfileNode* node2 = token1_helper.Walk(&entry2);
+ CHECK_NE(NULL, node2);
+ CHECK_EQ(3, node2->total_ticks());
+ CHECK_EQ(2, node2->self_ticks());
+ ProfileNode* node2_4 = token1_helper.Walk(&entry2, &entry4);
+ CHECK_NE(NULL, node2_4);
+ CHECK_EQ(1, node2_4->total_ticks());
+ CHECK_EQ(1, node2_4->self_ticks());
+ }
+
+ {
+ ProfileTree token2_tree;
+ token2_tree.FilteredClone(&source_tree, token2);
+ // Should be
+ // {root,4,4,-1}
+ // [no nodes, all ticks get migrated into root node]
+ CHECK_EQ(4, token2_tree.root()->total_ticks());
+ CHECK_EQ(4, token2_tree.root()->self_ticks());
+ ProfileTreeTestHelper token2_helper(&token2_tree);
+ CHECK_EQ(NULL, token2_helper.Walk(&entry1));
+ CHECK_EQ(NULL, token2_helper.Walk(&entry2));
+ CHECK_EQ(NULL, token2_helper.Walk(&entry3));
+ }
+}
+
+
static inline i::Address ToAddress(int n) {
return reinterpret_cast<i::Address>(n);
}
TEST(CodeMapAddCode) {
CodeMap code_map;
- CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
- CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
- CodeEntry entry3(i::Logger::FUNCTION_TAG, "", "ccc", "", 0);
- CodeEntry entry4(i::Logger::FUNCTION_TAG, "", "ddd", "", 0);
+ CodeEntry entry1(
+ i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken);
+ CodeEntry entry2(
+ i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken);
+ CodeEntry entry3(
+ i::Logger::FUNCTION_TAG, "", "ccc", "", 0, CodeEntry::kNoSecurityToken);
+ CodeEntry entry4(
+ i::Logger::FUNCTION_TAG, "", "ddd", "", 0, CodeEntry::kNoSecurityToken);
code_map.AddCode(ToAddress(0x1500), &entry1, 0x200);
code_map.AddCode(ToAddress(0x1700), &entry2, 0x100);
code_map.AddCode(ToAddress(0x1900), &entry3, 0x50);
@@ -352,8 +523,10 @@ TEST(CodeMapAddCode) {
TEST(CodeMapMoveAndDeleteCode) {
CodeMap code_map;
- CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0);
- CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0);
+ CodeEntry entry1(
+ i::Logger::FUNCTION_TAG, "", "aaa", "", 0, CodeEntry::kNoSecurityToken);
+ CodeEntry entry2(
+ i::Logger::FUNCTION_TAG, "", "bbb", "", 0, CodeEntry::kNoSecurityToken);
code_map.AddCode(ToAddress(0x1500), &entry1, 0x200);
code_map.AddCode(ToAddress(0x1700), &entry2, 0x100);
CHECK_EQ(&entry1, code_map.FindEntry(ToAddress(0x1500)));
@@ -425,7 +598,8 @@ TEST(RecordTickSample) {
sample3.frames_count = 2;
generator.RecordTickSample(sample3);
- CpuProfile* profile = profiles.StopProfiling("", 1);
+ CpuProfile* profile =
+ profiles.StopProfiling(CodeEntry::kNoSecurityToken, "", 1);
CHECK_NE(NULL, profile);
ProfileTreeTestHelper top_down_test_helper(profile->top_down());
CHECK_EQ(NULL, top_down_test_helper.Walk(entry2));
« no previous file with comments | « test/cctest/test-log-stack-tracer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698