OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/service.h" | 5 #include "vm/service.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // TODO(johnmccutchan): Unify embedder service handler lists and their APIs. | 102 // TODO(johnmccutchan): Unify embedder service handler lists and their APIs. |
103 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; | 103 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; |
104 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; | 104 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; |
105 struct ServiceMethodDescriptor; | 105 struct ServiceMethodDescriptor; |
106 const ServiceMethodDescriptor* FindMethod(const char* method_name); | 106 const ServiceMethodDescriptor* FindMethod(const char* method_name); |
107 | 107 |
108 // Support for streams defined in embedders. | 108 // Support for streams defined in embedders. |
109 Dart_ServiceStreamListenCallback Service::stream_listen_callback_ = NULL; | 109 Dart_ServiceStreamListenCallback Service::stream_listen_callback_ = NULL; |
110 Dart_ServiceStreamCancelCallback Service::stream_cancel_callback_ = NULL; | 110 Dart_ServiceStreamCancelCallback Service::stream_cancel_callback_ = NULL; |
111 Dart_GetVMServiceAssetsArchive Service::get_service_assets_callback_ = NULL; | 111 Dart_GetVMServiceAssetsArchive Service::get_service_assets_callback_ = NULL; |
| 112 Dart_EmbedderInformationCallback Service::embedder_information_callback_ = NULL; |
112 | 113 |
113 // These are the set of streams known to the core VM. | 114 // These are the set of streams known to the core VM. |
114 StreamInfo Service::vm_stream("VM"); | 115 StreamInfo Service::vm_stream("VM"); |
115 StreamInfo Service::isolate_stream("Isolate"); | 116 StreamInfo Service::isolate_stream("Isolate"); |
116 StreamInfo Service::debug_stream("Debug"); | 117 StreamInfo Service::debug_stream("Debug"); |
117 StreamInfo Service::gc_stream("GC"); | 118 StreamInfo Service::gc_stream("GC"); |
118 StreamInfo Service::echo_stream("_Echo"); | 119 StreamInfo Service::echo_stream("_Echo"); |
119 StreamInfo Service::graph_stream("_Graph"); | 120 StreamInfo Service::graph_stream("_Graph"); |
120 StreamInfo Service::logging_stream("_Logging"); | 121 StreamInfo Service::logging_stream("_Logging"); |
121 StreamInfo Service::extension_stream("Extension"); | 122 StreamInfo Service::extension_stream("Extension"); |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 Dart_ServiceStreamCancelCallback cancel_callback) { | 1221 Dart_ServiceStreamCancelCallback cancel_callback) { |
1221 stream_listen_callback_ = listen_callback; | 1222 stream_listen_callback_ = listen_callback; |
1222 stream_cancel_callback_ = cancel_callback; | 1223 stream_cancel_callback_ = cancel_callback; |
1223 } | 1224 } |
1224 | 1225 |
1225 void Service::SetGetServiceAssetsCallback( | 1226 void Service::SetGetServiceAssetsCallback( |
1226 Dart_GetVMServiceAssetsArchive get_service_assets) { | 1227 Dart_GetVMServiceAssetsArchive get_service_assets) { |
1227 get_service_assets_callback_ = get_service_assets; | 1228 get_service_assets_callback_ = get_service_assets; |
1228 } | 1229 } |
1229 | 1230 |
| 1231 void Service::SetEmbedderInformationCallback( |
| 1232 Dart_EmbedderInformationCallback callback) { |
| 1233 embedder_information_callback_ = callback; |
| 1234 } |
| 1235 |
| 1236 int64_t Service::CurrentRSS() { |
| 1237 if (embedder_information_callback_ == NULL) { |
| 1238 return -1; |
| 1239 } |
| 1240 Dart_EmbedderInformation info = { |
| 1241 0, // version |
| 1242 NULL, // name |
| 1243 0, // max_rss |
| 1244 0 // current_rss |
| 1245 }; |
| 1246 embedder_information_callback_(&info); |
| 1247 ASSERT(info.version == DART_EMBEDDER_INFORMATION_CURRENT_VERSION); |
| 1248 return info.current_rss; |
| 1249 } |
| 1250 |
| 1251 int64_t Service::MaxRSS() { |
| 1252 if (embedder_information_callback_ == NULL) { |
| 1253 return -1; |
| 1254 } |
| 1255 Dart_EmbedderInformation info = { |
| 1256 0, // version |
| 1257 NULL, // name |
| 1258 0, // max_rss |
| 1259 0 // current_rss |
| 1260 }; |
| 1261 embedder_information_callback_(&info); |
| 1262 ASSERT(info.version == DART_EMBEDDER_INFORMATION_CURRENT_VERSION); |
| 1263 return info.max_rss; |
| 1264 } |
| 1265 |
1230 EmbedderServiceHandler* Service::FindRootEmbedderHandler(const char* name) { | 1266 EmbedderServiceHandler* Service::FindRootEmbedderHandler(const char* name) { |
1231 EmbedderServiceHandler* current = root_service_handler_head_; | 1267 EmbedderServiceHandler* current = root_service_handler_head_; |
1232 while (current != NULL) { | 1268 while (current != NULL) { |
1233 if (strcmp(name, current->name()) == 0) { | 1269 if (strcmp(name, current->name()) == 0) { |
1234 return current; | 1270 return current; |
1235 } | 1271 } |
1236 current = current->next(); | 1272 current = current->next(); |
1237 } | 1273 } |
1238 return NULL; | 1274 return NULL; |
1239 } | 1275 } |
(...skipping 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3814 } | 3850 } |
3815 | 3851 |
3816 private: | 3852 private: |
3817 JSONArray* jsarr_; | 3853 JSONArray* jsarr_; |
3818 }; | 3854 }; |
3819 | 3855 |
3820 static const MethodParameter* get_vm_params[] = { | 3856 static const MethodParameter* get_vm_params[] = { |
3821 NO_ISOLATE_PARAMETER, NULL, | 3857 NO_ISOLATE_PARAMETER, NULL, |
3822 }; | 3858 }; |
3823 | 3859 |
| 3860 void Service::PrintJSONForEmbedderInformation(JSONObject *jsobj) { |
| 3861 if (embedder_information_callback_ != NULL) { |
| 3862 Dart_EmbedderInformation info = { |
| 3863 0, // version |
| 3864 NULL, // name |
| 3865 0, // max_rss |
| 3866 0 // current_rss |
| 3867 }; |
| 3868 embedder_information_callback_(&info); |
| 3869 ASSERT(info.version == DART_EMBEDDER_INFORMATION_CURRENT_VERSION); |
| 3870 if (info.name != NULL) { |
| 3871 jsobj->AddProperty("_embedder", info.name); |
| 3872 } |
| 3873 if (info.max_rss > 0) { |
| 3874 jsobj->AddProperty64("_maxRSS", info.max_rss); |
| 3875 } |
| 3876 if (info.max_rss > 0) { |
| 3877 jsobj->AddProperty64("_currentRSS", info.current_rss); |
| 3878 } |
| 3879 } |
| 3880 } |
| 3881 |
3824 void Service::PrintJSONForVM(JSONStream* js, bool ref) { | 3882 void Service::PrintJSONForVM(JSONStream* js, bool ref) { |
3825 JSONObject jsobj(js); | 3883 JSONObject jsobj(js); |
3826 jsobj.AddProperty("type", (ref ? "@VM" : "VM")); | 3884 jsobj.AddProperty("type", (ref ? "@VM" : "VM")); |
3827 jsobj.AddProperty("name", GetVMName()); | 3885 jsobj.AddProperty("name", GetVMName()); |
3828 if (ref) { | 3886 if (ref) { |
3829 return; | 3887 return; |
3830 } | 3888 } |
3831 jsobj.AddProperty("architectureBits", static_cast<intptr_t>(kBitsPerWord)); | 3889 jsobj.AddProperty("architectureBits", static_cast<intptr_t>(kBitsPerWord)); |
3832 jsobj.AddProperty("targetCPU", CPU::Id()); | 3890 jsobj.AddProperty("targetCPU", CPU::Id()); |
3833 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); | 3891 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); |
3834 jsobj.AddProperty("version", Version::String()); | 3892 jsobj.AddProperty("version", Version::String()); |
3835 jsobj.AddProperty("_profilerMode", FLAG_profile_vm ? "VM" : "Dart"); | 3893 jsobj.AddProperty("_profilerMode", FLAG_profile_vm ? "VM" : "Dart"); |
3836 jsobj.AddProperty64("_nativeZoneMemoryUsage", | 3894 jsobj.AddProperty64("_nativeZoneMemoryUsage", |
3837 ApiNativeScope::current_memory_usage()); | 3895 ApiNativeScope::current_memory_usage()); |
3838 jsobj.AddProperty64("pid", OS::ProcessId()); | 3896 jsobj.AddProperty64("pid", OS::ProcessId()); |
3839 jsobj.AddProperty64("_maxRSS", OS::MaxRSS()); | |
3840 jsobj.AddPropertyTimeMillis( | 3897 jsobj.AddPropertyTimeMillis( |
3841 "startTime", OS::GetCurrentTimeMillis() - Dart::UptimeMillis()); | 3898 "startTime", OS::GetCurrentTimeMillis() - Dart::UptimeMillis()); |
3842 MallocHooks::PrintToJSONObject(&jsobj); | 3899 MallocHooks::PrintToJSONObject(&jsobj); |
| 3900 PrintJSONForEmbedderInformation(&jsobj); |
3843 // Construct the isolate list. | 3901 // Construct the isolate list. |
3844 { | 3902 { |
3845 JSONArray jsarr(&jsobj, "isolates"); | 3903 JSONArray jsarr(&jsobj, "isolates"); |
3846 ServiceIsolateVisitor visitor(&jsarr); | 3904 ServiceIsolateVisitor visitor(&jsarr); |
3847 Isolate::VisitIsolates(&visitor); | 3905 Isolate::VisitIsolates(&visitor); |
3848 } | 3906 } |
3849 } | 3907 } |
3850 | 3908 |
3851 static bool GetVM(Thread* thread, JSONStream* js) { | 3909 static bool GetVM(Thread* thread, JSONStream* js) { |
3852 Service::PrintJSONForVM(js, false); | 3910 Service::PrintJSONForVM(js, false); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4142 if (strcmp(method_name, method.name) == 0) { | 4200 if (strcmp(method_name, method.name) == 0) { |
4143 return &method; | 4201 return &method; |
4144 } | 4202 } |
4145 } | 4203 } |
4146 return NULL; | 4204 return NULL; |
4147 } | 4205 } |
4148 | 4206 |
4149 #endif // !PRODUCT | 4207 #endif // !PRODUCT |
4150 | 4208 |
4151 } // namespace dart | 4209 } // namespace dart |
OLD | NEW |