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

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: git cl format 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"
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",
1090 func_name, func_name);
1091
1092 CompileRun(script.start());
1093
1094 i::Handle<i::JSFunction> func = v8::Utils::OpenHandle(
1095 *v8::Local<v8::Function>::Cast((*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()) {
yurys 2014/09/10 08:05:14 You can use "%NeverOptimizeFunction(func)" or %Opt
Denis Pravdin 2014/09/11 08:14:44 The test should check optimized code also. I sugge
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, code, func->shared(), NULL,
1122 *str, line, column);
1123
1124 // Enqueue a tick event to enable code events processing.
1125 EnqueueTickSampleEvent(processor.get(), code_address);
1126
1127 processor->StopSynchronously();
1128
1129 CpuProfile* profile = profiles->StopProfiling("");
1130 CHECK_NE(NULL, profile);
1131
1132 // Check the state of profile generator.
1133 CodeEntry* func_entry = generator.code_map()->FindEntry(code_address);
1134 CHECK_NE(NULL, func_entry);
1135 CHECK_EQ(func_name, func_entry->name());
1136 const i::JITLineInfoTable* line_info = func_entry->line_info();
1137 CHECK_NE(NULL, line_info);
1138 CHECK_EQ(false, line_info->Empty());
yurys 2014/09/10 08:05:14 nit: CHECK(!line_info->Empty())
1139
1140 // Check the hit source lines using V8 Public APIs.
1141 const i::ProfileTree* tree = profile->top_down();
1142 ProfileNode* root = tree->root();
1143 CHECK_NE(NULL, root);
1144 ProfileNode* func_node = root->FindChild(func_entry);
1145 CHECK_NE(NULL, func_node);
1146
1147 // Add 10 faked ticks to source line #5.
1148 int hit_line = 5;
1149 int hit_count = 10;
1150 for (int i = 0; i < hit_count; i++) func_node->IncrementLineTicks(hit_line);
1151
1152 unsigned int line_count = func_node->GetHitLineCount();
1153 CHECK_EQ(2, line_count); // Expect two hit source lines - #1 and #5.
1154 ScopedVector<v8::CpuProfileNode::LineTick> entries(line_count);
1155 CHECK_EQ(true, func_node->GetLineTicks(&entries[0], line_count));
1156 int value = 0;
1157 for (int i = 0; i < entries.length(); i++)
1158 if (entries[i].line == hit_line) {
1159 value = entries[i].hit_count;
1160 break;
1161 }
1162 CHECK_EQ(hit_count, value);
1163 }
1164
1165
1067 static const char* call_function_test_source = "function bar(iterations) {\n" 1166 static const char* call_function_test_source = "function bar(iterations) {\n"
1068 "}\n" 1167 "}\n"
1069 "function start(duration) {\n" 1168 "function start(duration) {\n"
1070 " var start = Date.now();\n" 1169 " var start = Date.now();\n"
1071 " while (Date.now() - start < duration) {\n" 1170 " while (Date.now() - start < duration) {\n"
1072 " try {\n" 1171 " try {\n"
1073 " bar.call(this, 10 * 1000);\n" 1172 " bar.call(this, 10 * 1000);\n"
1074 " } catch(e) {}\n" 1173 " } catch(e) {}\n"
1075 " }\n" 1174 " }\n"
1076 "}"; 1175 "}";
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 inner_profile = NULL; 1773 inner_profile = NULL;
1675 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1774 CHECK_EQ(0, iprofiler->GetProfilesCount());
1676 1775
1677 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); 1776 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer);
1678 CHECK(outer_profile); 1777 CHECK(outer_profile);
1679 CHECK_EQ(1, iprofiler->GetProfilesCount()); 1778 CHECK_EQ(1, iprofiler->GetProfilesCount());
1680 outer_profile->Delete(); 1779 outer_profile->Delete();
1681 outer_profile = NULL; 1780 outer_profile = NULL;
1682 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1781 CHECK_EQ(0, iprofiler->GetProfilesCount());
1683 } 1782 }
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