Bug 1654413 - Add add_text_marker Rust API r=emilio,gerald

This is the second API for the markers. This allows one payload as a text for
more information. See the PROFILER_MARKER_TEXT macro for the C++ counterpart.

Differential Revision: https://phabricator.services.mozilla.com/D124023
This commit is contained in:
Nazım Can Altınova 2021-09-21 11:08:10 +00:00
parent 02f9877e83
commit 978dbc8ab8
3 changed files with 74 additions and 0 deletions

View File

@ -125,3 +125,21 @@ void gecko_profiler_add_marker_untyped(
mozilla::MarkerStack::WithCaptureOptions(aStackCaptureOptions)));
#endif
}
void gecko_profiler_add_marker_text(
const char* aName, size_t aNameLength,
mozilla::baseprofiler::ProfilingCategoryPair aCategoryPair,
mozilla::MarkerTiming* aMarkerTiming,
mozilla::StackCaptureOptions aStackCaptureOptions, const char* aText,
size_t aTextLength) {
#ifdef MOZ_GECKO_PROFILER
profiler_add_marker(
mozilla::ProfilerString8View(aName, aNameLength),
mozilla::MarkerCategory{aCategoryPair},
mozilla::MarkerOptions(
std::move(*aMarkerTiming),
mozilla::MarkerStack::WithCaptureOptions(aStackCaptureOptions)),
geckoprofiler::markers::TextMarker{},
mozilla::ProfilerString8View(aText, aTextLength));
#endif
}

View File

@ -66,6 +66,12 @@ void gecko_profiler_add_marker_untyped(
mozilla::baseprofiler::ProfilingCategoryPair aCategoryPair,
mozilla::MarkerTiming* aMarkerTiming,
mozilla::StackCaptureOptions aStackCaptureOptions);
void gecko_profiler_add_marker_text(
const char* aName, size_t aNameLength,
mozilla::baseprofiler::ProfilingCategoryPair aCategoryPair,
mozilla::MarkerTiming* aMarkerTiming,
mozilla::StackCaptureOptions aStackCaptureOptions, const char* aText,
size_t aTextLength);
} // extern "C"

View File

@ -40,6 +40,30 @@
//! MarkerOptions { timing: MarkerTiming::instant_now(), ..Default::default() }
//! ```
//!
//! ### Marker with only an additional text for more information:
//!
//! The next and slightly more advanced API is [`add_text_marker`].
//! This is used to add a marker name + a string value for extra information.
//! E.g.:
//!
//! ```
//! let info = "info about this marker";
//! ...
//! gecko_profiler::add_text_marker(
//! // Name of the marker as a string.
//! "Marker Name",
//! // Category with an optional sub-category.
//! gecko_profiler_category!(DOM),
//! // MarkerOptions that keeps options like marker timing and marker stack.
//! MarkerOptions {
//! timing: MarkerTiming::instant_now(),
//! ..Default::default()
//! },
//! // Additional information as a string.
//! info,
//! );
//! ```
//!
//! TODO: Explain the marker API once we have them in the following patches.
pub mod options;
@ -66,3 +90,29 @@ pub fn add_untyped_marker(name: &str, category: ProfilingCategoryPair, mut optio
)
}
}
/// Marker API to add a new marker with additional text for details.
/// Please see the module documentation on how to add a marker with this API.
pub fn add_text_marker(
name: &str,
category: ProfilingCategoryPair,
mut options: MarkerOptions,
text: &str,
) {
if !crate::profiler_state::can_accept_markers() {
// Nothing to do.
return;
}
unsafe {
bindings::gecko_profiler_add_marker_text(
name.as_ptr() as *const c_char,
name.len(),
category.to_cpp_enum_value(),
options.timing.0.as_mut_ptr(),
options.stack,
text.as_ptr() as *const c_char,
text.len(),
)
}
}