| OLD | NEW | 
|---|
| 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  Loading... | 
| 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(Dart_Port port, | 2673   NoAllocationSampleFilter(Isolate* isolate, | 
| 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(port, | 2677       : SampleFilter(isolate, | 
| 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) { | 2682   bool FilterSample(Sample* sample) { return !sample->is_allocation_sample(); } | 
| 2683     return !sample->is_allocation_sample() && |  | 
| 2684            !sample->is_native_allocation_sample(); |  | 
| 2685   } |  | 
| 2686 }; | 2683 }; | 
| 2687 | 2684 | 
| 2688 | 2685 | 
| 2689 void ProfilerService::PrintJSON(JSONStream* stream, | 2686 void ProfilerService::PrintJSON(JSONStream* stream, | 
| 2690                                 Profile::TagOrder tag_order, | 2687                                 Profile::TagOrder tag_order, | 
| 2691                                 intptr_t extra_tags, | 2688                                 intptr_t extra_tags, | 
| 2692                                 int64_t time_origin_micros, | 2689                                 int64_t time_origin_micros, | 
| 2693                                 int64_t time_extent_micros) { | 2690                                 int64_t time_extent_micros) { | 
| 2694   Thread* thread = Thread::Current(); | 2691   Thread* thread = Thread::Current(); | 
| 2695   Isolate* isolate = thread->isolate(); | 2692   Isolate* isolate = thread->isolate(); | 
| 2696   NoAllocationSampleFilter filter(isolate->main_port(), Thread::kMutatorTask, | 2693   NoAllocationSampleFilter filter(isolate, Thread::kMutatorTask, | 
| 2697                                   time_origin_micros, time_extent_micros); | 2694                                   time_origin_micros, time_extent_micros); | 
| 2698   const bool as_timeline = false; | 2695   const bool as_timeline = false; | 
| 2699   PrintJSONImpl(thread, stream, tag_order, extra_tags, &filter, as_timeline); | 2696   PrintJSONImpl(thread, stream, tag_order, extra_tags, &filter, as_timeline); | 
| 2700 } | 2697 } | 
| 2701 | 2698 | 
| 2702 | 2699 | 
| 2703 class ClassAllocationSampleFilter : public SampleFilter { | 2700 class ClassAllocationSampleFilter : public SampleFilter { | 
| 2704  public: | 2701  public: | 
| 2705   ClassAllocationSampleFilter(Dart_Port port, | 2702   ClassAllocationSampleFilter(Isolate* isolate, | 
| 2706                               const Class& cls, | 2703                               const Class& cls, | 
| 2707                               intptr_t thread_task_mask, | 2704                               intptr_t thread_task_mask, | 
| 2708                               int64_t time_origin_micros, | 2705                               int64_t time_origin_micros, | 
| 2709                               int64_t time_extent_micros) | 2706                               int64_t time_extent_micros) | 
| 2710       : SampleFilter(port, | 2707       : SampleFilter(isolate, | 
| 2711                      thread_task_mask, | 2708                      thread_task_mask, | 
| 2712                      time_origin_micros, | 2709                      time_origin_micros, | 
| 2713                      time_extent_micros), | 2710                      time_extent_micros), | 
| 2714         cls_(Class::Handle(cls.raw())) { | 2711         cls_(Class::Handle(cls.raw())) { | 
| 2715     ASSERT(!cls_.IsNull()); | 2712     ASSERT(!cls_.IsNull()); | 
| 2716   } | 2713   } | 
| 2717 | 2714 | 
| 2718   bool FilterSample(Sample* sample) { | 2715   bool FilterSample(Sample* sample) { | 
| 2719     return sample->is_allocation_sample() && | 2716     return sample->is_allocation_sample() && | 
| 2720            (sample->allocation_cid() == cls_.id()); | 2717            (sample->allocation_cid() == cls_.id()); | 
| 2721   } | 2718   } | 
| 2722 | 2719 | 
| 2723  private: | 2720  private: | 
| 2724   const Class& cls_; | 2721   const Class& cls_; | 
| 2725 }; | 2722 }; | 
| 2726 | 2723 | 
| 2727 | 2724 | 
| 2728 class NativeAllocationSampleFilter : public SampleFilter { |  | 
| 2729  public: |  | 
| 2730   NativeAllocationSampleFilter(intptr_t thread_task_mask, |  | 
| 2731                                int64_t time_origin_micros, |  | 
| 2732                                int64_t time_extent_micros) |  | 
| 2733       : SampleFilter(ILLEGAL_PORT, |  | 
| 2734                      thread_task_mask, |  | 
| 2735                      time_origin_micros, |  | 
| 2736                      time_extent_micros) {} |  | 
| 2737   bool FilterSample(Sample* sample) { |  | 
| 2738     return sample->is_native_allocation_sample(); |  | 
| 2739   } |  | 
| 2740 }; |  | 
| 2741 |  | 
| 2742 |  | 
| 2743 void ProfilerService::PrintAllocationJSON(JSONStream* stream, | 2725 void ProfilerService::PrintAllocationJSON(JSONStream* stream, | 
| 2744                                           Profile::TagOrder tag_order, | 2726                                           Profile::TagOrder tag_order, | 
| 2745                                           const Class& cls, | 2727                                           const Class& cls, | 
| 2746                                           int64_t time_origin_micros, | 2728                                           int64_t time_origin_micros, | 
| 2747                                           int64_t time_extent_micros) { | 2729                                           int64_t time_extent_micros) { | 
| 2748   Thread* thread = Thread::Current(); | 2730   Thread* thread = Thread::Current(); | 
| 2749   Isolate* isolate = thread->isolate(); | 2731   Isolate* isolate = thread->isolate(); | 
| 2750   ClassAllocationSampleFilter filter(isolate->main_port(), cls, | 2732   ClassAllocationSampleFilter filter(isolate, cls, Thread::kMutatorTask, | 
| 2751                                      Thread::kMutatorTask, time_origin_micros, | 2733                                      time_origin_micros, time_extent_micros); | 
| 2752                                      time_extent_micros); |  | 
| 2753   const bool as_timeline = false; | 2734   const bool as_timeline = false; | 
| 2754   PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline); | 2735   PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline); | 
| 2755 } | 2736 } | 
| 2756 |  | 
| 2757 |  | 
| 2758 void ProfilerService::PrintNativeAllocationJSON(JSONStream* stream, |  | 
| 2759                                                 Profile::TagOrder tag_order, |  | 
| 2760                                                 int64_t time_origin_micros, |  | 
| 2761                                                 int64_t time_extent_micros) { |  | 
| 2762   Thread* thread = Thread::Current(); |  | 
| 2763   const intptr_t thread_task_mask = Thread::kMutatorTask | |  | 
| 2764                                     Thread::kCompilerTask | |  | 
| 2765                                     Thread::kSweeperTask | Thread::kMarkerTask; |  | 
| 2766   NativeAllocationSampleFilter filter(thread_task_mask, time_origin_micros, |  | 
| 2767                                       time_extent_micros); |  | 
| 2768   const bool as_timeline = false; |  | 
| 2769   PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline); |  | 
| 2770 } |  | 
| 2771 | 2737 | 
| 2772 | 2738 | 
| 2773 void ProfilerService::PrintTimelineJSON(JSONStream* stream, | 2739 void ProfilerService::PrintTimelineJSON(JSONStream* stream, | 
| 2774                                         Profile::TagOrder tag_order, | 2740                                         Profile::TagOrder tag_order, | 
| 2775                                         int64_t time_origin_micros, | 2741                                         int64_t time_origin_micros, | 
| 2776                                         int64_t time_extent_micros) { | 2742                                         int64_t time_extent_micros) { | 
| 2777   Thread* thread = Thread::Current(); | 2743   Thread* thread = Thread::Current(); | 
| 2778   Isolate* isolate = thread->isolate(); | 2744   Isolate* isolate = thread->isolate(); | 
| 2779   const intptr_t thread_task_mask = Thread::kMutatorTask | | 2745   const intptr_t thread_task_mask = Thread::kMutatorTask | | 
| 2780                                     Thread::kCompilerTask | | 2746                                     Thread::kCompilerTask | | 
| 2781                                     Thread::kSweeperTask | Thread::kMarkerTask; | 2747                                     Thread::kSweeperTask | Thread::kMarkerTask; | 
| 2782   NoAllocationSampleFilter filter(isolate->main_port(), thread_task_mask, | 2748   NoAllocationSampleFilter filter(isolate, thread_task_mask, time_origin_micros, | 
| 2783                                   time_origin_micros, time_extent_micros); | 2749                                   time_extent_micros); | 
| 2784   const bool as_timeline = true; | 2750   const bool as_timeline = true; | 
| 2785   PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline); | 2751   PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter, as_timeline); | 
| 2786 } | 2752 } | 
| 2787 | 2753 | 
| 2788 | 2754 | 
| 2789 void ProfilerService::ClearSamples() { | 2755 void ProfilerService::ClearSamples() { | 
| 2790   SampleBuffer* sample_buffer = Profiler::sample_buffer(); | 2756   SampleBuffer* sample_buffer = Profiler::sample_buffer(); | 
| 2791   if (sample_buffer == NULL) { | 2757   if (sample_buffer == NULL) { | 
| 2792     return; | 2758     return; | 
| 2793   } | 2759   } | 
| 2794 | 2760 | 
| 2795   Thread* thread = Thread::Current(); | 2761   Thread* thread = Thread::Current(); | 
| 2796   Isolate* isolate = thread->isolate(); | 2762   Isolate* isolate = thread->isolate(); | 
| 2797 | 2763 | 
| 2798   // Disable thread interrupts while processing the buffer. | 2764   // Disable thread interrupts while processing the buffer. | 
| 2799   DisableThreadInterruptsScope dtis(thread); | 2765   DisableThreadInterruptsScope dtis(thread); | 
| 2800 | 2766 | 
| 2801   ClearProfileVisitor clear_profile(isolate); | 2767   ClearProfileVisitor clear_profile(isolate); | 
| 2802   sample_buffer->VisitSamples(&clear_profile); | 2768   sample_buffer->VisitSamples(&clear_profile); | 
| 2803 } | 2769 } | 
| 2804 | 2770 | 
| 2805 #endif  // !PRODUCT | 2771 #endif  // !PRODUCT | 
| 2806 | 2772 | 
| 2807 }  // namespace dart | 2773 }  // namespace dart | 
| OLD | NEW | 
|---|