Skip to content

Commit b657e73

Browse files
committed
Make the marker category part of the schema.
1 parent dc04432 commit b657e73

File tree

12 files changed

+98
-158
lines changed

12 files changed

+98
-158
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rustc_hash::FxHashMap;
21
use indexmap::IndexSet;
2+
use rustc_hash::FxHashMap;
33

44
pub type FastHashMap<K, V> = FxHashMap<K, V>;
55
pub type FastIndexSet<V> = IndexSet<V, rustc_hash::FxBuildHasher>;

fxprof-processed-profile/src/marker_table.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl MarkerTable {
5858
schema: &InternalMarkerSchema,
5959
marker: T,
6060
timing: MarkerTiming,
61-
category: CategoryHandle,
6261
thread_string_table: &mut ThreadStringTable,
6362
global_string_table: &mut GlobalStringTable,
6463
) -> MarkerHandle {
@@ -68,7 +67,7 @@ impl MarkerTable {
6867
MarkerTiming::IntervalStart(s) => (Some(s), None, Phase::IntervalStart),
6968
MarkerTiming::IntervalEnd(e) => (None, Some(e), Phase::IntervalEnd),
7069
};
71-
self.marker_categories.push(category);
70+
self.marker_categories.push(schema.category());
7271
self.marker_name_string_indexes.push(name_string_index);
7372
self.marker_starts.push(s);
7473
self.marker_ends.push(e);

fxprof-processed-profile/src/markers.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde_derive::Serialize;
88

99
use super::profile::StringHandle;
1010
use super::timestamp::Timestamp;
11-
use crate::{CategoryHandle, Profile};
11+
use crate::{Category, CategoryHandle, Profile};
1212

1313
/// The handle for a marker. Returned from [`Profile::add_marker`].
1414
///
@@ -65,9 +65,6 @@ pub trait Marker {
6565
/// used as `{marker.name}` in the various `label` template strings in the schema.
6666
fn name(&self, profile: &mut Profile) -> StringHandle;
6767

68-
/// The category of this marker. The marker chart groups marker rows by category.
69-
fn category(&self, profile: &mut Profile) -> CategoryHandle;
70-
7168
/// Called for any fields defined in the schema whose [`format`](RuntimeSchemaMarkerField::format) is
7269
/// of [kind](MarkerFieldFormat::kind) [`MarkerFieldFormatKind::String`].
7370
///
@@ -98,17 +95,15 @@ pub trait Marker {
9895
/// The trait for markers whose schema is known at compile time. Any type which implements
9996
/// [`StaticSchemaMarker`] automatically implements the [`Marker`] trait via a blanket impl.
10097
///
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.
10299
/// The fields of a marker type are defined by the marker type's schema, see [`RuntimeSchemaMarkerSchema`].
103100
/// The timestamps are not part of the marker; they are supplied separately to
104101
/// [`Profile::add_marker`] when a marker is added to the profile.
105102
///
106-
/// In [`StaticSchemaMarker`], the schema is returned from a static `schema` method.
107-
///
108103
/// ```
109104
/// use fxprof_processed_profile::{
110105
/// Profile, Marker, MarkerLocations, MarkerFieldFlags, MarkerFieldFormat, StaticSchemaMarkerField,
111-
/// StaticSchemaMarker, CategoryHandle, StringHandle,
106+
/// StaticSchemaMarker, Category, CategoryColor, StringHandle,
112107
/// };
113108
///
114109
/// /// An example marker type with a name and some text content.
@@ -121,6 +116,8 @@ pub trait Marker {
121116
/// impl StaticSchemaMarker for TextMarker {
122117
/// const UNIQUE_MARKER_TYPE_NAME: &'static str = "Text";
123118
///
119+
/// const CATEGORY: Category<'static> = Category("Other", CategoryColor::Gray);
120+
///
124121
/// const LOCATIONS: MarkerLocations = MarkerLocations::MARKER_CHART.union(MarkerLocations::MARKER_TABLE);
125122
/// const CHART_LABEL: Option<&'static str> = Some("{marker.data.text}");
126123
/// const TABLE_LABEL: Option<&'static str> = Some("{marker.name} - {marker.data.text}");
@@ -136,10 +133,6 @@ pub trait Marker {
136133
/// self.name
137134
/// }
138135
///
139-
/// fn category(&self, _profile: &mut Profile) -> CategoryHandle {
140-
/// CategoryHandle::OTHER
141-
/// }
142-
///
143136
/// fn string_field_value(&self, _field_index: u32) -> StringHandle {
144137
/// self.text
145138
/// }
@@ -154,6 +147,9 @@ pub trait StaticSchemaMarker {
154147
/// [`RuntimeSchemaMarkerSchema::type_name`] of this type's schema.
155148
const UNIQUE_MARKER_TYPE_NAME: &'static str;
156149

150+
/// The category of this marker. The marker chart groups marker rows by category.
151+
const CATEGORY: Category<'static>;
152+
157153
/// An optional description string. Applies to all markers of this type.
158154
const DESCRIPTION: Option<&'static str> = None;
159155

@@ -204,9 +200,6 @@ pub trait StaticSchemaMarker {
204200
/// used as `{marker.name}` in the various `label` template strings in the schema.
205201
fn name(&self, profile: &mut Profile) -> StringHandle;
206202

207-
/// The category of this marker. The marker chart groups marker rows by category.
208-
fn category(&self, profile: &mut Profile) -> CategoryHandle;
209-
210203
/// Called for any fields defined in the schema whose [`format`](RuntimeSchemaMarkerField::format) is
211204
/// of [kind](MarkerFieldFormat::kind) [`MarkerFieldFormatKind::String`].
212205
///
@@ -243,10 +236,6 @@ impl<T: StaticSchemaMarker> Marker for T {
243236
<T as StaticSchemaMarker>::name(self, profile)
244237
}
245238

246-
fn category(&self, profile: &mut Profile) -> CategoryHandle {
247-
<T as StaticSchemaMarker>::category(self, profile)
248-
}
249-
250239
fn string_field_value(&self, field_index: u32) -> StringHandle {
251240
<T as StaticSchemaMarker>::string_field_value(self, field_index)
252241
}
@@ -265,12 +254,14 @@ impl<T: StaticSchemaMarker> Marker for T {
265254
/// ```
266255
/// use fxprof_processed_profile::{
267256
/// Profile, Marker, MarkerLocations, MarkerFieldFlags, MarkerFieldFormat, RuntimeSchemaMarkerSchema, RuntimeSchemaMarkerField,
268-
/// CategoryHandle, StringHandle,
257+
/// CategoryHandle, StringHandle, Category, CategoryColor,
269258
/// };
270259
///
271260
/// # fn fun() {
261+
/// # let mut profile = Profile::new("My app", std::time::SystemTime::now().into(), fxprof_processed_profile::SamplingInterval::from_millis(1));
272262
/// let schema = RuntimeSchemaMarkerSchema {
273263
/// type_name: "custom".into(),
264+
/// category: profile.handle_for_category(Category("Custom", CategoryColor::Purple)),
274265
/// locations: MarkerLocations::MARKER_CHART | MarkerLocations::MARKER_TABLE,
275266
/// chart_label: Some("{marker.data.eventName}".into()),
276267
/// tooltip_label: Some("Custom {marker.name} marker".into()),
@@ -312,6 +303,9 @@ pub struct RuntimeSchemaMarkerSchema {
312303
/// with the same name.
313304
pub type_name: String,
314305

306+
/// The category shared by all markers of this schema.
307+
pub category: CategoryHandle,
308+
315309
/// An optional description string. Applies to all markers of this type.
316310
pub description: Option<String>,
317311

@@ -636,6 +630,8 @@ pub struct InternalMarkerSchema {
636630
/// The name of this marker type.
637631
type_name: String,
638632

633+
category: CategoryHandle,
634+
639635
/// List of marker display locations.
640636
locations: MarkerLocations,
641637

@@ -675,6 +671,7 @@ impl InternalMarkerSchema {
675671
.count();
676672
Self {
677673
type_name: schema.type_name,
674+
category: schema.category,
678675
locations: schema.locations,
679676
chart_label: schema.chart_label,
680677
tooltip_label: schema.tooltip_label,
@@ -687,7 +684,7 @@ impl InternalMarkerSchema {
687684
}
688685
}
689686

690-
pub fn from_static_schema<T: StaticSchemaMarker>() -> Self {
687+
pub fn from_static_schema<T: StaticSchemaMarker>(profile: &mut Profile) -> Self {
691688
let string_field_count = T::FIELDS
692689
.iter()
693690
.filter(|f| f.format.kind() == MarkerFieldFormatKind::String)
@@ -698,6 +695,7 @@ impl InternalMarkerSchema {
698695
.count();
699696
Self {
700697
type_name: T::UNIQUE_MARKER_TYPE_NAME.into(),
698+
category: profile.handle_for_category(T::CATEGORY),
701699
locations: T::LOCATIONS,
702700
chart_label: T::CHART_LABEL.map(Into::into),
703701
tooltip_label: T::TOOLTIP_LABEL.map(Into::into),
@@ -713,6 +711,9 @@ impl InternalMarkerSchema {
713711
pub fn type_name(&self) -> &str {
714712
&self.type_name
715713
}
714+
pub fn category(&self) -> CategoryHandle {
715+
self.category
716+
}
716717
pub fn fields(&self) -> &[RuntimeSchemaMarkerField] {
717718
&self.fields
718719
}

fxprof-processed-profile/src/profile.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub struct Profile {
122122
pub(crate) global_libs: GlobalLibTable,
123123
pub(crate) kernel_libs: LibMappings<LibraryHandle>,
124124
pub(crate) categories: FastIndexSet<InternalCategory>, // append-only for stable CategoryHandles
125-
pub(crate) processes: Vec<Process>, // append-only for stable ProcessHandles
125+
pub(crate) processes: Vec<Process>, // append-only for stable ProcessHandles
126126
pub(crate) counters: Vec<Counter>,
127127
pub(crate) threads: Vec<Thread>, // append-only for stable ThreadHandles
128128
pub(crate) initial_visible_threads: Vec<ThreadHandle>,
@@ -694,19 +694,19 @@ impl Profile {
694694
/// You usually don't need to call this, ever. It is called by the blanket impl
695695
/// of [`Marker::marker_type`] for all types which implement [`StaticSchemaMarker`].
696696
pub fn static_schema_marker_type<T: StaticSchemaMarker>(&mut self) -> MarkerTypeHandle {
697-
match self
697+
if let Some(handle) = self
698698
.static_schema_marker_types
699-
.entry(T::UNIQUE_MARKER_TYPE_NAME)
699+
.get(T::UNIQUE_MARKER_TYPE_NAME)
700700
{
701-
Entry::Occupied(entry) => *entry.get(),
702-
Entry::Vacant(entry) => {
703-
let handle = MarkerTypeHandle(self.marker_schemas.len());
704-
let schema = InternalMarkerSchema::from_static_schema::<T>();
705-
self.marker_schemas.push(schema);
706-
entry.insert(handle);
707-
handle
708-
}
701+
return *handle;
709702
}
703+
704+
let handle = MarkerTypeHandle(self.marker_schemas.len());
705+
let schema = InternalMarkerSchema::from_static_schema::<T>(self);
706+
self.marker_schemas.push(schema);
707+
self.static_schema_marker_types
708+
.insert(T::UNIQUE_MARKER_TYPE_NAME, handle);
709+
handle
710710
}
711711

712712
/// Add a marker to the given thread.
@@ -715,7 +715,7 @@ impl Profile {
715715
///
716716
/// ```
717717
/// use fxprof_processed_profile::{
718-
/// Profile, CategoryHandle, Marker, MarkerFieldFlags, MarkerFieldFormat, MarkerTiming,
718+
/// Profile, Category, CategoryColor, Marker, MarkerFieldFlags, MarkerFieldFormat, MarkerTiming,
719719
/// StaticSchemaMarker, StaticSchemaMarkerField, StringHandle, ThreadHandle, Timestamp,
720720
/// };
721721
///
@@ -739,6 +739,8 @@ impl Profile {
739739
/// impl StaticSchemaMarker for TextMarker {
740740
/// const UNIQUE_MARKER_TYPE_NAME: &'static str = "Text";
741741
///
742+
/// const CATEGORY: Category<'static> = Category("Other", CategoryColor::Gray);
743+
///
742744
/// const CHART_LABEL: Option<&'static str> = Some("{marker.data.text}");
743745
/// const TABLE_LABEL: Option<&'static str> = Some("{marker.name} - {marker.data.text}");
744746
///
@@ -753,10 +755,6 @@ impl Profile {
753755
/// self.name
754756
/// }
755757
///
756-
/// fn category(&self, _profile: &mut Profile) -> CategoryHandle {
757-
/// CategoryHandle::OTHER
758-
/// }
759-
///
760758
/// fn string_field_value(&self, _field_index: u32) -> StringHandle {
761759
/// self.text
762760
/// }
@@ -774,7 +772,6 @@ impl Profile {
774772
) -> MarkerHandle {
775773
let marker_type = marker.marker_type(self);
776774
let name = marker.name(self);
777-
let category = marker.category(self);
778775
let thread = &mut self.threads[thread.0];
779776
let name_thread_string_index = thread.convert_string_index(&self.string_table, name.0);
780777
let schema = &self.marker_schemas[marker_type.0];
@@ -784,7 +781,6 @@ impl Profile {
784781
schema,
785782
marker,
786783
timing,
787-
category,
788784
&mut self.string_table,
789785
)
790786
}

fxprof-processed-profile/src/thread.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::sample_table::{NativeAllocationsTable, SampleTable, WeightType};
1515
use crate::stack_table::StackTable;
1616
use crate::string_table::{GlobalStringIndex, GlobalStringTable};
1717
use crate::thread_string_table::{ThreadInternalStringIndex, ThreadStringTable};
18-
use crate::{CategoryHandle, Marker, MarkerHandle, MarkerTiming, MarkerTypeHandle, Timestamp};
18+
use crate::{Marker, MarkerHandle, MarkerTiming, MarkerTypeHandle, Timestamp};
1919

2020
/// A process. Can be created with [`Profile::add_process`](crate::Profile::add_process).
2121
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
@@ -169,7 +169,6 @@ impl Thread {
169169
schema: &InternalMarkerSchema,
170170
marker: T,
171171
timing: MarkerTiming,
172-
category: CategoryHandle,
173172
global_string_table: &mut GlobalStringTable,
174173
) -> MarkerHandle {
175174
self.markers.add_marker(
@@ -178,7 +177,6 @@ impl Thread {
178177
schema,
179178
marker,
180179
timing,
181-
category,
182180
&mut self.string_table,
183181
global_string_table,
184182
)

fxprof-processed-profile/tests/integration_tests/main.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::time::Duration;
44
use assert_json_diff::assert_json_eq;
55
use debugid::DebugId;
66
use fxprof_processed_profile::{
7-
Category, CategoryColor, CategoryHandle, CpuDelta, Frame, FrameFlags, FrameInfo, GraphColor,
8-
LibraryInfo, MarkerFieldFlags, MarkerFieldFormat, MarkerGraphType, MarkerTiming, Profile,
7+
Category, CategoryColor, CpuDelta, Frame, FrameFlags, FrameInfo, GraphColor, LibraryInfo,
8+
MarkerFieldFlags, MarkerFieldFormat, MarkerGraphType, MarkerTiming, Profile,
99
ReferenceTimestamp, SamplingInterval, StaticSchemaMarker, StaticSchemaMarkerField,
1010
StaticSchemaMarkerGraph, StringHandle, Symbol, SymbolTable, Timestamp, WeightType,
1111
};
@@ -22,6 +22,7 @@ pub struct TextMarker {
2222

2323
impl StaticSchemaMarker for TextMarker {
2424
const UNIQUE_MARKER_TYPE_NAME: &'static str = "Text";
25+
const CATEGORY: Category<'static> = Category("Other", CategoryColor::Gray);
2526
const CHART_LABEL: Option<&'static str> = Some("{marker.data.name}");
2627
const TABLE_LABEL: Option<&'static str> = Some("{marker.name} - {marker.data.name}");
2728
const FIELDS: &'static [StaticSchemaMarkerField] = &[StaticSchemaMarkerField {
@@ -35,10 +36,6 @@ impl StaticSchemaMarker for TextMarker {
3536
self.name
3637
}
3738

38-
fn category(&self, _profile: &mut Profile) -> CategoryHandle {
39-
CategoryHandle::OTHER
40-
}
41-
4239
fn string_field_value(&self, _field_index: u32) -> StringHandle {
4340
self.text
4441
}
@@ -58,6 +55,7 @@ fn profile_without_js() {
5855
}
5956
impl StaticSchemaMarker for CustomMarker {
6057
const UNIQUE_MARKER_TYPE_NAME: &'static str = "custom";
58+
const CATEGORY: Category<'static> = Category("Other", CategoryColor::Gray);
6159
const TOOLTIP_LABEL: Option<&'static str> = Some("Custom tooltip label");
6260

6361
const FIELDS: &'static [StaticSchemaMarkerField] = &[
@@ -100,10 +98,6 @@ fn profile_without_js() {
10098
profile.handle_for_string("CustomName")
10199
}
102100

103-
fn category(&self, _profile: &mut Profile) -> CategoryHandle {
104-
CategoryHandle::OTHER
105-
}
106-
107101
fn string_field_value(&self, field_index: u32) -> StringHandle {
108102
match field_index {
109103
0 => self.event_name,

samply/src/linux_shared/converter.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use byteorder::LittleEndian;
77
use debugid::DebugId;
88
use framehop::{ExplicitModuleSectionInfo, FrameAddress, Module, Unwinder};
99
use fxprof_processed_profile::{
10-
Category, CategoryColor, CategoryHandle, CpuDelta, LibraryHandle, LibraryInfo,
11-
MarkerFieldFlags, MarkerFieldFormat, MarkerTiming, Profile, ReferenceTimestamp,
12-
SamplingInterval, StaticSchemaMarker, StaticSchemaMarkerField, StringHandle, SubcategoryHandle,
13-
SymbolTable, ThreadHandle,
10+
Category, CategoryColor, CpuDelta, LibraryHandle, LibraryInfo, MarkerFieldFlags,
11+
MarkerFieldFormat, MarkerTiming, Profile, ReferenceTimestamp, SamplingInterval,
12+
StaticSchemaMarker, StaticSchemaMarkerField, StringHandle, SubcategoryHandle, SymbolTable,
13+
ThreadHandle,
1414
};
1515
use linux_perf_data::linux_perf_event_reader::TaskWasPreempted;
1616
use linux_perf_data::simpleperf_dso_type::{DSO_DEX_FILE, DSO_KERNEL, DSO_KERNEL_MODULE};
@@ -1905,6 +1905,8 @@ struct MmapMarker(StringHandle);
19051905
impl StaticSchemaMarker for MmapMarker {
19061906
const UNIQUE_MARKER_TYPE_NAME: &'static str = "mmap";
19071907

1908+
const CATEGORY: Category<'static> = Category("Other", CategoryColor::Gray);
1909+
19081910
const FIELDS: &'static [StaticSchemaMarkerField] = &[StaticSchemaMarkerField {
19091911
key: "name",
19101912
label: "Details",
@@ -1916,10 +1918,6 @@ impl StaticSchemaMarker for MmapMarker {
19161918
profile.handle_for_string("mmap")
19171919
}
19181920

1919-
fn category(&self, _profile: &mut Profile) -> CategoryHandle {
1920-
CategoryHandle::OTHER
1921-
}
1922-
19231921
fn string_field_value(&self, _field_index: u32) -> StringHandle {
19241922
self.0
19251923
}

0 commit comments

Comments
 (0)