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

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 2175233003: Replace SmartPointer<T> with unique_ptr<T> (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@smart-array
Patch Set: Created 4 years, 4 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 2896 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 { 2907 {
2908 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile(); 2908 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile();
2909 CHECK(profile == nullptr); 2909 CHECK(profile == nullptr);
2910 } 2910 }
2911 2911
2912 int count_1024 = 0; 2912 int count_1024 = 0;
2913 { 2913 {
2914 heap_profiler->StartSamplingHeapProfiler(1024); 2914 heap_profiler->StartSamplingHeapProfiler(1024);
2915 CompileRun(script_source); 2915 CompileRun(script_source);
2916 2916
2917 v8::base::SmartPointer<v8::AllocationProfile> profile( 2917 std::unique_ptr<v8::AllocationProfile> profile(
2918 heap_profiler->GetAllocationProfile()); 2918 heap_profiler->GetAllocationProfile());
2919 CHECK(!profile.is_empty()); 2919 CHECK(profile);
2920 2920
2921 const char* names[] = {"", "foo", "bar"}; 2921 const char* names[] = {"", "foo", "bar"};
2922 auto node_bar = FindAllocationProfileNode(*profile, ArrayVector(names)); 2922 auto node_bar = FindAllocationProfileNode(*profile, ArrayVector(names));
2923 CHECK(node_bar); 2923 CHECK(node_bar);
2924 2924
2925 // Count the number of allocations we sampled from bar. 2925 // Count the number of allocations we sampled from bar.
2926 for (auto allocation : node_bar->allocations) { 2926 for (auto allocation : node_bar->allocations) {
2927 count_1024 += allocation.count; 2927 count_1024 += allocation.count;
2928 } 2928 }
2929 2929
2930 heap_profiler->StopSamplingHeapProfiler(); 2930 heap_profiler->StopSamplingHeapProfiler();
2931 } 2931 }
2932 2932
2933 // Samples should get cleared once sampling is stopped. 2933 // Samples should get cleared once sampling is stopped.
2934 { 2934 {
2935 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile(); 2935 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile();
2936 CHECK(profile == nullptr); 2936 CHECK(profile == nullptr);
2937 } 2937 }
2938 2938
2939 // Sampling at a higher rate should give us similar numbers of objects. 2939 // Sampling at a higher rate should give us similar numbers of objects.
2940 { 2940 {
2941 heap_profiler->StartSamplingHeapProfiler(128); 2941 heap_profiler->StartSamplingHeapProfiler(128);
2942 CompileRun(script_source); 2942 CompileRun(script_source);
2943 2943
2944 v8::base::SmartPointer<v8::AllocationProfile> profile( 2944 std::unique_ptr<v8::AllocationProfile> profile(
2945 heap_profiler->GetAllocationProfile()); 2945 heap_profiler->GetAllocationProfile());
2946 CHECK(!profile.is_empty()); 2946 CHECK(profile);
2947 2947
2948 const char* names[] = {"", "foo", "bar"}; 2948 const char* names[] = {"", "foo", "bar"};
2949 auto node_bar = FindAllocationProfileNode(*profile, ArrayVector(names)); 2949 auto node_bar = FindAllocationProfileNode(*profile, ArrayVector(names));
2950 CHECK(node_bar); 2950 CHECK(node_bar);
2951 2951
2952 // Count the number of allocations we sampled from bar. 2952 // Count the number of allocations we sampled from bar.
2953 int count_128 = 0; 2953 int count_128 = 0;
2954 for (auto allocation : node_bar->allocations) { 2954 for (auto allocation : node_bar->allocations) {
2955 count_128 += allocation.count; 2955 count_128 += allocation.count;
2956 } 2956 }
(...skipping 11 matching lines...) Expand all
2968 2968
2969 heap_profiler->StopSamplingHeapProfiler(); 2969 heap_profiler->StopSamplingHeapProfiler();
2970 } 2970 }
2971 2971
2972 // A more complicated test cases with deeper call graph and dynamically 2972 // A more complicated test cases with deeper call graph and dynamically
2973 // generated function names. 2973 // generated function names.
2974 { 2974 {
2975 heap_profiler->StartSamplingHeapProfiler(64); 2975 heap_profiler->StartSamplingHeapProfiler(64);
2976 CompileRun(record_trace_tree_source); 2976 CompileRun(record_trace_tree_source);
2977 2977
2978 v8::base::SmartPointer<v8::AllocationProfile> profile( 2978 std::unique_ptr<v8::AllocationProfile> profile(
2979 heap_profiler->GetAllocationProfile()); 2979 heap_profiler->GetAllocationProfile());
2980 CHECK(!profile.is_empty()); 2980 CHECK(profile);
2981 2981
2982 const char* names1[] = {"", "start", "f_0_0", "f_0_1", "f_0_2"}; 2982 const char* names1[] = {"", "start", "f_0_0", "f_0_1", "f_0_2"};
2983 auto node1 = FindAllocationProfileNode(*profile, ArrayVector(names1)); 2983 auto node1 = FindAllocationProfileNode(*profile, ArrayVector(names1));
2984 CHECK(node1); 2984 CHECK(node1);
2985 2985
2986 const char* names2[] = {"", "generateFunctions"}; 2986 const char* names2[] = {"", "generateFunctions"};
2987 auto node2 = FindAllocationProfileNode(*profile, ArrayVector(names2)); 2987 auto node2 = FindAllocationProfileNode(*profile, ArrayVector(names2));
2988 CHECK(node2); 2988 CHECK(node2);
2989 2989
2990 heap_profiler->StopSamplingHeapProfiler(); 2990 heap_profiler->StopSamplingHeapProfiler();
2991 } 2991 }
2992 2992
2993 // A test case with scripts unloaded before profile gathered 2993 // A test case with scripts unloaded before profile gathered
2994 { 2994 {
2995 heap_profiler->StartSamplingHeapProfiler(64); 2995 heap_profiler->StartSamplingHeapProfiler(64);
2996 CompileRun( 2996 CompileRun(
2997 "for (var i = 0; i < 1024; i++) {\n" 2997 "for (var i = 0; i < 1024; i++) {\n"
2998 " eval(\"new Array(100)\");\n" 2998 " eval(\"new Array(100)\");\n"
2999 "}\n"); 2999 "}\n");
3000 3000
3001 CcTest::heap()->CollectAllGarbage(); 3001 CcTest::heap()->CollectAllGarbage();
3002 3002
3003 v8::base::SmartPointer<v8::AllocationProfile> profile( 3003 std::unique_ptr<v8::AllocationProfile> profile(
3004 heap_profiler->GetAllocationProfile()); 3004 heap_profiler->GetAllocationProfile());
3005 CHECK(!profile.is_empty()); 3005 CHECK(profile);
3006 3006
3007 CheckNoZeroCountNodes(profile->GetRootNode()); 3007 CheckNoZeroCountNodes(profile->GetRootNode());
3008 3008
3009 heap_profiler->StopSamplingHeapProfiler(); 3009 heap_profiler->StopSamplingHeapProfiler();
3010 } 3010 }
3011 } 3011 }
3012 3012
3013 3013
3014 TEST(SamplingHeapProfilerApiAllocation) { 3014 TEST(SamplingHeapProfilerApiAllocation) {
3015 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3015 v8::HandleScope scope(v8::Isolate::GetCurrent());
3016 LocalContext env; 3016 LocalContext env;
3017 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 3017 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
3018 3018
3019 // Suppress randomness to avoid flakiness in tests. 3019 // Suppress randomness to avoid flakiness in tests.
3020 v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true; 3020 v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true;
3021 3021
3022 heap_profiler->StartSamplingHeapProfiler(256); 3022 heap_profiler->StartSamplingHeapProfiler(256);
3023 3023
3024 for (int i = 0; i < 8 * 1024; ++i) v8::Object::New(env->GetIsolate()); 3024 for (int i = 0; i < 8 * 1024; ++i) v8::Object::New(env->GetIsolate());
3025 3025
3026 v8::base::SmartPointer<v8::AllocationProfile> profile( 3026 std::unique_ptr<v8::AllocationProfile> profile(
3027 heap_profiler->GetAllocationProfile()); 3027 heap_profiler->GetAllocationProfile());
3028 CHECK(!profile.is_empty()); 3028 CHECK(profile);
3029 const char* names[] = {"(V8 API)"}; 3029 const char* names[] = {"(V8 API)"};
3030 auto node = FindAllocationProfileNode(*profile, ArrayVector(names)); 3030 auto node = FindAllocationProfileNode(*profile, ArrayVector(names));
3031 CHECK(node); 3031 CHECK(node);
3032 3032
3033 heap_profiler->StopSamplingHeapProfiler(); 3033 heap_profiler->StopSamplingHeapProfiler();
3034 } 3034 }
3035 3035
3036 TEST(SamplingHeapProfilerLeftTrimming) { 3036 TEST(SamplingHeapProfilerLeftTrimming) {
3037 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3037 v8::HandleScope scope(v8::Isolate::GetCurrent());
3038 LocalContext env; 3038 LocalContext env;
(...skipping 11 matching lines...) Expand all
3050 " a[i] = i;\n" 3050 " a[i] = i;\n"
3051 " for (var i = 0; i < 3; ++i)\n" 3051 " for (var i = 0; i < 3; ++i)\n"
3052 " a.shift();\n" 3052 " a.shift();\n"
3053 "}\n"); 3053 "}\n");
3054 3054
3055 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); 3055 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
3056 // Should not crash. 3056 // Should not crash.
3057 3057
3058 heap_profiler->StopSamplingHeapProfiler(); 3058 heap_profiler->StopSamplingHeapProfiler();
3059 } 3059 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698