зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1733335 - Add tracing marker type for the Rust side r=gerald
Differential Revision: https://phabricator.services.mozilla.com/D127112
This commit is contained in:
Родитель
142d00a761
Коммит
146befbbdb
|
@ -148,6 +148,8 @@ struct TextMarker {
|
|||
}
|
||||
};
|
||||
|
||||
// Keep this struct in sync with the `gecko_profiler::marker::Tracing` Rust
|
||||
// counterpart.
|
||||
struct Tracing {
|
||||
static constexpr Span<const char> MarkerTypeName() {
|
||||
return MakeStringSpan("tracing");
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "GeckoProfiler.h"
|
||||
|
||||
#include <set>
|
||||
#include <type_traits>
|
||||
|
||||
void gecko_profiler_register_thread(const char* aName) {
|
||||
|
@ -233,9 +234,18 @@ void gecko_profiler_marker_schema_add_static_label_value(
|
|||
|
||||
void gecko_profiler_marker_schema_stream(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, mozilla::MarkerSchema* aMarkerSchema) {
|
||||
size_t aNameLength, mozilla::MarkerSchema* aMarkerSchema,
|
||||
void* aStreamedNamesSet) {
|
||||
#ifdef MOZ_GECKO_PROFILER
|
||||
std::move(*aMarkerSchema).Stream(*aWriter, mozilla::Span(aName, aNameLength));
|
||||
auto* streamedNames = static_cast<std::set<std::string>*>(aStreamedNamesSet);
|
||||
// std::set.insert(T&&) returns a pair, its `second` is true if the element
|
||||
// was actually inserted (i.e., it was not there yet.).
|
||||
const bool didInsert =
|
||||
streamedNames->insert(std::string(aName, aNameLength)).second;
|
||||
if (didInsert) {
|
||||
std::move(*aMarkerSchema)
|
||||
.Stream(*aWriter, mozilla::Span(aName, aNameLength));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -2476,8 +2476,11 @@ static void StreamMarkerSchema(SpliceableJSONWriter& aWriter) {
|
|||
}
|
||||
}
|
||||
|
||||
// Now stream the Rust marker schemas.
|
||||
profiler::ffi::gecko_profiler_stream_marker_schemas(&aWriter);
|
||||
// Now stream the Rust marker schemas. Passing the names set as a void pointer
|
||||
// as well, so we can continue checking if the schemes are added already in
|
||||
// the Rust side.
|
||||
profiler::ffi::gecko_profiler_stream_marker_schemas(
|
||||
&aWriter, static_cast<void*>(&names));
|
||||
}
|
||||
|
||||
// Some meta information that is better recorded before streaming the profile.
|
||||
|
|
|
@ -118,7 +118,8 @@ void gecko_profiler_marker_schema_add_static_label_value(
|
|||
// Stream MarkerSchema to SpliceableJSONWriter.
|
||||
void gecko_profiler_marker_schema_stream(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, mozilla::MarkerSchema* aMarkerSchema);
|
||||
size_t aNameLength, mozilla::MarkerSchema* aMarkerSchema,
|
||||
void* aStreamedNamesSet);
|
||||
|
||||
// Various SpliceableJSONWriter methods to add properties.
|
||||
void gecko_profiler_json_writer_int_property(
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::marker::deserializer_tags_state::{
|
|||
get_marker_type_functions_read_guard, MarkerTypeFunctions,
|
||||
};
|
||||
use std::ops::DerefMut;
|
||||
use std::os::raw::c_char;
|
||||
use std::os::raw::{c_char, c_void};
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn gecko_profiler_serialize_marker_for_tag(
|
||||
|
@ -34,6 +34,7 @@ pub unsafe extern "C" fn gecko_profiler_serialize_marker_for_tag(
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn gecko_profiler_stream_marker_schemas(
|
||||
json_writer: &mut mozilla::baseprofiler::SpliceableJSONWriter,
|
||||
streamed_names_set: *mut c_void,
|
||||
) {
|
||||
let marker_type_functions = get_marker_type_functions_read_guard();
|
||||
|
||||
|
@ -46,6 +47,7 @@ pub unsafe extern "C" fn gecko_profiler_stream_marker_schemas(
|
|||
marker_name.as_ptr() as *const c_char,
|
||||
marker_name.len(),
|
||||
marker_schema.pin.deref_mut().as_mut_ptr(),
|
||||
streamed_names_set,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
//! "marker type from rust"
|
||||
//! }
|
||||
//! fn marker_type_display() -> gecko_profiler::MarkerSchema {
|
||||
//! use gecko_profiler::schema::*;
|
||||
//! use gecko_profiler::marker::schema::*;
|
||||
//! let mut schema = MarkerSchema::new(&[Location::MarkerChart]);
|
||||
//! schema.set_chart_label("Name: {marker.name}");
|
||||
//! schema.set_tooltip_label("{marker.data.a}");
|
||||
|
@ -121,11 +121,14 @@ pub(crate) mod deserializer_tags_state;
|
|||
pub mod options;
|
||||
pub mod schema;
|
||||
|
||||
pub use options::*;
|
||||
pub use schema::MarkerSchema;
|
||||
|
||||
use crate::gecko_bindings::{bindings, profiling_categories::ProfilingCategoryPair};
|
||||
use crate::json_writer::JSONWriter;
|
||||
use crate::marker::deserializer_tags_state::get_or_insert_deserializer_tag;
|
||||
use crate::marker::options::MarkerOptions;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use std::os::raw::c_char;
|
||||
|
||||
/// Marker API to add a new simple marker without any payload.
|
||||
|
@ -246,3 +249,36 @@ pub fn add_marker<T>(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Tracing marker type for Rust code.
|
||||
/// This must be kept in sync with the `mozilla::baseprofiler::markers::Tracing`
|
||||
/// C++ counterpart.
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Tracing(pub String);
|
||||
|
||||
impl ProfilerMarker for Tracing {
|
||||
fn marker_type_name() -> &'static str {
|
||||
"tracing"
|
||||
}
|
||||
|
||||
fn stream_json_marker_data(&self, json_writer: &mut JSONWriter) {
|
||||
if self.0.len() != 0 {
|
||||
json_writer.string_property("category", &self.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Tracing marker is a bit special because we have the same schema in the
|
||||
// C++ side. This function will only get called when no Tracing markers are
|
||||
// generated from the C++ side. But, most of the time, this will not be called
|
||||
// when there is another C++ Tracing marker.
|
||||
fn marker_type_display() -> schema::MarkerSchema {
|
||||
use crate::marker::schema::*;
|
||||
let mut schema = MarkerSchema::new(&[
|
||||
Location::MarkerChart,
|
||||
Location::MarkerTable,
|
||||
Location::TimelineOverview,
|
||||
]);
|
||||
schema.add_key_label_format("category", "Type", Format::String);
|
||||
schema
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче