OLD | NEW |
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 2883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2894 " }\n" | 2894 " }\n" |
2895 "}\n" | 2895 "}\n" |
2896 "foo();"; | 2896 "foo();"; |
2897 | 2897 |
2898 // Sample should be empty if requested before sampling has started. | 2898 // Sample should be empty if requested before sampling has started. |
2899 { | 2899 { |
2900 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile(); | 2900 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile(); |
2901 CHECK(profile == nullptr); | 2901 CHECK(profile == nullptr); |
2902 } | 2902 } |
2903 | 2903 |
2904 int count_512kb = 0; | 2904 int count_1024 = 0; |
2905 { | 2905 { |
2906 heap_profiler->StartSamplingHeapProfiler(512 * 1024); | 2906 heap_profiler->StartSamplingHeapProfiler(1024); |
2907 CompileRun(script_source); | 2907 CompileRun(script_source); |
2908 | 2908 |
2909 v8::base::SmartPointer<v8::AllocationProfile> profile( | 2909 v8::base::SmartPointer<v8::AllocationProfile> profile( |
2910 heap_profiler->GetAllocationProfile()); | 2910 heap_profiler->GetAllocationProfile()); |
2911 CHECK(!profile.is_empty()); | 2911 CHECK(!profile.is_empty()); |
2912 | 2912 |
2913 const char* names[] = {"", "foo", "bar"}; | 2913 const char* names[] = {"", "foo", "bar"}; |
2914 auto node_bar = FindAllocationProfileNode( | 2914 auto node_bar = FindAllocationProfileNode( |
2915 *profile, Vector<const char*>(names, arraysize(names))); | 2915 *profile, Vector<const char*>(names, arraysize(names))); |
2916 CHECK(node_bar); | 2916 CHECK(node_bar); |
2917 | 2917 |
2918 // Count the number of allocations we sampled from bar. | 2918 // Count the number of allocations we sampled from bar. |
2919 for (auto allocation : node_bar->allocations) { | 2919 for (auto allocation : node_bar->allocations) { |
2920 count_512kb += allocation.count; | 2920 count_1024 += allocation.count; |
2921 } | 2921 } |
2922 | 2922 |
2923 heap_profiler->StopSamplingHeapProfiler(); | 2923 heap_profiler->StopSamplingHeapProfiler(); |
2924 } | 2924 } |
2925 | 2925 |
2926 // Samples should get cleared once sampling is stopped. | 2926 // Samples should get cleared once sampling is stopped. |
2927 { | 2927 { |
2928 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile(); | 2928 v8::AllocationProfile* profile = heap_profiler->GetAllocationProfile(); |
2929 CHECK(profile == nullptr); | 2929 CHECK(profile == nullptr); |
2930 } | 2930 } |
2931 | 2931 |
2932 // Sampling at a higher rate should give us more sampled objects. | 2932 // Sampling at a higher rate should give us similar numbers of objects. |
2933 { | 2933 { |
2934 heap_profiler->StartSamplingHeapProfiler(32 * 1024); | 2934 heap_profiler->StartSamplingHeapProfiler(128); |
2935 CompileRun(script_source); | 2935 CompileRun(script_source); |
2936 | 2936 |
2937 v8::base::SmartPointer<v8::AllocationProfile> profile( | 2937 v8::base::SmartPointer<v8::AllocationProfile> profile( |
2938 heap_profiler->GetAllocationProfile()); | 2938 heap_profiler->GetAllocationProfile()); |
2939 CHECK(!profile.is_empty()); | 2939 CHECK(!profile.is_empty()); |
2940 | 2940 |
2941 const char* names[] = {"", "foo", "bar"}; | 2941 const char* names[] = {"", "foo", "bar"}; |
2942 auto node_bar = FindAllocationProfileNode( | 2942 auto node_bar = FindAllocationProfileNode( |
2943 *profile, Vector<const char*>(names, arraysize(names))); | 2943 *profile, Vector<const char*>(names, arraysize(names))); |
2944 CHECK(node_bar); | 2944 CHECK(node_bar); |
2945 | 2945 |
2946 // Count the number of allocations we sampled from bar. | 2946 // Count the number of allocations we sampled from bar. |
2947 int count_32kb = 0; | 2947 int count_128 = 0; |
2948 for (auto allocation : node_bar->allocations) { | 2948 for (auto allocation : node_bar->allocations) { |
2949 count_32kb += allocation.count; | 2949 count_128 += allocation.count; |
2950 } | 2950 } |
2951 | 2951 |
2952 // We should have roughly 16x as many sampled allocations. However, | 2952 // We should have similar unsampled counts of allocations. Though |
2953 // alignment and boundaries might tweak the numbers slightly. We use a | 2953 // we will sample different numbers of objects at different rates, |
2954 // slightly weaker test to account for this. | 2954 // the unsampling process should produce similar final estimates |
2955 CHECK_GT(count_32kb, 8 * count_512kb); | 2955 // at the true number of allocations. However, the process to |
| 2956 // determine these unsampled counts is probabilisitic so we need to |
| 2957 // account for error. |
| 2958 double max_count = std::max(count_128, count_1024); |
| 2959 double min_count = std::min(count_128, count_1024); |
| 2960 double percent_difference = (max_count - min_count) / min_count; |
| 2961 CHECK_LT(percent_difference, 0.15); |
2956 | 2962 |
2957 heap_profiler->StopSamplingHeapProfiler(); | 2963 heap_profiler->StopSamplingHeapProfiler(); |
2958 } | 2964 } |
2959 | 2965 |
2960 // A more complicated test cases with deeper call graph and dynamically | 2966 // A more complicated test cases with deeper call graph and dynamically |
2961 // generated function names. | 2967 // generated function names. |
2962 { | 2968 { |
2963 heap_profiler->StartSamplingHeapProfiler(64); | 2969 heap_profiler->StartSamplingHeapProfiler(64); |
2964 CompileRun(record_trace_tree_source); | 2970 CompileRun(record_trace_tree_source); |
2965 | 2971 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2997 v8::base::SmartPointer<v8::AllocationProfile> profile( | 3003 v8::base::SmartPointer<v8::AllocationProfile> profile( |
2998 heap_profiler->GetAllocationProfile()); | 3004 heap_profiler->GetAllocationProfile()); |
2999 CHECK(!profile.is_empty()); | 3005 CHECK(!profile.is_empty()); |
3000 const char* names[] = {"(V8 API)"}; | 3006 const char* names[] = {"(V8 API)"}; |
3001 auto node = FindAllocationProfileNode( | 3007 auto node = FindAllocationProfileNode( |
3002 *profile, Vector<const char*>(names, arraysize(names))); | 3008 *profile, Vector<const char*>(names, arraysize(names))); |
3003 CHECK(node); | 3009 CHECK(node); |
3004 | 3010 |
3005 heap_profiler->StopSamplingHeapProfiler(); | 3011 heap_profiler->StopSamplingHeapProfiler(); |
3006 } | 3012 } |
OLD | NEW |