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 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 i::OS::SNPrintF(title, "%d", i); | 898 i::OS::SNPrintF(title, "%d", i); |
899 // UID must be > 0. | 899 // UID must be > 0. |
900 CHECK(collection.StartProfiling(title.start(), i + 1, false)); | 900 CHECK(collection.StartProfiling(title.start(), i + 1, false)); |
901 titles[i] = title.start(); | 901 titles[i] = title.start(); |
902 } | 902 } |
903 CHECK(!collection.StartProfiling( | 903 CHECK(!collection.StartProfiling( |
904 "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1, false)); | 904 "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1, false)); |
905 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) | 905 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) |
906 i::DeleteArray(titles[i]); | 906 i::DeleteArray(titles[i]); |
907 } | 907 } |
| 908 |
| 909 |
| 910 static const v8::CpuProfileNode* PickChild(const v8::CpuProfileNode* parent, |
| 911 const char* name) { |
| 912 for (int i = 0; i < parent->GetChildrenCount(); ++i) { |
| 913 const v8::CpuProfileNode* child = parent->GetChild(i); |
| 914 v8::String::AsciiValue function_name(child->GetFunctionName()); |
| 915 if (strcmp(*function_name, name) == 0) return child; |
| 916 } |
| 917 return NULL; |
| 918 } |
| 919 |
| 920 |
| 921 TEST(ProfileNodeScriptId) { |
| 922 // This test does not pass with inlining enabled since inlined functions |
| 923 // don't appear in the stack trace. |
| 924 i::FLAG_use_inlining = false; |
| 925 |
| 926 const char* extensions[] = { "v8/profiler" }; |
| 927 v8::ExtensionConfiguration config(1, extensions); |
| 928 LocalContext env(&config); |
| 929 v8::HandleScope hs(env->GetIsolate()); |
| 930 |
| 931 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); |
| 932 CHECK_EQ(0, profiler->GetProfileCount()); |
| 933 v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::New( |
| 934 "function a() { startProfiling(); }\n")); |
| 935 script_a->Run(); |
| 936 v8::Handle<v8::Script> script_b = v8::Script::Compile(v8::String::New( |
| 937 "function b() { a(); }\n" |
| 938 "b();\n" |
| 939 "stopProfiling();\n")); |
| 940 script_b->Run(); |
| 941 CHECK_EQ(1, profiler->GetProfileCount()); |
| 942 const v8::CpuProfile* profile = profiler->GetCpuProfile(0); |
| 943 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); |
| 944 reinterpret_cast<ProfileNode*>( |
| 945 const_cast<v8::CpuProfileNode*>(current))->Print(0); |
| 946 // The tree should look like this: |
| 947 // (root) |
| 948 // (anonymous function) |
| 949 // b |
| 950 // a |
| 951 // There can also be: |
| 952 // startProfiling |
| 953 // if the sampler managed to get a tick. |
| 954 current = PickChild(current, i::ProfileGenerator::kAnonymousFunctionName); |
| 955 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); |
| 956 |
| 957 current = PickChild(current, "b"); |
| 958 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); |
| 959 CHECK_EQ(script_b->GetId(), current->GetScriptId()); |
| 960 |
| 961 current = PickChild(current, "a"); |
| 962 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); |
| 963 CHECK_EQ(script_a->GetId(), current->GetScriptId()); |
| 964 } |
| 965 |
| 966 |
OLD | NEW |