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

Side by Side Diff: test/cctest/test-profile-generator.cc

Issue 16932003: CPUProfiler: unflake flaky CPUProfiler tests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: HandleScope was moved one line down Created 7 years, 6 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
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 // 27 //
28 // Tests of profiles generator and utilities. 28 // Tests of profiles generator and utilities.
29 29
30 #include "v8.h" 30 #include "v8.h"
31 #include "profile-generator-inl.h" 31 #include "profile-generator-inl.h"
32 #include "cctest.h" 32 #include "cctest.h"
33 #include "profiler-extension.h"
33 #include "../include/v8-profiler.h" 34 #include "../include/v8-profiler.h"
34 35
35 using i::CodeEntry; 36 using i::CodeEntry;
36 using i::CodeMap; 37 using i::CodeMap;
37 using i::CpuProfile; 38 using i::CpuProfile;
38 using i::CpuProfiler; 39 using i::CpuProfiler;
39 using i::CpuProfilesCollection; 40 using i::CpuProfilesCollection;
40 using i::ProfileNode; 41 using i::ProfileNode;
41 using i::ProfileTree; 42 using i::ProfileTree;
42 using i::ProfileGenerator; 43 using i::ProfileGenerator;
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 CpuProfile* profile = 791 CpuProfile* profile =
791 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); 792 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
792 int nodeId = 1; 793 int nodeId = 1;
793 CheckNodeIds(profile->top_down()->root(), &nodeId); 794 CheckNodeIds(profile->top_down()->root(), &nodeId);
794 CHECK_EQ(3, nodeId - 1); 795 CHECK_EQ(3, nodeId - 1);
795 796
796 CHECK_EQ(0, profile->samples_count()); 797 CHECK_EQ(0, profile->samples_count());
797 } 798 }
798 799
799 800
800 // --- P r o f i l e r E x t e n s i o n ---
801
802 class ProfilerExtension : public v8::Extension {
803 public:
804 ProfilerExtension() : v8::Extension("v8/profiler", kSource) { }
805 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
806 v8::Handle<v8::String> name);
807 static v8::Handle<v8::Value> StartProfiling(const v8::Arguments& args);
808 static v8::Handle<v8::Value> StopProfiling(const v8::Arguments& args);
809 private:
810 static const char* kSource;
811 };
812
813
814 const char* ProfilerExtension::kSource =
815 "native function startProfiling();"
816 "native function stopProfiling();";
817
818 v8::Handle<v8::FunctionTemplate> ProfilerExtension::GetNativeFunction(
819 v8::Handle<v8::String> name) {
820 if (name->Equals(v8::String::New("startProfiling"))) {
821 return v8::FunctionTemplate::New(ProfilerExtension::StartProfiling);
822 } else if (name->Equals(v8::String::New("stopProfiling"))) {
823 return v8::FunctionTemplate::New(ProfilerExtension::StopProfiling);
824 } else {
825 CHECK(false);
826 return v8::Handle<v8::FunctionTemplate>();
827 }
828 }
829
830
831 v8::Handle<v8::Value> ProfilerExtension::StartProfiling(
832 const v8::Arguments& args) {
833 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
834 if (args.Length() > 0)
835 cpu_profiler->StartCpuProfiling(args[0].As<v8::String>());
836 else
837 cpu_profiler->StartCpuProfiling(v8::String::New(""));
838 return v8::Undefined();
839 }
840
841
842 v8::Handle<v8::Value> ProfilerExtension::StopProfiling(
843 const v8::Arguments& args) {
844 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
845 if (args.Length() > 0)
846 cpu_profiler->StopCpuProfiling(args[0].As<v8::String>());
847 else
848 cpu_profiler->StopCpuProfiling(v8::String::New(""));
849 return v8::Undefined();
850 }
851
852
853 static ProfilerExtension kProfilerExtension;
854 v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension);
855
856 static const ProfileNode* PickChild(const ProfileNode* parent, 801 static const ProfileNode* PickChild(const ProfileNode* parent,
857 const char* name) { 802 const char* name) {
858 for (int i = 0; i < parent->children()->length(); ++i) { 803 for (int i = 0; i < parent->children()->length(); ++i) {
859 const ProfileNode* child = parent->children()->at(i); 804 const ProfileNode* child = parent->children()->at(i);
860 if (strcmp(child->entry()->name(), name) == 0) return child; 805 if (strcmp(child->entry()->name(), name) == 0) return child;
861 } 806 }
862 return NULL; 807 return NULL;
863 } 808 }
864 809
865 810
866 TEST(RecordStackTraceAtStartProfiling) { 811 TEST(RecordStackTraceAtStartProfiling) {
867 // This test does not pass with inlining enabled since inlined functions 812 // This test does not pass with inlining enabled since inlined functions
868 // don't appear in the stack trace. 813 // don't appear in the stack trace.
869 i::FLAG_use_inlining = false; 814 i::FLAG_use_inlining = false;
870 815
871 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 816 v8::Isolate* isolate = v8::Isolate::GetCurrent();
872 v8::HandleScope scope(isolate); 817 v8::HandleScope scope(isolate);
873 const char* extensions[] = { "v8/profiler" }; 818 const char* extensions[] = { i::ProfilerExtension::kName };
874 v8::ExtensionConfiguration config(1, extensions); 819 v8::ExtensionConfiguration config(1, extensions);
875 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); 820 v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
876 context->Enter(); 821 context->Enter();
877 822
878 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler(); 823 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
879 CHECK_EQ(0, profiler->GetProfilesCount()); 824 CHECK_EQ(0, profiler->GetProfilesCount());
880 CompileRun( 825 CompileRun(
881 "function c() { startProfiling(); }\n" 826 "function c() { startProfiling(); }\n"
882 "function b() { c(); }\n" 827 "function b() { c(); }\n"
883 "function a() { b(); }\n" 828 "function a() { b(); }\n"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 i::OS::SNPrintF(title, "%d", i); 868 i::OS::SNPrintF(title, "%d", i);
924 // UID must be > 0. 869 // UID must be > 0.
925 CHECK(collection.StartProfiling(title.start(), i + 1, false)); 870 CHECK(collection.StartProfiling(title.start(), i + 1, false));
926 titles[i] = title.start(); 871 titles[i] = title.start();
927 } 872 }
928 CHECK(!collection.StartProfiling( 873 CHECK(!collection.StartProfiling(
929 "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1, false)); 874 "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1, false));
930 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) 875 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i)
931 i::DeleteArray(titles[i]); 876 i::DeleteArray(titles[i]);
932 } 877 }
OLDNEW
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698