| 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/native_symbol.h" | 8 #include "vm/native_symbol.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/os.h" | 10 #include "vm/os.h" |
| (...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1957 } | 1957 } |
| 1958 current_index++; | 1958 current_index++; |
| 1959 if (current_index >= parent_->NumChildren()) { | 1959 if (current_index >= parent_->NumChildren()) { |
| 1960 return false; | 1960 return false; |
| 1961 } | 1961 } |
| 1962 current_ = parent_->At(current_index); | 1962 current_ = parent_->At(current_index); |
| 1963 return true; | 1963 return true; |
| 1964 } | 1964 } |
| 1965 | 1965 |
| 1966 | 1966 |
| 1967 class NoAllocationSampleFilter : public SampleFilter { | 1967 void ProfilerService::PrintJSONImpl(Isolate* isolate, |
| 1968 public: | 1968 JSONStream* stream, |
| 1969 explicit NoAllocationSampleFilter(Isolate* isolate) | 1969 Profile::TagOrder tag_order, |
| 1970 : SampleFilter(isolate) { | 1970 SampleFilter* filter) { |
| 1971 } | |
| 1972 | |
| 1973 bool FilterSample(Sample* sample) { | |
| 1974 return !sample->is_allocation_sample(); | |
| 1975 } | |
| 1976 }; | |
| 1977 | |
| 1978 | |
| 1979 void ProfilerService::PrintJSON(JSONStream* stream, | |
| 1980 Profile::TagOrder tag_order) { | |
| 1981 Isolate* isolate = Isolate::Current(); | |
| 1982 // Disable profile interrupts while processing the buffer. | 1971 // Disable profile interrupts while processing the buffer. |
| 1983 Profiler::EndExecution(isolate); | 1972 Profiler::EndExecution(isolate); |
| 1984 | 1973 |
| 1985 { | 1974 { |
| 1986 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); | 1975 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); |
| 1987 IsolateProfilerData* profiler_data = isolate->profiler_data(); | 1976 IsolateProfilerData* profiler_data = isolate->profiler_data(); |
| 1988 if (profiler_data == NULL) { | 1977 if (profiler_data == NULL) { |
| 1989 stream->PrintError(kFeatureDisabled, NULL); | 1978 stream->PrintError(kFeatureDisabled, NULL); |
| 1990 return; | 1979 return; |
| 1991 } | 1980 } |
| 1992 } | 1981 } |
| 1993 | 1982 |
| 1994 { | 1983 { |
| 1995 StackZone zone(isolate); | 1984 StackZone zone(isolate); |
| 1996 HANDLESCOPE(isolate); | 1985 HANDLESCOPE(isolate); |
| 1997 Profile profile(isolate); | 1986 Profile profile(isolate); |
| 1998 NoAllocationSampleFilter filter(isolate); | 1987 profile.Build(filter, tag_order); |
| 1999 profile.Build(&filter, tag_order); | |
| 2000 profile.PrintJSON(stream); | 1988 profile.PrintJSON(stream); |
| 2001 } | 1989 } |
| 2002 | 1990 |
| 2003 // Enable profile interrupts. | 1991 // Enable profile interrupts. |
| 2004 Profiler::BeginExecution(isolate); | 1992 Profiler::BeginExecution(isolate); |
| 2005 } | 1993 } |
| 2006 | 1994 |
| 2007 | 1995 |
| 1996 class NoAllocationSampleFilter : public SampleFilter { |
| 1997 public: |
| 1998 explicit NoAllocationSampleFilter(Isolate* isolate) |
| 1999 : SampleFilter(isolate) { |
| 2000 } |
| 2001 |
| 2002 bool FilterSample(Sample* sample) { |
| 2003 return !sample->is_allocation_sample(); |
| 2004 } |
| 2005 }; |
| 2006 |
| 2007 |
| 2008 void ProfilerService::PrintJSON(JSONStream* stream, |
| 2009 Profile::TagOrder tag_order) { |
| 2010 Isolate* isolate = Isolate::Current(); |
| 2011 NoAllocationSampleFilter filter(isolate); |
| 2012 PrintJSONImpl(isolate, stream, tag_order, &filter); |
| 2013 } |
| 2014 |
| 2015 |
| 2016 class ClassAllocationSampleFilter : public SampleFilter { |
| 2017 public: |
| 2018 ClassAllocationSampleFilter(Isolate* isolate, const Class& cls) |
| 2019 : SampleFilter(isolate), |
| 2020 cls_(Class::Handle(cls.raw())) { |
| 2021 ASSERT(!cls_.IsNull()); |
| 2022 } |
| 2023 |
| 2024 bool FilterSample(Sample* sample) { |
| 2025 return sample->is_allocation_sample() && |
| 2026 (sample->allocation_cid() == cls_.id()); |
| 2027 } |
| 2028 |
| 2029 private: |
| 2030 const Class& cls_; |
| 2031 }; |
| 2032 |
| 2033 |
| 2034 void ProfilerService::PrintAllocationJSON(JSONStream* stream, |
| 2035 Profile::TagOrder tag_order, |
| 2036 const Class& cls) { |
| 2037 Isolate* isolate = Isolate::Current(); |
| 2038 ClassAllocationSampleFilter filter(isolate, cls); |
| 2039 PrintJSONImpl(isolate, stream, tag_order, &filter); |
| 2040 } |
| 2041 |
| 2042 |
| 2008 void ProfilerService::ClearSamples() { | 2043 void ProfilerService::ClearSamples() { |
| 2009 Isolate* isolate = Isolate::Current(); | 2044 Isolate* isolate = Isolate::Current(); |
| 2010 | 2045 |
| 2011 // Disable profile interrupts while processing the buffer. | 2046 // Disable profile interrupts while processing the buffer. |
| 2012 Profiler::EndExecution(isolate); | 2047 Profiler::EndExecution(isolate); |
| 2013 | 2048 |
| 2014 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); | 2049 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); |
| 2015 IsolateProfilerData* profiler_data = isolate->profiler_data(); | 2050 IsolateProfilerData* profiler_data = isolate->profiler_data(); |
| 2016 if (profiler_data == NULL) { | 2051 if (profiler_data == NULL) { |
| 2017 return; | 2052 return; |
| 2018 } | 2053 } |
| 2019 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); | 2054 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); |
| 2020 ASSERT(sample_buffer != NULL); | 2055 ASSERT(sample_buffer != NULL); |
| 2021 | 2056 |
| 2022 ClearProfileVisitor clear_profile(isolate); | 2057 ClearProfileVisitor clear_profile(isolate); |
| 2023 sample_buffer->VisitSamples(&clear_profile); | 2058 sample_buffer->VisitSamples(&clear_profile); |
| 2024 | 2059 |
| 2025 // Enable profile interrupts. | 2060 // Enable profile interrupts. |
| 2026 Profiler::BeginExecution(isolate); | 2061 Profiler::BeginExecution(isolate); |
| 2027 } | 2062 } |
| 2028 | 2063 |
| 2029 } // namespace dart | 2064 } // namespace dart |
| OLD | NEW |