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

Side by Side Diff: runtime/vm/profiler_service.cc

Issue 2680213002: Updated MallocHooks to collect stack traces when memory is allocated. (Closed)
Patch Set: Updated tests, addressed prior comments. Created 3 years, 10 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 (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/profiler_service.h" 5 #include "vm/profiler_service.h"
6 6
7 #include "vm/growable_array.h" 7 #include "vm/growable_array.h"
8 #include "vm/hash_map.h" 8 #include "vm/hash_map.h"
9 #include "vm/log.h" 9 #include "vm/log.h"
10 #include "vm/native_symbol.h" 10 #include "vm/native_symbol.h"
(...skipping 2652 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 profile.PrintTimelineJSON(stream); 2663 profile.PrintTimelineJSON(stream);
2664 } else { 2664 } else {
2665 profile.PrintProfileJSON(stream); 2665 profile.PrintProfileJSON(stream);
2666 } 2666 }
2667 } 2667 }
2668 } 2668 }
2669 2669
2670 2670
2671 class NoAllocationSampleFilter : public SampleFilter { 2671 class NoAllocationSampleFilter : public SampleFilter {
2672 public: 2672 public:
2673 NoAllocationSampleFilter(Isolate* isolate, 2673 NoAllocationSampleFilter(Dart_Port port,
2674 intptr_t thread_task_mask, 2674 intptr_t thread_task_mask,
2675 int64_t time_origin_micros, 2675 int64_t time_origin_micros,
2676 int64_t time_extent_micros) 2676 int64_t time_extent_micros)
2677 : SampleFilter(isolate, 2677 : SampleFilter(port,
2678 thread_task_mask, 2678 thread_task_mask,
2679 time_origin_micros, 2679 time_origin_micros,
2680 time_extent_micros) {} 2680 time_extent_micros) {}
2681 2681
2682 bool FilterSample(Sample* sample) { return !sample->is_allocation_sample(); } 2682 bool FilterSample(Sample* sample) {
2683 return !sample->is_allocation_sample() &&
2684 !sample->is_native_allocation_sample();
2685 }
2683 }; 2686 };
2684 2687
2685 2688
2686 void ProfilerService::PrintJSON(JSONStream* stream, 2689 void ProfilerService::PrintJSON(JSONStream* stream,
2687 Profile::TagOrder tag_order, 2690 Profile::TagOrder tag_order,
2688 intptr_t extra_tags, 2691 intptr_t extra_tags,
2689 int64_t time_origin_micros, 2692 int64_t time_origin_micros,
2690 int64_t time_extent_micros) { 2693 int64_t time_extent_micros) {
2691 Thread* thread = Thread::Current(); 2694 Thread* thread = Thread::Current();
2692 Isolate* isolate = thread->isolate(); 2695 Isolate* isolate = thread->isolate();
2693 NoAllocationSampleFilter filter(isolate, Thread::kMutatorTask, 2696 NoAllocationSampleFilter filter(isolate->main_port(), Thread::kMutatorTask,
2694 time_origin_micros, time_extent_micros); 2697 time_origin_micros, time_extent_micros);
2695 const bool as_timeline = false; 2698 const bool as_timeline = false;
2696 PrintJSONImpl(thread, stream, tag_order, extra_tags, &filter, as_timeline); 2699 PrintJSONImpl(thread, stream, tag_order, extra_tags, &filter, as_timeline);
2697 } 2700 }
2698 2701
2699 2702
2700 class ClassAllocationSampleFilter : public SampleFilter { 2703 class ClassAllocationSampleFilter : public SampleFilter {
2701 public: 2704 public:
2702 ClassAllocationSampleFilter(Isolate* isolate, 2705 ClassAllocationSampleFilter(Dart_Port port,
2703 const Class& cls, 2706 const Class& cls,
2704 intptr_t thread_task_mask, 2707 intptr_t thread_task_mask,
2705 int64_t time_origin_micros, 2708 int64_t time_origin_micros,
2706 int64_t time_extent_micros) 2709 int64_t time_extent_micros)
2707 : SampleFilter(isolate, 2710 : SampleFilter(port,
2708 thread_task_mask, 2711 thread_task_mask,
2709 time_origin_micros, 2712 time_origin_micros,
2710 time_extent_micros), 2713 time_extent_micros),
2711 cls_(Class::Handle(cls.raw())) { 2714 cls_(Class::Handle(cls.raw())) {
2712 ASSERT(!cls_.IsNull()); 2715 ASSERT(!cls_.IsNull());
2713 } 2716 }
2714 2717
2715 bool FilterSample(Sample* sample) { 2718 bool FilterSample(Sample* sample) {
2716 return sample->is_allocation_sample() && 2719 return sample->is_allocation_sample() &&
2717 (sample->allocation_cid() == cls_.id()); 2720 (sample->allocation_cid() == cls_.id()) &&
2721 !sample->is_native_allocation_sample();
2718 } 2722 }
2719 2723
2720 private: 2724 private:
2721 const Class& cls_; 2725 const Class& cls_;
2722 }; 2726 };
2723 2727
2724 2728
2729 class NativeAllocationSampleFilter : public SampleFilter {
2730 public:
2731 NativeAllocationSampleFilter(Dart_Port port,
2732 intptr_t thread_task_mask,
2733 int64_t time_origin_micros,
2734 int64_t time_extent_micros)
2735 : SampleFilter(port,
2736 thread_task_mask,
2737 time_origin_micros,
2738 time_extent_micros) {}
2739 bool FilterSample(Sample* sample) {
2740 return sample->is_native_allocation_sample();
2741 }
2742 };
2743
2744
2725 void ProfilerService::PrintAllocationJSON(JSONStream* stream, 2745 void ProfilerService::PrintAllocationJSON(JSONStream* stream,
2726 Profile::TagOrder tag_order, 2746 Profile::TagOrder tag_order,
2727 const Class& cls, 2747 const Class& cls,
2728 int64_t time_origin_micros, 2748 int64_t time_origin_micros,
2729 int64_t time_extent_micros) { 2749 int64_t time_extent_micros) {
2730 Thread* thread = Thread::Current(); 2750 Thread* thread = Thread::Current();
2731 Isolate* isolate = thread->isolate(); 2751 Isolate* isolate = thread->isolate();
2732 ClassAllocationSampleFilter filter(isolate, cls, Thread::kMutatorTask, 2752 ClassAllocationSampleFilter filter(isolate->main_port(), cls,
2733 time_origin_micros, time_extent_micros); 2753 Thread::kMutatorTask, time_origin_micros,
2754 time_extent_micros);
2734 const bool as_timeline = false; 2755 const bool as_timeline = false;
2735 PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline); 2756 PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline);
2736 } 2757 }
2758
2759
2760 void ProfilerService::PrintNativeAllocationJSON(JSONStream* stream,
2761 Profile::TagOrder tag_order,
2762 int64_t time_origin_micros,
2763 int64_t time_extent_micros) {
2764 Thread* thread = Thread::Current();
2765 Isolate* isolate = thread->isolate();
2766 const intptr_t thread_task_mask = Thread::kMutatorTask |
2767 Thread::kCompilerTask |
2768 Thread::kSweeperTask | Thread::kMarkerTask;
2769 NativeAllocationSampleFilter filter(isolate->main_port(), thread_task_mask,
2770 time_origin_micros, time_extent_micros);
2771 const bool as_timeline = false;
2772 PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline);
2773 }
2737 2774
2738 2775
2739 void ProfilerService::PrintTimelineJSON(JSONStream* stream, 2776 void ProfilerService::PrintTimelineJSON(JSONStream* stream,
2740 Profile::TagOrder tag_order, 2777 Profile::TagOrder tag_order,
2741 int64_t time_origin_micros, 2778 int64_t time_origin_micros,
2742 int64_t time_extent_micros) { 2779 int64_t time_extent_micros) {
2743 Thread* thread = Thread::Current(); 2780 Thread* thread = Thread::Current();
2744 Isolate* isolate = thread->isolate(); 2781 Isolate* isolate = thread->isolate();
2745 const intptr_t thread_task_mask = Thread::kMutatorTask | 2782 const intptr_t thread_task_mask = Thread::kMutatorTask |
2746 Thread::kCompilerTask | 2783 Thread::kCompilerTask |
2747 Thread::kSweeperTask | Thread::kMarkerTask; 2784 Thread::kSweeperTask | Thread::kMarkerTask;
2748 NoAllocationSampleFilter filter(isolate, thread_task_mask, time_origin_micros, 2785 NoAllocationSampleFilter filter(isolate->main_port(), thread_task_mask,
2749 time_extent_micros); 2786 time_origin_micros, time_extent_micros);
2750 const bool as_timeline = true; 2787 const bool as_timeline = true;
2751 PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline); 2788 PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline);
2752 } 2789 }
2753 2790
2754 2791
2755 void ProfilerService::ClearSamples() { 2792 void ProfilerService::ClearSamples() {
2756 SampleBuffer* sample_buffer = Profiler::sample_buffer(); 2793 SampleBuffer* sample_buffer = Profiler::sample_buffer();
2757 if (sample_buffer == NULL) { 2794 if (sample_buffer == NULL) {
2758 return; 2795 return;
2759 } 2796 }
2760 2797
2761 Thread* thread = Thread::Current(); 2798 Thread* thread = Thread::Current();
2762 Isolate* isolate = thread->isolate(); 2799 Isolate* isolate = thread->isolate();
2763 2800
2764 // Disable thread interrupts while processing the buffer. 2801 // Disable thread interrupts while processing the buffer.
2765 DisableThreadInterruptsScope dtis(thread); 2802 DisableThreadInterruptsScope dtis(thread);
2766 2803
2767 ClearProfileVisitor clear_profile(isolate); 2804 ClearProfileVisitor clear_profile(isolate);
2768 sample_buffer->VisitSamples(&clear_profile); 2805 sample_buffer->VisitSamples(&clear_profile);
2769 } 2806 }
2770 2807
2771 #endif // !PRODUCT 2808 #endif // !PRODUCT
2772 2809
2773 } // namespace dart 2810 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698