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 896 matching lines...) Loading... | |
907 reinterpret_cast<i::CpuProfile*>( | 907 reinterpret_cast<i::CpuProfile*>( |
908 const_cast<v8::CpuProfile*>(profile))->Print(); | 908 const_cast<v8::CpuProfile*>(profile))->Print(); |
909 | 909 |
910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
911 GetChild(root, "start"); | 911 GetChild(root, "start"); |
912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
913 GetChild(startNode, "fooMethod"); | 913 GetChild(startNode, "fooMethod"); |
914 | 914 |
915 cpu_profiler->DeleteAllCpuProfiles(); | 915 cpu_profiler->DeleteAllCpuProfiles(); |
916 } | 916 } |
917 | |
918 | |
919 static const char* bound_function_test_source = "function foo(iterations) {\n" | |
920 " var r = 0;\n" | |
921 " for (var i = 0; i < iterations; i++) { r += i; }\n" | |
922 " return r;\n" | |
923 "}\n" | |
924 "function start(duration) {\n" | |
925 " var callback = foo.bind(this);\n" | |
926 " var start = Date.now();\n" | |
927 " while (Date.now() - start < duration) {\n" | |
928 " callback(10 * 1000);\n" | |
929 " }\n" | |
930 "}"; | |
931 | |
932 | |
933 TEST(BoundFunctionCall) { | |
934 LocalContext env; | |
935 v8::HandleScope scope(env->GetIsolate()); | |
936 | |
937 v8::Script::Compile(v8::String::New(bound_function_test_source))->Run(); | |
938 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | |
939 env->Global()->Get(v8::String::New("start"))); | |
940 | |
941 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
942 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
943 | |
944 cpu_profiler->StartCpuProfiling(profile_name); | |
945 int32_t duration_ms = 100; | |
946 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | |
947 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
948 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
949 | |
950 CHECK_NE(NULL, profile); | |
951 // Dump collected profile to have a better diagnostic in case of failure. | |
952 reinterpret_cast<i::CpuProfile*>( | |
953 const_cast<v8::CpuProfile*>(profile))->Print(); | |
954 | |
955 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | |
956 GetChild(root, "start"); | |
957 ScopedVector<v8::Handle<v8::String> > names(3); | |
958 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | |
959 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | |
960 names[2] = v8::String::New("start"); | |
961 // Don't allow |foo| node to be at the top level. | |
962 CheckChildrenNames(root, names); | |
loislo
2013/06/25 13:42:43
Do you have a guarantee that profiler ever hit int
yurys
2013/06/26 05:18:12
Yes, most of the time is spent inside the callback
| |
963 | |
964 cpu_profiler->DeleteAllCpuProfiles(); | |
965 } | |
OLD | NEW |