| 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 #ifndef RUNTIME_VM_TIMELINE_H_ | 5 #ifndef RUNTIME_VM_TIMELINE_H_ |
| 6 #define RUNTIME_VM_TIMELINE_H_ | 6 #define RUNTIME_VM_TIMELINE_H_ |
| 7 | 7 |
| 8 #include "include/dart_tools_api.h" | 8 #include "include/dart_tools_api.h" |
| 9 | 9 |
| 10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| 11 #include "vm/bitfield.h" | 11 #include "vm/bitfield.h" |
| 12 #include "vm/growable_array.h" |
| 12 #include "vm/os.h" | 13 #include "vm/os.h" |
| 14 #include "vm/os_thread.h" |
| 13 | 15 |
| 14 namespace dart { | 16 namespace dart { |
| 15 | 17 |
| 16 class JSONArray; | 18 class JSONArray; |
| 17 class JSONObject; | 19 class JSONObject; |
| 18 class JSONStream; | 20 class JSONStream; |
| 19 class Object; | 21 class Object; |
| 20 class ObjectPointerVisitor; | 22 class ObjectPointerVisitor; |
| 21 class Isolate; | 23 class Isolate; |
| 22 class RawArray; | 24 class RawArray; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 321 } |
| 320 | 322 |
| 321 bool Within(int64_t time_origin_micros, int64_t time_extent_micros); | 323 bool Within(int64_t time_origin_micros, int64_t time_extent_micros); |
| 322 | 324 |
| 323 const char* GetSerializedJSON() const; | 325 const char* GetSerializedJSON() const; |
| 324 | 326 |
| 325 void set_owns_label(bool owns_label) { | 327 void set_owns_label(bool owns_label) { |
| 326 state_ = OwnsLabelBit::update(owns_label, state_); | 328 state_ = OwnsLabelBit::update(owns_label, state_); |
| 327 } | 329 } |
| 328 | 330 |
| 329 // Returns the number of bytes written into |buffer|. | 331 TimelineEventArgument* arguments() const { return arguments_; } |
| 330 intptr_t PrintSystrace(char* buffer, intptr_t buffer_size); | |
| 331 | 332 |
| 332 #if defined(HOST_OS_FUCHSIA) | 333 intptr_t arguments_length() const { return arguments_length_; } |
| 333 void EmitFuchsiaEvent(); | |
| 334 #endif | |
| 335 | 334 |
| 336 private: | 335 private: |
| 337 void FreeArguments(); | 336 void FreeArguments(); |
| 338 | 337 |
| 339 void StreamInit(TimelineStream* stream); | 338 void StreamInit(TimelineStream* stream); |
| 340 void Init(EventType event_type, const char* label); | 339 void Init(EventType event_type, const char* label); |
| 341 | 340 |
| 342 void set_event_type(EventType event_type) { | 341 void set_event_type(EventType event_type) { |
| 343 // We only reserve 4 bits to hold the event type. | 342 // We only reserve 4 bits to hold the event type. |
| 344 COMPILE_ASSERT(kNumEventTypes < 16); | 343 COMPILE_ASSERT(kNumEventTypes < 16); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 uword state_; | 392 uword state_; |
| 394 const char* label_; | 393 const char* label_; |
| 395 const char* category_; | 394 const char* category_; |
| 396 ThreadId thread_; | 395 ThreadId thread_; |
| 397 Dart_Port isolate_id_; | 396 Dart_Port isolate_id_; |
| 398 | 397 |
| 399 friend class TimelineEventRecorder; | 398 friend class TimelineEventRecorder; |
| 400 friend class TimelineEventEndlessRecorder; | 399 friend class TimelineEventEndlessRecorder; |
| 401 friend class TimelineEventRingRecorder; | 400 friend class TimelineEventRingRecorder; |
| 402 friend class TimelineEventStartupRecorder; | 401 friend class TimelineEventStartupRecorder; |
| 403 friend class TimelineEventSystraceRecorder; | 402 friend class TimelineEventPlatformRecorder; |
| 404 friend class TimelineEventFuchsiaRecorder; | |
| 405 friend class TimelineStream; | 403 friend class TimelineStream; |
| 406 friend class TimelineTestHelper; | 404 friend class TimelineTestHelper; |
| 407 DISALLOW_COPY_AND_ASSIGN(TimelineEvent); | 405 DISALLOW_COPY_AND_ASSIGN(TimelineEvent); |
| 408 }; | 406 }; |
| 409 | 407 |
| 410 #ifndef PRODUCT | 408 #ifndef PRODUCT |
| 411 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, name, function) \ | 409 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, name, function) \ |
| 412 TimelineDurationScope tds(thread, Timeline::GetCompilerStream(), name); \ | 410 TimelineDurationScope tds(thread, Timeline::GetCompilerStream(), name); \ |
| 413 if (tds.enabled()) { \ | 411 if (tds.enabled()) { \ |
| 414 tds.SetNumArguments(1); \ | 412 tds.SetNumArguments(1); \ |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 bool in_use_; | 566 bool in_use_; |
| 569 | 567 |
| 570 void Open(); | 568 void Open(); |
| 571 void Finish(); | 569 void Finish(); |
| 572 | 570 |
| 573 friend class Thread; | 571 friend class Thread; |
| 574 friend class TimelineEventRecorder; | 572 friend class TimelineEventRecorder; |
| 575 friend class TimelineEventEndlessRecorder; | 573 friend class TimelineEventEndlessRecorder; |
| 576 friend class TimelineEventRingRecorder; | 574 friend class TimelineEventRingRecorder; |
| 577 friend class TimelineEventStartupRecorder; | 575 friend class TimelineEventStartupRecorder; |
| 578 friend class TimelineEventSystraceRecorder; | 576 friend class TimelineEventPlatformRecorder; |
| 579 friend class TimelineEventFuchsiaRecorder; | |
| 580 friend class TimelineTestHelper; | 577 friend class TimelineTestHelper; |
| 581 friend class JSONStream; | 578 friend class JSONStream; |
| 582 | 579 |
| 583 private: | 580 private: |
| 584 DISALLOW_COPY_AND_ASSIGN(TimelineEventBlock); | 581 DISALLOW_COPY_AND_ASSIGN(TimelineEventBlock); |
| 585 }; | 582 }; |
| 586 | 583 |
| 587 class TimelineEventFilter : public ValueObject { | 584 class TimelineEventFilter : public ValueObject { |
| 588 public: | 585 public: |
| 589 TimelineEventFilter(int64_t time_origin_micros = -1, | 586 TimelineEventFilter(int64_t time_origin_micros = -1, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 explicit TimelineEventRingRecorder(intptr_t capacity = kDefaultCapacity) | 718 explicit TimelineEventRingRecorder(intptr_t capacity = kDefaultCapacity) |
| 722 : TimelineEventFixedBufferRecorder(capacity) {} | 719 : TimelineEventFixedBufferRecorder(capacity) {} |
| 723 virtual ~TimelineEventRingRecorder() {} | 720 virtual ~TimelineEventRingRecorder() {} |
| 724 | 721 |
| 725 const char* name() const { return "Ring"; } | 722 const char* name() const { return "Ring"; } |
| 726 | 723 |
| 727 protected: | 724 protected: |
| 728 TimelineEventBlock* GetNewBlockLocked(); | 725 TimelineEventBlock* GetNewBlockLocked(); |
| 729 }; | 726 }; |
| 730 | 727 |
| 731 // A recorder that writes events to Android Systrace. Events are also stored in | |
| 732 // a buffer of fixed capacity. When the buffer is full, new events overwrite | |
| 733 // old events. | |
| 734 class TimelineEventSystraceRecorder : public TimelineEventFixedBufferRecorder { | |
| 735 public: | |
| 736 explicit TimelineEventSystraceRecorder(intptr_t capacity = kDefaultCapacity); | |
| 737 virtual ~TimelineEventSystraceRecorder(); | |
| 738 | |
| 739 const char* name() const { return "Systrace"; } | |
| 740 | |
| 741 protected: | |
| 742 TimelineEventBlock* GetNewBlockLocked(); | |
| 743 void CompleteEvent(TimelineEvent* event); | |
| 744 | |
| 745 int systrace_fd_; | |
| 746 }; | |
| 747 | |
| 748 #if defined(HOST_OS_FUCHSIA) | |
| 749 // A recorder that sends events to Fuchsia's tracing app. Events are also stored | |
| 750 // in a buffer of fixed capacity. When the buffer is full, new events overwrite | |
| 751 // old events. | |
| 752 // See: https://fuchsia.googlesource.com/tracing/+/HEAD/docs/usage_guide.md | |
| 753 class TimelineEventFuchsiaRecorder : public TimelineEventFixedBufferRecorder { | |
| 754 public: | |
| 755 explicit TimelineEventFuchsiaRecorder(intptr_t capacity = kDefaultCapacity); | |
| 756 virtual ~TimelineEventFuchsiaRecorder() {} | |
| 757 | |
| 758 const char* name() const { return "Fuchsia"; } | |
| 759 | |
| 760 protected: | |
| 761 TimelineEventBlock* GetNewBlockLocked(); | |
| 762 void CompleteEvent(TimelineEvent* event); | |
| 763 }; | |
| 764 #endif // defined(HOST_OS_FUCHSIA) | |
| 765 | |
| 766 // A recorder that stores events in a buffer of fixed capacity. When the buffer | 728 // A recorder that stores events in a buffer of fixed capacity. When the buffer |
| 767 // is full, new events are dropped. | 729 // is full, new events are dropped. |
| 768 class TimelineEventStartupRecorder : public TimelineEventFixedBufferRecorder { | 730 class TimelineEventStartupRecorder : public TimelineEventFixedBufferRecorder { |
| 769 public: | 731 public: |
| 770 explicit TimelineEventStartupRecorder(intptr_t capacity = kDefaultCapacity) | 732 explicit TimelineEventStartupRecorder(intptr_t capacity = kDefaultCapacity) |
| 771 : TimelineEventFixedBufferRecorder(capacity) {} | 733 : TimelineEventFixedBufferRecorder(capacity) {} |
| 772 virtual ~TimelineEventStartupRecorder() {} | 734 virtual ~TimelineEventStartupRecorder() {} |
| 773 | 735 |
| 774 const char* name() const { return "Startup"; } | 736 const char* name() const { return "Startup"; } |
| 775 | 737 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 bool HasNext() const; | 803 bool HasNext() const; |
| 842 | 804 |
| 843 // Returns the next block and moves forward. | 805 // Returns the next block and moves forward. |
| 844 TimelineEventBlock* Next(); | 806 TimelineEventBlock* Next(); |
| 845 | 807 |
| 846 private: | 808 private: |
| 847 TimelineEventBlock* current_; | 809 TimelineEventBlock* current_; |
| 848 TimelineEventRecorder* recorder_; | 810 TimelineEventRecorder* recorder_; |
| 849 }; | 811 }; |
| 850 | 812 |
| 813 // The TimelineEventPlatformRecorder records timeline events to a platform |
| 814 // specific destination. It's implementation is in the timeline_{linux,...}.cc |
| 815 // files. |
| 816 class TimelineEventPlatformRecorder : public TimelineEventFixedBufferRecorder { |
| 817 public: |
| 818 explicit TimelineEventPlatformRecorder(intptr_t capacity = kDefaultCapacity); |
| 819 virtual ~TimelineEventPlatformRecorder(); |
| 820 |
| 821 static TimelineEventPlatformRecorder* CreatePlatformRecorder( |
| 822 intptr_t capacity = kDefaultCapacity); |
| 823 |
| 824 const char* name() const; |
| 825 |
| 826 protected: |
| 827 TimelineEventBlock* GetNewBlockLocked(); |
| 828 virtual void CompleteEvent(TimelineEvent* event); |
| 829 }; |
| 830 |
| 831 #if defined(HOST_OS_ANDROID) || defined(HOST_OS_LINUX) |
| 832 // A recorder that writes events to Android Systrace. Events are also stored in |
| 833 // a buffer of fixed capacity. When the buffer is full, new events overwrite |
| 834 // old events. This class is exposed in this header file only so that |
| 835 // PrintSystrace can be visible to timeline_test.cc. |
| 836 class TimelineEventSystraceRecorder : public TimelineEventPlatformRecorder { |
| 837 public: |
| 838 explicit TimelineEventSystraceRecorder(intptr_t capacity = kDefaultCapacity); |
| 839 virtual ~TimelineEventSystraceRecorder(); |
| 840 |
| 841 static intptr_t PrintSystrace(TimelineEvent* event, |
| 842 char* buffer, |
| 843 intptr_t buffer_size); |
| 844 |
| 845 private: |
| 846 virtual void CompleteEvent(TimelineEvent* event); |
| 847 |
| 848 int systrace_fd_; |
| 849 }; |
| 850 #endif // defined(HOST_OS_ANDROID) || defined(HOST_OS_LINUX) |
| 851 |
| 852 // These helper functions have platform specific implementations defined in |
| 853 // the timeline_{linux,...}.cc files. They are called from the runtime calls |
| 854 // that implement the dart:developer Timeline API. |
| 855 class DartTimelineEventHelpers : public AllStatic { |
| 856 public: |
| 857 static void ReportTaskEvent(Thread* thread, |
| 858 Zone* zone, |
| 859 TimelineEvent* event, |
| 860 int64_t start, |
| 861 int64_t id, |
| 862 const char* phase, |
| 863 const char* category, |
| 864 const char* name, |
| 865 const char* args); |
| 866 |
| 867 static void ReportCompleteEvent(Thread* thread, |
| 868 Zone* zone, |
| 869 TimelineEvent* event, |
| 870 int64_t start, |
| 871 int64_t start_cpu, |
| 872 const char* category, |
| 873 const char* name, |
| 874 const char* args); |
| 875 |
| 876 static void ReportInstantEvent(Thread* thread, |
| 877 Zone* zone, |
| 878 TimelineEvent* event, |
| 879 int64_t start, |
| 880 const char* category, |
| 881 const char* name, |
| 882 const char* args); |
| 883 }; |
| 884 |
| 885 // These are common implementations of the DartTimelineEventHelpers that should |
| 886 // be used when there is nothing platform-specific needed. |
| 887 class DartCommonTimelineEventHelpers : public AllStatic { |
| 888 public: |
| 889 static void ReportTaskEvent(Thread* thread, |
| 890 Zone* zone, |
| 891 TimelineEvent* event, |
| 892 int64_t start, |
| 893 int64_t id, |
| 894 const char* phase, |
| 895 const char* category, |
| 896 const char* name, |
| 897 const char* args); |
| 898 |
| 899 static void ReportCompleteEvent(Thread* thread, |
| 900 Zone* zone, |
| 901 TimelineEvent* event, |
| 902 int64_t start, |
| 903 int64_t start_cpu, |
| 904 const char* category, |
| 905 const char* name, |
| 906 const char* args); |
| 907 |
| 908 static void ReportInstantEvent(Thread* thread, |
| 909 Zone* zone, |
| 910 TimelineEvent* event, |
| 911 int64_t start, |
| 912 const char* category, |
| 913 const char* name, |
| 914 const char* args); |
| 915 }; |
| 916 |
| 851 } // namespace dart | 917 } // namespace dart |
| 852 | 918 |
| 853 #endif // RUNTIME_VM_TIMELINE_H_ | 919 #endif // RUNTIME_VM_TIMELINE_H_ |
| OLD | NEW |