Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 static i::SharedFunctionInfo* GetFunctionInfoFromHeap(i::Isolate* isolate, | |
| 1068 const char* name) { | |
| 1069 CHECK_NE(NULL, isolate); | |
| 1070 i::Heap* heap = isolate->heap(); | |
| 1071 CHECK_NE(NULL, heap); | |
| 1072 | |
| 1073 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, | |
| 1074 "GetFunctionInfoFromHeap"); | |
| 1075 | |
| 1076 i::HandleScope scope(isolate); | |
| 1077 i::HeapIterator iterator(heap); | |
| 1078 i::DisallowHeapAllocation no_gc; | |
| 1079 | |
| 1080 // Iterate the heap to find shared function info objects. | |
| 1081 for (i::HeapObject* obj = iterator.next(); | |
| 1082 obj != NULL; | |
| 1083 obj = iterator.next()) { | |
| 1084 if (!obj->IsSharedFunctionInfo()) continue; | |
| 1085 i::SharedFunctionInfo* sfi = i::SharedFunctionInfo::cast(obj); | |
| 1086 if (sfi->is_compiled() | |
| 1087 && (!sfi->script()->IsScript() | |
| 1088 || i::Script::cast(sfi->script())->HasValidSource())) { | |
| 1089 i::Handle<i::String> func_name(sfi->DebugName()); | |
| 1090 i::SmartArrayPointer<char> str = | |
| 1091 sfi->DebugName()->ToCString(i::DISALLOW_NULLS, | |
| 1092 i::ROBUST_STRING_TRAVERSAL); | |
| 1093 if (strcmp(str.get(), name) == 0) | |
|
alph
2014/08/11 12:18:15
It's better to make a v8 heap string out of 'name'
| |
| 1094 return sfi; | |
| 1095 } | |
| 1096 } | |
| 1097 | |
| 1098 return NULL; | |
| 1099 } | |
| 1100 | |
| 1101 | |
| 1102 // This tests checks distribution of the samples through the source lines. | |
| 1103 TEST(TickLines) { | |
| 1104 CcTest::InitializeVM(); | |
| 1105 LocalContext env; | |
| 1106 i::Isolate* isolate = CcTest::i_isolate(); | |
| 1107 i::Factory* factory = isolate->factory(); | |
| 1108 i::HandleScope scope(isolate); | |
| 1109 | |
| 1110 i::EmbeddedVector<char, 512> source; | |
| 1111 const char* foo_name = "foo"; | |
| 1112 i::SNPrintF(source, | |
| 1113 "(function %s(timeout) {\n" | |
| 1114 " this.mmm = 0;\n" | |
| 1115 " var start = Date.now();\n" | |
| 1116 " while (Date.now() - start < timeout) {\n" | |
|
alph
2014/08/11 12:18:15
This test bound to be flaky as it depends on the t
| |
| 1117 " var n = 100*1000;\n" | |
| 1118 " while(n > 1) {\n" | |
| 1119 " n--;\n" | |
| 1120 " this.mmm += n * n * n;\n" | |
| 1121 " }\n" | |
| 1122 " }\n" | |
| 1123 "})(%d)\n", foo_name, 100); | |
| 1124 | |
| 1125 // Compile the source. The compiled functions with relocation info are | |
| 1126 // located in the heap. | |
| 1127 CompileRun(source.start()); | |
| 1128 | |
| 1129 i::SharedFunctionInfo* shared = GetFunctionInfoFromHeap(isolate, foo_name); | |
|
alph
2014/08/11 12:18:15
You can get the JSFunction object out of global co
| |
| 1130 CHECK_NE(NULL, shared); | |
| 1131 i::Code* foo_code = shared->code(); | |
| 1132 CHECK_NE(NULL, foo_code); | |
| 1133 | |
| 1134 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | |
| 1135 profiles->StartProfiling("", false); | |
| 1136 ProfileGenerator generator(profiles); | |
| 1137 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | |
| 1138 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); | |
| 1139 processor->Start(); | |
| 1140 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | |
| 1141 | |
| 1142 // Enqueue code creation events. | |
| 1143 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(foo_name); | |
| 1144 int line = 1; | |
| 1145 int column = 1; | |
| 1146 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, | |
| 1147 foo_code, | |
| 1148 shared, | |
| 1149 NULL, | |
| 1150 *str, | |
| 1151 line, | |
| 1152 column); | |
| 1153 | |
| 1154 // Enqueue a tick event to enable code events processing. | |
| 1155 EnqueueTickSampleEvent(processor.get(), foo_code->address()); | |
| 1156 | |
| 1157 processor->StopSynchronously(); | |
| 1158 | |
| 1159 CpuProfile* profile = profiles->StopProfiling(""); | |
| 1160 CHECK_NE(NULL, profile); | |
| 1161 | |
| 1162 // Check the state of profile generator. | |
| 1163 CodeEntry* foo = generator.code_map()->FindEntry(foo_code->address()); | |
| 1164 CHECK_NE(NULL, foo); | |
| 1165 CHECK_EQ(foo_name, foo->name()); | |
| 1166 const i::JITLineInfoTable* foo_line_info = foo->line_info(); | |
| 1167 CHECK_NE(NULL, foo_line_info); | |
| 1168 CHECK_EQ(false, foo_line_info->Empty()); | |
| 1169 | |
| 1170 // Check the hit source lines using V8 Public APIs. | |
| 1171 const i::ProfileTree* tree = profile->top_down(); | |
| 1172 ProfileNode* root = tree->root(); | |
| 1173 CHECK_NE(NULL, root); | |
| 1174 ProfileNode* foo_node = root->FindChild(foo); | |
| 1175 CHECK_NE(NULL, foo_node); | |
| 1176 | |
| 1177 // Add 10 faked ticks to source line #5. | |
| 1178 int hit_line = 5; | |
| 1179 int hit_count = 10; | |
| 1180 for (int i = 0; i < hit_count; i++) | |
| 1181 foo_node->IncrementLineTicks(hit_line); | |
| 1182 | |
| 1183 unsigned int line_count = foo_node->GetHitLineCount(); | |
| 1184 CHECK_EQ(2, line_count); // Expect two hit source lines - #1 and #5. | |
| 1185 ScopedVector<v8::CpuProfileNode::LineTick> entries(line_count); | |
| 1186 CHECK_EQ(true, foo_node->GetLineTicks(&entries[0], line_count)); | |
| 1187 int value = 0; | |
| 1188 for (int i = 0; i < entries.length(); i++) | |
| 1189 if (entries[i].line == hit_line) { | |
| 1190 value = entries[i].hit_count; | |
| 1191 break; | |
| 1192 } | |
| 1193 CHECK_EQ(hit_count, value); | |
| 1194 } | |
| 1195 | |
| 1196 | |
| 1067 static const char* call_function_test_source = "function bar(iterations) {\n" | 1197 static const char* call_function_test_source = "function bar(iterations) {\n" |
| 1068 "}\n" | 1198 "}\n" |
| 1069 "function start(duration) {\n" | 1199 "function start(duration) {\n" |
| 1070 " var start = Date.now();\n" | 1200 " var start = Date.now();\n" |
| 1071 " while (Date.now() - start < duration) {\n" | 1201 " while (Date.now() - start < duration) {\n" |
| 1072 " try {\n" | 1202 " try {\n" |
| 1073 " bar.call(this, 10 * 1000);\n" | 1203 " bar.call(this, 10 * 1000);\n" |
| 1074 " } catch(e) {}\n" | 1204 " } catch(e) {}\n" |
| 1075 " }\n" | 1205 " }\n" |
| 1076 "}"; | 1206 "}"; |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1676 inner_profile = NULL; | 1806 inner_profile = NULL; |
| 1677 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1807 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1678 | 1808 |
| 1679 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); | 1809 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); |
| 1680 CHECK(outer_profile); | 1810 CHECK(outer_profile); |
| 1681 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1811 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
| 1682 outer_profile->Delete(); | 1812 outer_profile->Delete(); |
| 1683 outer_profile = NULL; | 1813 outer_profile = NULL; |
| 1684 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1814 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1685 } | 1815 } |
| OLD | NEW |