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

Side by Side Diff: test/cctest/test-cpu-profiler.cc

Issue 424973004: Extend CPU profiler with mapping ticks to source lines (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed the various code object issue in the test Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« src/profile-generator.cc ('K') | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 CheckChildrenNames(root, names); 1057 CheckChildrenNames(root, names);
1058 1058
1059 const v8::CpuProfileNode* startNode = 1059 const v8::CpuProfileNode* startNode =
1060 GetChild(env->GetIsolate(), root, "start"); 1060 GetChild(env->GetIsolate(), root, "start");
1061 GetChild(env->GetIsolate(), startNode, "foo"); 1061 GetChild(env->GetIsolate(), startNode, "foo");
1062 1062
1063 profile->Delete(); 1063 profile->Delete();
1064 } 1064 }
1065 1065
1066 1066
1067 // This tests checks distribution of the samples through the source lines.
1068 TEST(TickLines) {
1069 CcTest::InitializeVM();
1070 LocalContext env;
1071 i::Isolate* isolate = CcTest::i_isolate();
1072 i::Factory* factory = isolate->factory();
1073 i::HandleScope scope(isolate);
1074
1075 i::EmbeddedVector<char, 512> script;
1076
1077 const char* func_name = "func";
1078 i::SNPrintF(script,
1079 "function %s() {\n"
alph 2014/09/09 14:47:34 Does the test function need to be that complex? Th
1080 " for (var i = 0; i < 10; ++i) {\n"
1081 " var n = 0;\n"
1082 " var m = 100*100;\n"
1083 " while (m > 1) {\n"
1084 " m--;\n"
1085 " n += m * m * m;\n"
1086 " }\n"
1087 " }\n"
1088 "}\n"
1089 "%s();\n", func_name, func_name);
1090
1091 CompileRun(script.start());
1092
1093 i::Handle<i::JSFunction> func = v8::Utils::OpenHandle(
1094 *v8::Local<v8::Function>::Cast(
1095 (*env)->Global()->Get(v8_str(func_name))));
1096 CHECK_NE(NULL, func->shared());
1097 CHECK_NE(NULL, func->shared()->code());
1098 i::Code* code = NULL;
1099 if (func->code()->is_optimized_code()) {
1100 code = func->code();
1101 } else {
1102 CHECK(func->shared()->code() == func->code() || !i::FLAG_crankshaft);
1103 code = func->shared()->code();
1104 }
1105 CHECK_NE(NULL, code);
1106 i::Address code_address = code->address();
1107 CHECK_NE(NULL, code_address);
1108
1109 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
1110 profiles->StartProfiling("", false);
1111 ProfileGenerator generator(profiles);
1112 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
1113 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100)));
1114 processor->Start();
1115 CpuProfiler profiler(isolate, profiles, &generator, processor.get());
1116
1117 // Enqueue code creation events.
1118 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name);
1119 int line = 1;
1120 int column = 1;
1121 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG,
1122 code,
1123 func->shared(),
1124 NULL,
1125 *str,
1126 line,
1127 column);
1128
1129 // Enqueue a tick event to enable code events processing.
1130 EnqueueTickSampleEvent(processor.get(), code_address);
1131
1132 processor->StopSynchronously();
1133
1134 CpuProfile* profile = profiles->StopProfiling("");
1135 CHECK_NE(NULL, profile);
1136
1137 // Check the state of profile generator.
1138 CodeEntry* func_entry = generator.code_map()->FindEntry(code_address);
1139 CHECK_NE(NULL, func_entry);
1140 CHECK_EQ(func_name, func_entry->name());
1141 const i::JITLineInfoTable* line_info = func_entry->line_info();
1142 CHECK_NE(NULL, line_info);
1143 CHECK_EQ(false, line_info->Empty());
1144
1145 // Check the hit source lines using V8 Public APIs.
1146 const i::ProfileTree* tree = profile->top_down();
1147 ProfileNode* root = tree->root();
1148 CHECK_NE(NULL, root);
1149 ProfileNode* func_node = root->FindChild(func_entry);
1150 CHECK_NE(NULL, func_node);
1151
1152 // Add 10 faked ticks to source line #5.
1153 int hit_line = 5;
1154 int hit_count = 10;
1155 for (int i = 0; i < hit_count; i++)
1156 func_node->IncrementLineTicks(hit_line);
1157
1158 unsigned int line_count = func_node->GetHitLineCount();
1159 CHECK_EQ(2, line_count); // Expect two hit source lines - #1 and #5.
1160 ScopedVector<v8::CpuProfileNode::LineTick> entries(line_count);
1161 CHECK_EQ(true, func_node->GetLineTicks(&entries[0], line_count));
1162 int value = 0;
1163 for (int i = 0; i < entries.length(); i++)
1164 if (entries[i].line == hit_line) {
1165 value = entries[i].hit_count;
1166 break;
1167 }
1168 CHECK_EQ(hit_count, value);
1169 }
1170
1171
1067 static const char* call_function_test_source = "function bar(iterations) {\n" 1172 static const char* call_function_test_source = "function bar(iterations) {\n"
1068 "}\n" 1173 "}\n"
1069 "function start(duration) {\n" 1174 "function start(duration) {\n"
1070 " var start = Date.now();\n" 1175 " var start = Date.now();\n"
1071 " while (Date.now() - start < duration) {\n" 1176 " while (Date.now() - start < duration) {\n"
1072 " try {\n" 1177 " try {\n"
1073 " bar.call(this, 10 * 1000);\n" 1178 " bar.call(this, 10 * 1000);\n"
1074 " } catch(e) {}\n" 1179 " } catch(e) {}\n"
1075 " }\n" 1180 " }\n"
1076 "}"; 1181 "}";
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 inner_profile = NULL; 1779 inner_profile = NULL;
1675 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1780 CHECK_EQ(0, iprofiler->GetProfilesCount());
1676 1781
1677 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); 1782 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer);
1678 CHECK(outer_profile); 1783 CHECK(outer_profile);
1679 CHECK_EQ(1, iprofiler->GetProfilesCount()); 1784 CHECK_EQ(1, iprofiler->GetProfilesCount());
1680 outer_profile->Delete(); 1785 outer_profile->Delete();
1681 outer_profile = NULL; 1786 outer_profile = NULL;
1682 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1787 CHECK_EQ(0, iprofiler->GetProfilesCount());
1683 } 1788 }
OLDNEW
« src/profile-generator.cc ('K') | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698