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 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 enum ProfileInfoKind { | 977 enum ProfileInfoKind { |
978 kNone, | 978 kNone, |
979 kOptimized, | 979 kOptimized, |
980 kUnoptimized, | 980 kUnoptimized, |
981 kNative, | 981 kNative, |
982 kInlineStart, | 982 kInlineStart, |
983 kInlineFinish, | 983 kInlineFinish, |
984 kNumProfileInfoKind, | 984 kNumProfileInfoKind, |
985 }; | 985 }; |
986 | 986 |
987 ProfileBuilder(Isolate* isolate, | 987 ProfileBuilder(Thread* thread, |
988 SampleFilter* filter, | 988 SampleFilter* filter, |
989 Profile::TagOrder tag_order, | 989 Profile::TagOrder tag_order, |
990 intptr_t extra_tags, | 990 intptr_t extra_tags, |
991 Profile* profile) | 991 Profile* profile) |
992 : isolate_(isolate), | 992 : thread_(thread), |
993 vm_isolate_(Dart::vm_isolate()), | 993 vm_isolate_(Dart::vm_isolate()), |
994 filter_(filter), | 994 filter_(filter), |
995 tag_order_(tag_order), | 995 tag_order_(tag_order), |
996 extra_tags_(extra_tags), | 996 extra_tags_(extra_tags), |
997 profile_(profile), | 997 profile_(profile), |
998 deoptimized_code_(new DeoptimizedCodeSet(isolate)), | 998 deoptimized_code_(new DeoptimizedCodeSet(thread->isolate())), |
999 null_code_(Code::ZoneHandle()), | 999 null_code_(Code::ZoneHandle()), |
1000 null_function_(Function::ZoneHandle()), | 1000 null_function_(Function::ZoneHandle()), |
1001 tick_functions_(false), | 1001 tick_functions_(false), |
1002 inclusive_tree_(false), | 1002 inclusive_tree_(false), |
1003 samples_(NULL), | 1003 samples_(NULL), |
1004 info_kind_(kNone) { | 1004 info_kind_(kNone) { |
1005 ASSERT(profile_ != NULL); | 1005 ASSERT(profile_ != NULL); |
1006 } | 1006 } |
1007 | 1007 |
1008 void Build() { | 1008 void Build() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 RegisterProfileCodeTag(VMTag::kNoneCodeTagId); | 1044 RegisterProfileCodeTag(VMTag::kNoneCodeTagId); |
1045 RegisterProfileCodeTag(VMTag::kOptimizedCodeTagId); | 1045 RegisterProfileCodeTag(VMTag::kOptimizedCodeTagId); |
1046 RegisterProfileCodeTag(VMTag::kUnoptimizedCodeTagId); | 1046 RegisterProfileCodeTag(VMTag::kUnoptimizedCodeTagId); |
1047 RegisterProfileCodeTag(VMTag::kNativeCodeTagId); | 1047 RegisterProfileCodeTag(VMTag::kNativeCodeTagId); |
1048 RegisterProfileCodeTag(VMTag::kInlineStartCodeTagId); | 1048 RegisterProfileCodeTag(VMTag::kInlineStartCodeTagId); |
1049 RegisterProfileCodeTag(VMTag::kInlineEndCodeTagId); | 1049 RegisterProfileCodeTag(VMTag::kInlineEndCodeTagId); |
1050 } | 1050 } |
1051 | 1051 |
1052 void FilterSamples() { | 1052 void FilterSamples() { |
1053 ScopeTimer sw("ProfileBuilder::FilterSamples", FLAG_trace_profiler); | 1053 ScopeTimer sw("ProfileBuilder::FilterSamples", FLAG_trace_profiler); |
1054 MutexLocker profiler_data_lock(isolate_->profiler_data_mutex()); | 1054 Isolate* isolate = thread_->isolate(); |
1055 IsolateProfilerData* profiler_data = isolate_->profiler_data(); | 1055 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); |
| 1056 IsolateProfilerData* profiler_data = isolate->profiler_data(); |
1056 if (profiler_data == NULL) { | 1057 if (profiler_data == NULL) { |
1057 return; | 1058 return; |
1058 } | 1059 } |
1059 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); | 1060 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); |
1060 if (sample_buffer == NULL) { | 1061 if (sample_buffer == NULL) { |
1061 return; | 1062 return; |
1062 } | 1063 } |
1063 samples_ = sample_buffer->BuildProcessedSampleBuffer(filter_); | 1064 samples_ = sample_buffer->BuildProcessedSampleBuffer(filter_); |
1064 profile_->sample_count_ = samples_->length(); | 1065 profile_->sample_count_ = samples_->length(); |
1065 } | 1066 } |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 pc, | 1839 pc, |
1839 pc + 1, | 1840 pc + 1, |
1840 0, | 1841 0, |
1841 null_code_); | 1842 null_code_); |
1842 return code; | 1843 return code; |
1843 } | 1844 } |
1844 | 1845 |
1845 ProfileCode* CreateProfileCode(uword pc) { | 1846 ProfileCode* CreateProfileCode(uword pc) { |
1846 const intptr_t kDartCodeAlignment = OS::PreferredCodeAlignment(); | 1847 const intptr_t kDartCodeAlignment = OS::PreferredCodeAlignment(); |
1847 const intptr_t kDartCodeAlignmentMask = ~(kDartCodeAlignment - 1); | 1848 const intptr_t kDartCodeAlignmentMask = ~(kDartCodeAlignment - 1); |
1848 Code& code = Code::Handle(isolate_->current_zone()); | 1849 Code& code = Code::Handle(thread_->zone()); |
1849 | 1850 |
1850 // Check current isolate for pc. | 1851 // Check current isolate for pc. |
1851 if (isolate_->heap()->CodeContains(pc)) { | 1852 if (thread_->isolate()->heap()->CodeContains(pc)) { |
1852 code ^= Code::LookupCode(pc); | 1853 code ^= Code::LookupCode(pc); |
1853 if (!code.IsNull()) { | 1854 if (!code.IsNull()) { |
1854 deoptimized_code_->Add(code); | 1855 deoptimized_code_->Add(code); |
1855 return new ProfileCode(ProfileCode::kDartCode, | 1856 return new ProfileCode(ProfileCode::kDartCode, |
1856 code.EntryPoint(), | 1857 code.EntryPoint(), |
1857 code.EntryPoint() + code.Size(), | 1858 code.EntryPoint() + code.Size(), |
1858 code.compile_timestamp(), | 1859 code.compile_timestamp(), |
1859 code); | 1860 code); |
1860 } | 1861 } |
1861 return new ProfileCode(ProfileCode::kCollectedCode, | 1862 return new ProfileCode(ProfileCode::kCollectedCode, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 bool vm_tags_emitted() const { | 1951 bool vm_tags_emitted() const { |
1951 return (tag_order_ == Profile::kUserVM) || | 1952 return (tag_order_ == Profile::kUserVM) || |
1952 (tag_order_ == Profile::kVMUser) || | 1953 (tag_order_ == Profile::kVMUser) || |
1953 (tag_order_ == Profile::kVM); | 1954 (tag_order_ == Profile::kVM); |
1954 } | 1955 } |
1955 | 1956 |
1956 bool TagsEnabled(intptr_t extra_tags_bits) const { | 1957 bool TagsEnabled(intptr_t extra_tags_bits) const { |
1957 return (extra_tags_ & extra_tags_bits) != 0; | 1958 return (extra_tags_ & extra_tags_bits) != 0; |
1958 } | 1959 } |
1959 | 1960 |
1960 Isolate* isolate_; | 1961 Thread* thread_; |
1961 Isolate* vm_isolate_; | 1962 Isolate* vm_isolate_; |
1962 SampleFilter* filter_; | 1963 SampleFilter* filter_; |
1963 Profile::TagOrder tag_order_; | 1964 Profile::TagOrder tag_order_; |
1964 intptr_t extra_tags_; | 1965 intptr_t extra_tags_; |
1965 Profile* profile_; | 1966 Profile* profile_; |
1966 DeoptimizedCodeSet* deoptimized_code_; | 1967 DeoptimizedCodeSet* deoptimized_code_; |
1967 const Code& null_code_; | 1968 const Code& null_code_; |
1968 const Function& null_function_; | 1969 const Function& null_function_; |
1969 bool tick_functions_; | 1970 bool tick_functions_; |
1970 bool inclusive_tree_; | 1971 bool inclusive_tree_; |
1971 | 1972 |
1972 ProcessedSampleBuffer* samples_; | 1973 ProcessedSampleBuffer* samples_; |
1973 ProfileInfoKind info_kind_; | 1974 ProfileInfoKind info_kind_; |
1974 }; | 1975 }; // ProfileBuilder. |
1975 | 1976 |
1976 | 1977 |
1977 Profile::Profile(Isolate* isolate) | 1978 Profile::Profile(Isolate* isolate) |
1978 : isolate_(isolate), | 1979 : isolate_(isolate), |
1979 live_code_(NULL), | 1980 live_code_(NULL), |
1980 dead_code_(NULL), | 1981 dead_code_(NULL), |
1981 tag_code_(NULL), | 1982 tag_code_(NULL), |
1982 functions_(NULL), | 1983 functions_(NULL), |
1983 dead_code_index_offset_(-1), | 1984 dead_code_index_offset_(-1), |
1984 tag_code_index_offset_(-1), | 1985 tag_code_index_offset_(-1), |
1985 min_time_(kMaxInt64), | 1986 min_time_(kMaxInt64), |
1986 max_time_(0) { | 1987 max_time_(0) { |
1987 ASSERT(isolate_ != NULL); | 1988 ASSERT(isolate_ != NULL); |
1988 for (intptr_t i = 0; i < kNumTrieKinds; i++) { | 1989 for (intptr_t i = 0; i < kNumTrieKinds; i++) { |
1989 roots_[i] = NULL; | 1990 roots_[i] = NULL; |
1990 } | 1991 } |
1991 } | 1992 } |
1992 | 1993 |
1993 | 1994 |
1994 void Profile::Build(SampleFilter* filter, | 1995 void Profile::Build(Thread* thread, |
| 1996 SampleFilter* filter, |
1995 TagOrder tag_order, | 1997 TagOrder tag_order, |
1996 intptr_t extra_tags) { | 1998 intptr_t extra_tags) { |
1997 ProfileBuilder builder(isolate_, filter, tag_order, extra_tags, this); | 1999 ProfileBuilder builder(thread, filter, tag_order, extra_tags, this); |
1998 builder.Build(); | 2000 builder.Build(); |
1999 } | 2001 } |
2000 | 2002 |
2001 | 2003 |
2002 ProfileFunction* Profile::GetFunction(intptr_t index) { | 2004 ProfileFunction* Profile::GetFunction(intptr_t index) { |
2003 ASSERT(functions_ != NULL); | 2005 ASSERT(functions_ != NULL); |
2004 return functions_->At(index); | 2006 return functions_->At(index); |
2005 } | 2007 } |
2006 | 2008 |
2007 | 2009 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2209 if (profiler_data == NULL) { | 2211 if (profiler_data == NULL) { |
2210 stream->PrintError(kFeatureDisabled, NULL); | 2212 stream->PrintError(kFeatureDisabled, NULL); |
2211 return; | 2213 return; |
2212 } | 2214 } |
2213 } | 2215 } |
2214 | 2216 |
2215 { | 2217 { |
2216 StackZone zone(thread); | 2218 StackZone zone(thread); |
2217 HANDLESCOPE(thread); | 2219 HANDLESCOPE(thread); |
2218 Profile profile(isolate); | 2220 Profile profile(isolate); |
2219 profile.Build(filter, tag_order, extra_tags); | 2221 profile.Build(thread, filter, tag_order, extra_tags); |
2220 profile.PrintJSON(stream); | 2222 profile.PrintJSON(stream); |
2221 } | 2223 } |
2222 | 2224 |
2223 // Enable profile interrupts. | 2225 // Enable profile interrupts. |
2224 Profiler::BeginExecution(isolate); | 2226 Profiler::BeginExecution(isolate); |
2225 } | 2227 } |
2226 | 2228 |
2227 | 2229 |
2228 class NoAllocationSampleFilter : public SampleFilter { | 2230 class NoAllocationSampleFilter : public SampleFilter { |
2229 public: | 2231 public: |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2290 ASSERT(sample_buffer != NULL); | 2292 ASSERT(sample_buffer != NULL); |
2291 | 2293 |
2292 ClearProfileVisitor clear_profile(isolate); | 2294 ClearProfileVisitor clear_profile(isolate); |
2293 sample_buffer->VisitSamples(&clear_profile); | 2295 sample_buffer->VisitSamples(&clear_profile); |
2294 | 2296 |
2295 // Enable profile interrupts. | 2297 // Enable profile interrupts. |
2296 Profiler::BeginExecution(isolate); | 2298 Profiler::BeginExecution(isolate); |
2297 } | 2299 } |
2298 | 2300 |
2299 } // namespace dart | 2301 } // namespace dart |
OLD | NEW |