4
4
5
5
#include " GeckoProfiler.h"
6
6
7
- #include " mozilla/Maybe.h"
8
- #include " nsPrintfCString.h"
9
- #include " public/GeckoTraceEvent.h"
10
-
11
7
using namespace mozilla ;
12
- using webrtc::trace_event_internal::TraceValueUnion;
13
8
14
9
void uprofiler_register_thread (const char * name, void * stacktop) {
15
10
#ifdef MOZ_GECKO_PROFILER
@@ -23,177 +18,30 @@ void uprofiler_unregister_thread() {
23
18
#endif // MOZ_GECKO_PROFILER
24
19
}
25
20
21
+ // The category string will be handled later in Bug 1715047
22
+ void uprofiler_simple_event_marker (const char * name, const char *, char phase) {
26
23
#ifdef MOZ_GECKO_PROFILER
27
- namespace {
28
- Maybe<MarkerTiming> ToTiming (char phase) {
29
24
switch (phase) {
30
25
case ' B' :
31
- return Some (MarkerTiming::IntervalStart ());
26
+ profiler_add_marker (ProfilerString8View::WrapNullTerminatedString (name),
27
+ geckoprofiler::category::MEDIA_RT,
28
+ {MarkerTiming::IntervalStart ()});
29
+ break ;
32
30
case ' E' :
33
- return Some (MarkerTiming::IntervalEnd ());
31
+ profiler_add_marker (ProfilerString8View::WrapNullTerminatedString (name),
32
+ geckoprofiler::category::MEDIA_RT,
33
+ {MarkerTiming::IntervalEnd ()});
34
+ break ;
34
35
case ' I' :
35
- return Some (MarkerTiming::InstantNow ());
36
+ profiler_add_marker (ProfilerString8View::WrapNullTerminatedString (name),
37
+ geckoprofiler::category::MEDIA_RT,
38
+ {MarkerTiming::InstantNow ()});
39
+ break ;
36
40
default :
37
- return Nothing ();
38
- }
39
- }
40
-
41
- struct TraceOption {
42
- bool mPassed = false ;
43
- ProfilerString8View mName ;
44
- Variant<int64_t , bool , double , ProfilerString8View> mValue = AsVariant(false );
45
- };
46
-
47
- struct TraceMarker {
48
- static constexpr int MAX_NUM_ARGS = 2 ;
49
- using OptionsType = std::tuple<TraceOption, TraceOption>;
50
- static constexpr mozilla::Span<const char > MarkerTypeName () {
51
- return MakeStringSpan (" TraceEvent" );
52
- }
53
- static void StreamJSONMarkerData (
54
- mozilla::baseprofiler::SpliceableJSONWriter& aWriter,
55
- const OptionsType& aArgs) {
56
- auto writeValue = [&](const auto & aName, const auto & aVariant) {
57
- aVariant.match (
58
- [&](const int64_t & aValue) { aWriter.IntProperty (aName, aValue); },
59
- [&](const bool & aValue) { aWriter.BoolProperty (aName, aValue); },
60
- [&](const double & aValue) { aWriter.DoubleProperty (aName, aValue); },
61
- [&](const ProfilerString8View& aValue) {
62
- aWriter.StringProperty (aName, aValue);
63
- });
64
- };
65
- if (const auto & arg = std::get<0 >(aArgs); arg.mPassed ) {
66
- aWriter.StringProperty (" name1" , arg.mName );
67
- writeValue (" val1" , arg.mValue );
68
- }
69
- if (const auto & arg = std::get<1 >(aArgs); arg.mPassed ) {
70
- aWriter.StringProperty (" name2" , arg.mName );
71
- writeValue (" val2" , arg.mValue );
72
- }
73
- }
74
- static mozilla::MarkerSchema MarkerTypeDisplay () {
75
- using MS = MarkerSchema;
76
- MS schema{MS::Location::MarkerChart, MS::Location::MarkerTable};
77
- schema.SetChartLabel (" {marker.name}" );
78
- schema.SetTableLabel (
79
- " {marker.name} {marker.data.name1} {marker.data.val1} "
80
- " {marker.data.name2} {marker.data.val2}" );
81
- schema.AddKeyLabelFormat (" name1" , " Key 1" , MS::Format::String);
82
- schema.AddKeyLabelFormat (" val1" , " Value 1" , MS::Format::String);
83
- schema.AddKeyLabelFormat (" name2" , " Key 2" , MS::Format::String);
84
- schema.AddKeyLabelFormat (" val2" , " Value 2" , MS::Format::String);
85
- return schema;
86
- }
87
- };
88
- } // namespace
89
-
90
- namespace mozilla {
91
- template <>
92
- struct ProfileBufferEntryWriter ::Serializer<TraceOption> {
93
- static Length Bytes (const TraceOption& aOption) {
94
- // 1 byte to store passed flag, then object size if passed.
95
- return aOption.mPassed ? (1 + SumBytes (aOption.mName , aOption.mValue )) : 1 ;
96
- }
97
-
98
- static void Write (ProfileBufferEntryWriter& aEW, const TraceOption& aOption) {
99
- // 'T'/'t' is just an arbitrary 1-byte value to distinguish states.
100
- if (aOption.mPassed ) {
101
- aEW.WriteObject <char >(' T' );
102
- // Use the Serializer for the name/value pair.
103
- aEW.WriteObject (aOption.mName );
104
- aEW.WriteObject (aOption.mValue );
105
- } else {
106
- aEW.WriteObject <char >(' t' );
107
- }
108
- }
109
- };
110
-
111
- template <>
112
- struct ProfileBufferEntryReader ::Deserializer<TraceOption> {
113
- static void ReadInto (ProfileBufferEntryReader& aER, TraceOption& aOption) {
114
- char c = aER.ReadObject <char >();
115
- if ((aOption.mPassed = (c == ' T' ))) {
116
- aER.ReadIntoObject (aOption.mName );
117
- aER.ReadIntoObject (aOption.mValue );
118
- } else {
119
- MOZ_ASSERT (c == ' t' );
120
- }
121
- }
122
-
123
- static TraceOption Read (ProfileBufferEntryReader& aER) {
124
- TraceOption option;
125
- ReadInto (aER, option);
126
- return option;
127
- }
128
- };
129
- } // namespace mozilla
130
- #endif // MOZ_GECKO_PROFILER
131
-
132
- void uprofiler_simple_event_marker (const char * name, char phase, int num_args,
133
- const char ** arg_names,
134
- const unsigned char * arg_types,
135
- const unsigned long long * arg_values) {
136
- #ifdef MOZ_GECKO_PROFILER
137
- if (!profiler_thread_is_being_profiled_for_markers ()) {
138
- return ;
139
- }
140
- Maybe<MarkerTiming> timing = ToTiming (phase);
141
- if (!timing) {
142
- if (getenv (" MOZ_LOG_UNKNOWN_TRACE_EVENT_PHASES" )) {
143
- fprintf (stderr, " XXX UProfiler: phase not handled: '%c'\n " , phase);
144
- }
145
- return ;
146
- }
147
- MOZ_ASSERT (num_args <= TraceMarker::MAX_NUM_ARGS);
148
- TraceMarker::OptionsType tuple;
149
- TraceOption* args[2 ] = {&std::get<0 >(tuple), &std::get<1 >(tuple)};
150
- for (int i = 0 ; i < std::min (num_args, TraceMarker::MAX_NUM_ARGS); ++i) {
151
- auto & arg = *args[i];
152
- arg.mPassed = true ;
153
- arg.mName = ProfilerString8View::WrapNullTerminatedString (arg_names[i]);
154
- switch (arg_types[i]) {
155
- case TRACE_VALUE_TYPE_UINT:
156
- MOZ_ASSERT (arg_values[i] <= std::numeric_limits<int64_t >::max ());
157
- arg.mValue = AsVariant (static_cast <int64_t >(
158
- reinterpret_cast <const TraceValueUnion*>(&arg_values[i])->as_uint ));
159
- break ;
160
- case TRACE_VALUE_TYPE_INT:
161
- arg.mValue = AsVariant (static_cast <int64_t >(
162
- reinterpret_cast <const TraceValueUnion*>(&arg_values[i])->as_int ));
163
- break ;
164
- case TRACE_VALUE_TYPE_BOOL:
165
- arg.mValue = AsVariant (
166
- reinterpret_cast <const TraceValueUnion*>(&arg_values[i])->as_bool );
167
- break ;
168
- case TRACE_VALUE_TYPE_DOUBLE:
169
- arg.mValue =
170
- AsVariant (reinterpret_cast <const TraceValueUnion*>(&arg_values[i])
171
- ->as_double );
172
- break ;
173
- case TRACE_VALUE_TYPE_POINTER:
174
- arg.mValue = AsVariant (ProfilerString8View (nsPrintfCString (
175
- " %p" , reinterpret_cast <const TraceValueUnion*>(&arg_values[i])
176
- ->as_pointer )));
177
- break ;
178
- case TRACE_VALUE_TYPE_STRING:
179
- arg.mValue = AsVariant (ProfilerString8View::WrapNullTerminatedString (
180
- reinterpret_cast <const TraceValueUnion*>(&arg_values[i])
181
- ->as_string ));
182
- break ;
183
- case TRACE_VALUE_TYPE_COPY_STRING:
184
- arg.mValue = AsVariant (ProfilerString8View (
185
- nsCString (reinterpret_cast <const TraceValueUnion*>(&arg_values[i])
186
- ->as_string )));
187
- break ;
188
- default :
189
- MOZ_ASSERT_UNREACHABLE (" Unexpected trace value type" );
190
- arg.mValue = AsVariant (ProfilerString8View (
191
- nsPrintfCString (" Unexpected type: %u" , arg_types[i])));
192
- break ;
193
- }
41
+ if (getenv (" MOZ_LOG_UNKNOWN_TRACE_EVENT_PHASES" )) {
42
+ fprintf (stderr, " XXX UProfiler: phase not handled: '%c'\n " , phase);
43
+ }
44
+ break ;
194
45
}
195
- profiler_add_marker (ProfilerString8View::WrapNullTerminatedString (name),
196
- geckoprofiler::category::MEDIA_RT, {timing.extract ()},
197
- TraceMarker{}, tuple);
198
46
#endif // MOZ_GECKO_PROFILER
199
47
}
0 commit comments