@@ -8,7 +8,7 @@ use serde_derive::Serialize;
8
8
9
9
use super :: profile:: StringHandle ;
10
10
use super :: timestamp:: Timestamp ;
11
- use crate :: { CategoryHandle , Profile } ;
11
+ use crate :: { Category , CategoryHandle , Profile } ;
12
12
13
13
/// The handle for a marker. Returned from [`Profile::add_marker`].
14
14
///
@@ -65,9 +65,6 @@ pub trait Marker {
65
65
/// used as `{marker.name}` in the various `label` template strings in the schema.
66
66
fn name ( & self , profile : & mut Profile ) -> StringHandle ;
67
67
68
- /// The category of this marker. The marker chart groups marker rows by category.
69
- fn category ( & self , profile : & mut Profile ) -> CategoryHandle ;
70
-
71
68
/// Called for any fields defined in the schema whose [`format`](RuntimeSchemaMarkerField::format) is
72
69
/// of [kind](MarkerFieldFormat::kind) [`MarkerFieldFormatKind::String`].
73
70
///
@@ -98,17 +95,15 @@ pub trait Marker {
98
95
/// The trait for markers whose schema is known at compile time. Any type which implements
99
96
/// [`StaticSchemaMarker`] automatically implements the [`Marker`] trait via a blanket impl.
100
97
///
101
- /// Markers have a type, a name, a category, and an arbitrary number of fields.
98
+ /// Markers have a type, a name, and an arbitrary number of fields.
102
99
/// The fields of a marker type are defined by the marker type's schema, see [`RuntimeSchemaMarkerSchema`].
103
100
/// The timestamps are not part of the marker; they are supplied separately to
104
101
/// [`Profile::add_marker`] when a marker is added to the profile.
105
102
///
106
- /// In [`StaticSchemaMarker`], the schema is returned from a static `schema` method.
107
- ///
108
103
/// ```
109
104
/// use fxprof_processed_profile::{
110
105
/// Profile, Marker, MarkerLocations, MarkerFieldFlags, MarkerFieldFormat, StaticSchemaMarkerField,
111
- /// StaticSchemaMarker, CategoryHandle , StringHandle,
106
+ /// StaticSchemaMarker, Category, CategoryColor , StringHandle,
112
107
/// };
113
108
///
114
109
/// /// An example marker type with a name and some text content.
@@ -121,6 +116,8 @@ pub trait Marker {
121
116
/// impl StaticSchemaMarker for TextMarker {
122
117
/// const UNIQUE_MARKER_TYPE_NAME: &'static str = "Text";
123
118
///
119
+ /// const CATEGORY: Category<'static> = Category("Other", CategoryColor::Gray);
120
+ ///
124
121
/// const LOCATIONS: MarkerLocations = MarkerLocations::MARKER_CHART.union(MarkerLocations::MARKER_TABLE);
125
122
/// const CHART_LABEL: Option<&'static str> = Some("{marker.data.text}");
126
123
/// const TABLE_LABEL: Option<&'static str> = Some("{marker.name} - {marker.data.text}");
@@ -136,10 +133,6 @@ pub trait Marker {
136
133
/// self.name
137
134
/// }
138
135
///
139
- /// fn category(&self, _profile: &mut Profile) -> CategoryHandle {
140
- /// CategoryHandle::OTHER
141
- /// }
142
- ///
143
136
/// fn string_field_value(&self, _field_index: u32) -> StringHandle {
144
137
/// self.text
145
138
/// }
@@ -154,6 +147,9 @@ pub trait StaticSchemaMarker {
154
147
/// [`RuntimeSchemaMarkerSchema::type_name`] of this type's schema.
155
148
const UNIQUE_MARKER_TYPE_NAME : & ' static str ;
156
149
150
+ /// The category of this marker. The marker chart groups marker rows by category.
151
+ const CATEGORY : Category < ' static > ;
152
+
157
153
/// An optional description string. Applies to all markers of this type.
158
154
const DESCRIPTION : Option < & ' static str > = None ;
159
155
@@ -204,9 +200,6 @@ pub trait StaticSchemaMarker {
204
200
/// used as `{marker.name}` in the various `label` template strings in the schema.
205
201
fn name ( & self , profile : & mut Profile ) -> StringHandle ;
206
202
207
- /// The category of this marker. The marker chart groups marker rows by category.
208
- fn category ( & self , profile : & mut Profile ) -> CategoryHandle ;
209
-
210
203
/// Called for any fields defined in the schema whose [`format`](RuntimeSchemaMarkerField::format) is
211
204
/// of [kind](MarkerFieldFormat::kind) [`MarkerFieldFormatKind::String`].
212
205
///
@@ -243,10 +236,6 @@ impl<T: StaticSchemaMarker> Marker for T {
243
236
<T as StaticSchemaMarker >:: name ( self , profile)
244
237
}
245
238
246
- fn category ( & self , profile : & mut Profile ) -> CategoryHandle {
247
- <T as StaticSchemaMarker >:: category ( self , profile)
248
- }
249
-
250
239
fn string_field_value ( & self , field_index : u32 ) -> StringHandle {
251
240
<T as StaticSchemaMarker >:: string_field_value ( self , field_index)
252
241
}
@@ -265,12 +254,14 @@ impl<T: StaticSchemaMarker> Marker for T {
265
254
/// ```
266
255
/// use fxprof_processed_profile::{
267
256
/// Profile, Marker, MarkerLocations, MarkerFieldFlags, MarkerFieldFormat, RuntimeSchemaMarkerSchema, RuntimeSchemaMarkerField,
268
- /// CategoryHandle, StringHandle,
257
+ /// CategoryHandle, StringHandle, Category, CategoryColor,
269
258
/// };
270
259
///
271
260
/// # fn fun() {
261
+ /// # let mut profile = Profile::new("My app", std::time::SystemTime::now().into(), fxprof_processed_profile::SamplingInterval::from_millis(1));
272
262
/// let schema = RuntimeSchemaMarkerSchema {
273
263
/// type_name: "custom".into(),
264
+ /// category: profile.handle_for_category(Category("Custom", CategoryColor::Purple)),
274
265
/// locations: MarkerLocations::MARKER_CHART | MarkerLocations::MARKER_TABLE,
275
266
/// chart_label: Some("{marker.data.eventName}".into()),
276
267
/// tooltip_label: Some("Custom {marker.name} marker".into()),
@@ -312,6 +303,9 @@ pub struct RuntimeSchemaMarkerSchema {
312
303
/// with the same name.
313
304
pub type_name : String ,
314
305
306
+ /// The category shared by all markers of this schema.
307
+ pub category : CategoryHandle ,
308
+
315
309
/// An optional description string. Applies to all markers of this type.
316
310
pub description : Option < String > ,
317
311
@@ -636,6 +630,8 @@ pub struct InternalMarkerSchema {
636
630
/// The name of this marker type.
637
631
type_name : String ,
638
632
633
+ category : CategoryHandle ,
634
+
639
635
/// List of marker display locations.
640
636
locations : MarkerLocations ,
641
637
@@ -675,6 +671,7 @@ impl InternalMarkerSchema {
675
671
. count ( ) ;
676
672
Self {
677
673
type_name : schema. type_name ,
674
+ category : schema. category ,
678
675
locations : schema. locations ,
679
676
chart_label : schema. chart_label ,
680
677
tooltip_label : schema. tooltip_label ,
@@ -687,7 +684,7 @@ impl InternalMarkerSchema {
687
684
}
688
685
}
689
686
690
- pub fn from_static_schema < T : StaticSchemaMarker > ( ) -> Self {
687
+ pub fn from_static_schema < T : StaticSchemaMarker > ( profile : & mut Profile ) -> Self {
691
688
let string_field_count = T :: FIELDS
692
689
. iter ( )
693
690
. filter ( |f| f. format . kind ( ) == MarkerFieldFormatKind :: String )
@@ -698,6 +695,7 @@ impl InternalMarkerSchema {
698
695
. count ( ) ;
699
696
Self {
700
697
type_name : T :: UNIQUE_MARKER_TYPE_NAME . into ( ) ,
698
+ category : profile. handle_for_category ( T :: CATEGORY ) ,
701
699
locations : T :: LOCATIONS ,
702
700
chart_label : T :: CHART_LABEL . map ( Into :: into) ,
703
701
tooltip_label : T :: TOOLTIP_LABEL . map ( Into :: into) ,
@@ -713,6 +711,9 @@ impl InternalMarkerSchema {
713
711
pub fn type_name ( & self ) -> & str {
714
712
& self . type_name
715
713
}
714
+ pub fn category ( & self ) -> CategoryHandle {
715
+ self . category
716
+ }
716
717
pub fn fields ( & self ) -> & [ RuntimeSchemaMarkerField ] {
717
718
& self . fields
718
719
}
0 commit comments