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 // 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", 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->code()); | |
1098 i::Address code_address = func->code()->address(); | |
1099 CHECK_NE(NULL, code_address); | |
1100 | |
1101 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | |
1102 profiles->StartProfiling("", false); | |
1103 ProfileGenerator generator(profiles); | |
1104 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | |
1105 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); | |
1106 processor->Start(); | |
1107 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | |
1108 | |
1109 // Enqueue code creation events. | |
1110 i::Handle<i::String> str = factory->NewStringFromAsciiChecked(func_name); | |
1111 int line = 1; | |
1112 int column = 1; | |
1113 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, | |
1114 func->code(), | |
1115 func->shared(), | |
1116 NULL, | |
1117 *str, | |
1118 line, | |
1119 column); | |
1120 | |
1121 // Enqueue a tick event to enable code events processing. | |
1122 EnqueueTickSampleEvent(processor.get(), code_address); | |
1123 | |
1124 processor->StopSynchronously(); | |
1125 | |
1126 CpuProfile* profile = profiles->StopProfiling(""); | |
1127 CHECK_NE(NULL, profile); | |
1128 | |
1129 // Check the state of profile generator. | |
1130 CodeEntry* func_entry = generator.code_map()->FindEntry(code_address); | |
1131 CHECK_NE(NULL, func_entry); | |
1132 CHECK_EQ(func_name, func_entry->name()); | |
1133 const i::JITLineInfoTable* line_info = func_entry->line_info(); | |
1134 CHECK_NE(NULL, line_info); | |
alph
2014/08/15 12:10:47
I've got the test failing at this line for ia32 ta
Denis Pravdin
2014/08/15 20:57:55
Well, I found out what causes this test failure bu
alph
2014/08/19 14:23:35
Could you please check the 'shared' and 'code' obj
Denis Pravdin
2014/09/01 09:35:13
Yes, you're right.
I debugged the test and found o
| |
1135 CHECK_EQ(false, line_info->Empty()); | |
1136 | |
1137 // Check the hit source lines using V8 Public APIs. | |
1138 const i::ProfileTree* tree = profile->top_down(); | |
1139 ProfileNode* root = tree->root(); | |
1140 CHECK_NE(NULL, root); | |
1141 ProfileNode* func_node = root->FindChild(func_entry); | |
1142 CHECK_NE(NULL, func_node); | |
1143 | |
1144 // Add 10 faked ticks to source line #5. | |
1145 int hit_line = 5; | |
1146 int hit_count = 10; | |
1147 for (int i = 0; i < hit_count; i++) | |
1148 func_node->IncrementLineTicks(hit_line); | |
1149 | |
1150 unsigned int line_count = func_node->GetHitLineCount(); | |
1151 CHECK_EQ(2, line_count); // Expect two hit source lines - #1 and #5. | |
1152 ScopedVector<v8::CpuProfileNode::LineTick> entries(line_count); | |
1153 CHECK_EQ(true, func_node->GetLineTicks(&entries[0], line_count)); | |
1154 int value = 0; | |
1155 for (int i = 0; i < entries.length(); i++) | |
1156 if (entries[i].line == hit_line) { | |
1157 value = entries[i].hit_count; | |
1158 break; | |
1159 } | |
1160 CHECK_EQ(hit_count, value); | |
1161 } | |
1162 | |
1163 | |
1067 static const char* call_function_test_source = "function bar(iterations) {\n" | 1164 static const char* call_function_test_source = "function bar(iterations) {\n" |
1068 "}\n" | 1165 "}\n" |
1069 "function start(duration) {\n" | 1166 "function start(duration) {\n" |
1070 " var start = Date.now();\n" | 1167 " var start = Date.now();\n" |
1071 " while (Date.now() - start < duration) {\n" | 1168 " while (Date.now() - start < duration) {\n" |
1072 " try {\n" | 1169 " try {\n" |
1073 " bar.call(this, 10 * 1000);\n" | 1170 " bar.call(this, 10 * 1000);\n" |
1074 " } catch(e) {}\n" | 1171 " } catch(e) {}\n" |
1075 " }\n" | 1172 " }\n" |
1076 "}"; | 1173 "}"; |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1674 inner_profile = NULL; | 1771 inner_profile = NULL; |
1675 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1772 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1676 | 1773 |
1677 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); | 1774 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); |
1678 CHECK(outer_profile); | 1775 CHECK(outer_profile); |
1679 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1776 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
1680 outer_profile->Delete(); | 1777 outer_profile->Delete(); |
1681 outer_profile = NULL; | 1778 outer_profile = NULL; |
1682 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1779 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1683 } | 1780 } |
OLD | NEW |