| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 return -1; | 469 return -1; |
| 470 } | 470 } |
| 471 char* end_ptr = NULL; | 471 char* end_ptr = NULL; |
| 472 uintptr_t result = strtoul(value, &end_ptr, 10); | 472 uintptr_t result = strtoul(value, &end_ptr, 10); |
| 473 ASSERT(*end_ptr == '\0'); // Parsed full string | 473 ASSERT(*end_ptr == '\0'); // Parsed full string |
| 474 return result; | 474 return result; |
| 475 } | 475 } |
| 476 }; | 476 }; |
| 477 | 477 |
| 478 | 478 |
| 479 class Int64Parameter : public MethodParameter { |
| 480 public: |
| 481 Int64Parameter(const char* name, bool required) |
| 482 : MethodParameter(name, required) { |
| 483 } |
| 484 |
| 485 virtual bool Validate(const char* value) const { |
| 486 if (value == NULL) { |
| 487 return false; |
| 488 } |
| 489 for (const char* cp = value; *cp != '\0'; cp++) { |
| 490 if ((*cp < '0' || *cp > '9') && (*cp != '-')) { |
| 491 return false; |
| 492 } |
| 493 } |
| 494 return true; |
| 495 } |
| 496 |
| 497 static int64_t Parse(const char* value, int64_t default_value = -1) { |
| 498 if ((value == NULL) || (*value == '\0')) { |
| 499 return default_value; |
| 500 } |
| 501 char* end_ptr = NULL; |
| 502 int64_t result = strtoll(value, &end_ptr, 10); |
| 503 ASSERT(*end_ptr == '\0'); // Parsed full string |
| 504 return result; |
| 505 } |
| 506 }; |
| 507 |
| 508 |
| 479 class IdParameter : public MethodParameter { | 509 class IdParameter : public MethodParameter { |
| 480 public: | 510 public: |
| 481 IdParameter(const char* name, bool required) | 511 IdParameter(const char* name, bool required) |
| 482 : MethodParameter(name, required) { | 512 : MethodParameter(name, required) { |
| 483 } | 513 } |
| 484 | 514 |
| 485 virtual bool Validate(const char* value) const { | 515 virtual bool Validate(const char* value) const { |
| 486 return (value != NULL); | 516 return (value != NULL); |
| 487 } | 517 } |
| 488 }; | 518 }; |
| (...skipping 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2726 Profile::kVMUser, | 2756 Profile::kVMUser, |
| 2727 Profile::kVM, | 2757 Profile::kVM, |
| 2728 Profile::kNoTags, // Default value. | 2758 Profile::kNoTags, // Default value. |
| 2729 }; | 2759 }; |
| 2730 | 2760 |
| 2731 | 2761 |
| 2732 static const MethodParameter* get_cpu_profile_params[] = { | 2762 static const MethodParameter* get_cpu_profile_params[] = { |
| 2733 ISOLATE_PARAMETER, | 2763 ISOLATE_PARAMETER, |
| 2734 new EnumParameter("tags", true, tags_enum_names), | 2764 new EnumParameter("tags", true, tags_enum_names), |
| 2735 new BoolParameter("_codeTransitionTags", false), | 2765 new BoolParameter("_codeTransitionTags", false), |
| 2766 new Int64Parameter("timeOriginMicros", false), |
| 2767 new Int64Parameter("timeExtentMicros", false), |
| 2736 NULL, | 2768 NULL, |
| 2737 }; | 2769 }; |
| 2738 | 2770 |
| 2739 | 2771 |
| 2740 // TODO(johnmccutchan): Rename this to GetCpuSamples. | 2772 // TODO(johnmccutchan): Rename this to GetCpuSamples. |
| 2741 static bool GetCpuProfile(Thread* thread, JSONStream* js) { | 2773 static bool GetCpuProfile(Thread* thread, JSONStream* js) { |
| 2742 Profile::TagOrder tag_order = | 2774 Profile::TagOrder tag_order = |
| 2743 EnumMapper(js->LookupParam("tags"), tags_enum_names, tags_enum_values); | 2775 EnumMapper(js->LookupParam("tags"), tags_enum_names, tags_enum_values); |
| 2744 intptr_t extra_tags = 0; | 2776 intptr_t extra_tags = 0; |
| 2745 if (BoolParameter::Parse(js->LookupParam("_codeTransitionTags"))) { | 2777 if (BoolParameter::Parse(js->LookupParam("_codeTransitionTags"))) { |
| 2746 extra_tags |= ProfilerService::kCodeTransitionTagsBit; | 2778 extra_tags |= ProfilerService::kCodeTransitionTagsBit; |
| 2747 } | 2779 } |
| 2748 ProfilerService::PrintJSON(js, tag_order, extra_tags); | 2780 int64_t time_origin_micros = |
| 2781 Int64Parameter::Parse(js->LookupParam("timeOriginMicros")); |
| 2782 int64_t time_extent_micros = |
| 2783 Int64Parameter::Parse(js->LookupParam("timeExtentMicros")); |
| 2784 ProfilerService::PrintJSON(js, |
| 2785 tag_order, |
| 2786 extra_tags, |
| 2787 time_origin_micros, |
| 2788 time_extent_micros); |
| 2749 return true; | 2789 return true; |
| 2750 } | 2790 } |
| 2751 | 2791 |
| 2752 | 2792 |
| 2753 static const MethodParameter* get_cpu_profile_timeline_params[] = { | 2793 static const MethodParameter* get_cpu_profile_timeline_params[] = { |
| 2754 ISOLATE_PARAMETER, | 2794 ISOLATE_PARAMETER, |
| 2755 new EnumParameter("tags", true, tags_enum_names), | 2795 new EnumParameter("tags", true, tags_enum_names), |
| 2796 new Int64Parameter("timeOriginMicros", false), |
| 2797 new Int64Parameter("timeExtentMicros", false), |
| 2756 NULL, | 2798 NULL, |
| 2757 }; | 2799 }; |
| 2758 | 2800 |
| 2759 | 2801 |
| 2760 static bool GetCpuProfileTimeline(Thread* thread, JSONStream* js) { | 2802 static bool GetCpuProfileTimeline(Thread* thread, JSONStream* js) { |
| 2761 Profile::TagOrder tag_order = | 2803 Profile::TagOrder tag_order = |
| 2762 EnumMapper(js->LookupParam("tags"), tags_enum_names, tags_enum_values); | 2804 EnumMapper(js->LookupParam("tags"), tags_enum_names, tags_enum_values); |
| 2763 ProfilerService::PrintTimelineJSON(js, tag_order); | 2805 int64_t time_origin_micros = |
| 2806 UIntParameter::Parse(js->LookupParam("timeOriginMicros")); |
| 2807 int64_t time_extent_micros = |
| 2808 UIntParameter::Parse(js->LookupParam("timeExtentMicros")); |
| 2809 ProfilerService::PrintTimelineJSON(js, |
| 2810 tag_order, |
| 2811 time_origin_micros, |
| 2812 time_extent_micros); |
| 2764 return true; | 2813 return true; |
| 2765 } | 2814 } |
| 2766 | 2815 |
| 2767 | 2816 |
| 2768 static const MethodParameter* get_allocation_samples_params[] = { | 2817 static const MethodParameter* get_allocation_samples_params[] = { |
| 2769 ISOLATE_PARAMETER, | 2818 ISOLATE_PARAMETER, |
| 2770 new EnumParameter("tags", true, tags_enum_names), | 2819 new EnumParameter("tags", true, tags_enum_names), |
| 2771 new IdParameter("classId", false), | 2820 new IdParameter("classId", false), |
| 2821 new Int64Parameter("timeOriginMicros", false), |
| 2822 new Int64Parameter("timeExtentMicros", false), |
| 2772 NULL, | 2823 NULL, |
| 2773 }; | 2824 }; |
| 2774 | 2825 |
| 2775 | 2826 |
| 2776 static bool GetAllocationSamples(Thread* thread, JSONStream* js) { | 2827 static bool GetAllocationSamples(Thread* thread, JSONStream* js) { |
| 2777 Profile::TagOrder tag_order = | 2828 Profile::TagOrder tag_order = |
| 2778 EnumMapper(js->LookupParam("tags"), tags_enum_names, tags_enum_values); | 2829 EnumMapper(js->LookupParam("tags"), tags_enum_names, tags_enum_values); |
| 2830 int64_t time_origin_micros = |
| 2831 Int64Parameter::Parse(js->LookupParam("timeOriginMicros")); |
| 2832 int64_t time_extent_micros = |
| 2833 Int64Parameter::Parse(js->LookupParam("timeExtentMicros")); |
| 2779 const char* class_id = js->LookupParam("classId"); | 2834 const char* class_id = js->LookupParam("classId"); |
| 2780 intptr_t cid = -1; | 2835 intptr_t cid = -1; |
| 2781 GetPrefixedIntegerId(class_id, "classes/", &cid); | 2836 GetPrefixedIntegerId(class_id, "classes/", &cid); |
| 2782 Isolate* isolate = thread->isolate(); | 2837 Isolate* isolate = thread->isolate(); |
| 2783 if (IsValidClassId(isolate, cid)) { | 2838 if (IsValidClassId(isolate, cid)) { |
| 2784 const Class& cls = Class::Handle(GetClassForId(isolate, cid)); | 2839 const Class& cls = Class::Handle(GetClassForId(isolate, cid)); |
| 2785 ProfilerService::PrintAllocationJSON(js, tag_order, cls); | 2840 ProfilerService::PrintAllocationJSON(js, |
| 2841 tag_order, |
| 2842 cls, |
| 2843 time_origin_micros, |
| 2844 time_extent_micros); |
| 2786 } else { | 2845 } else { |
| 2787 PrintInvalidParamError(js, "classId"); | 2846 PrintInvalidParamError(js, "classId"); |
| 2788 } | 2847 } |
| 2789 return true; | 2848 return true; |
| 2790 } | 2849 } |
| 2791 | 2850 |
| 2792 | 2851 |
| 2793 static const MethodParameter* clear_cpu_profile_params[] = { | 2852 static const MethodParameter* clear_cpu_profile_params[] = { |
| 2794 ISOLATE_PARAMETER, | 2853 ISOLATE_PARAMETER, |
| 2795 NULL, | 2854 NULL, |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3595 const ServiceMethodDescriptor& method = service_methods_[i]; | 3654 const ServiceMethodDescriptor& method = service_methods_[i]; |
| 3596 if (strcmp(method_name, method.name) == 0) { | 3655 if (strcmp(method_name, method.name) == 0) { |
| 3597 return &method; | 3656 return &method; |
| 3598 } | 3657 } |
| 3599 } | 3658 } |
| 3600 return NULL; | 3659 return NULL; |
| 3601 } | 3660 } |
| 3602 | 3661 |
| 3603 | 3662 |
| 3604 } // namespace dart | 3663 } // namespace dart |
| OLD | NEW |