mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1654413 - Add JSONWriter struct for marker schema r=emilio,gerald
JSON writer will be used for the third and last marker API. This is needed because we need to describe a marker payload struct on how to serialize it. Differential Revision: https://phabricator.services.mozilla.com/D124024
This commit is contained in:
parent
978dbc8ab8
commit
c850585eae
@ -111,6 +111,46 @@ void gecko_profiler_destruct_marker_timing(
|
||||
#endif
|
||||
}
|
||||
|
||||
void gecko_profiler_json_writer_int_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, int64_t aValue) {
|
||||
#ifdef MOZ_GECKO_PROFILER
|
||||
aWriter->IntProperty(mozilla::Span(aName, aNameLength), aValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
void gecko_profiler_json_writer_float_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, double aValue) {
|
||||
#ifdef MOZ_GECKO_PROFILER
|
||||
aWriter->DoubleProperty(mozilla::Span(aName, aNameLength), aValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
void gecko_profiler_json_writer_bool_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, bool aValue) {
|
||||
#ifdef MOZ_GECKO_PROFILER
|
||||
aWriter->BoolProperty(mozilla::Span(aName, aNameLength), aValue);
|
||||
#endif
|
||||
}
|
||||
void gecko_profiler_json_writer_string_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, const char* aValue, size_t aValueLength) {
|
||||
#ifdef MOZ_GECKO_PROFILER
|
||||
aWriter->StringProperty(mozilla::Span(aName, aNameLength),
|
||||
mozilla::Span(aValue, aValueLength));
|
||||
#endif
|
||||
}
|
||||
|
||||
void gecko_profiler_json_writer_null_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength) {
|
||||
#ifdef MOZ_GECKO_PROFILER
|
||||
aWriter->NullProperty(mozilla::Span(aName, aNameLength));
|
||||
#endif
|
||||
}
|
||||
|
||||
void gecko_profiler_add_marker_untyped(
|
||||
const char* aName, size_t aNameLength,
|
||||
mozilla::baseprofiler::ProfilingCategoryPair aCategoryPair,
|
||||
|
@ -20,6 +20,7 @@ enum class StackCaptureOptions;
|
||||
|
||||
namespace baseprofiler {
|
||||
enum class ProfilingCategoryPair : uint32_t;
|
||||
class SpliceableJSONWriter;
|
||||
} // namespace baseprofiler
|
||||
|
||||
} // namespace mozilla
|
||||
@ -60,6 +61,23 @@ void gecko_profiler_construct_marker_timing_interval_end(
|
||||
void gecko_profiler_destruct_marker_timing(
|
||||
mozilla::MarkerTiming* aMarkerTiming);
|
||||
|
||||
// Various SpliceableJSONWriter methods to add properties.
|
||||
void gecko_profiler_json_writer_int_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, int64_t aValue);
|
||||
void gecko_profiler_json_writer_float_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, double aValue);
|
||||
void gecko_profiler_json_writer_bool_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, bool aValue);
|
||||
void gecko_profiler_json_writer_string_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength, const char* aValue, size_t aValueLength);
|
||||
void gecko_profiler_json_writer_null_property(
|
||||
mozilla::baseprofiler::SpliceableJSONWriter* aWriter, const char* aName,
|
||||
size_t aNameLength);
|
||||
|
||||
// Marker APIs.
|
||||
void gecko_profiler_add_marker_untyped(
|
||||
const char* aName, size_t aNameLength,
|
||||
|
86
tools/profiler/rust-api/src/json_writer.rs
Normal file
86
tools/profiler/rust-api/src/json_writer.rs
Normal file
@ -0,0 +1,86 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Gecko JSON writer support for marker API.
|
||||
|
||||
use crate::gecko_bindings::{bindings, structs::mozilla};
|
||||
use std::os::raw::c_char;
|
||||
|
||||
/// Wrapper for the C++ SpliceableJSONWriter object. It exposes some methods to
|
||||
/// add various properties to the JSON.
|
||||
#[derive(Debug)]
|
||||
pub struct JSONWriter<'a>(&'a mut mozilla::baseprofiler::SpliceableJSONWriter);
|
||||
|
||||
impl<'a> JSONWriter<'a> {
|
||||
/// Constructor for the JSONWriter object. It takes a C++ SpliceableJSONWriter
|
||||
/// reference as its argument and stores it for later accesses.
|
||||
pub(crate) fn new(json_writer: &'a mut mozilla::baseprofiler::SpliceableJSONWriter) -> Self {
|
||||
JSONWriter(json_writer)
|
||||
}
|
||||
|
||||
/// Adds an int property to the JSON.
|
||||
/// Prints: "<name>": <value>
|
||||
pub fn int_property(&mut self, name: &str, value: i64) {
|
||||
unsafe {
|
||||
bindings::gecko_profiler_json_writer_int_property(
|
||||
self.0,
|
||||
name.as_ptr() as *const c_char,
|
||||
name.len(),
|
||||
value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a float property to the JSON.
|
||||
/// Prints: "<name>": <value>
|
||||
pub fn float_property(&mut self, name: &str, value: f64) {
|
||||
unsafe {
|
||||
bindings::gecko_profiler_json_writer_float_property(
|
||||
self.0,
|
||||
name.as_ptr() as *const c_char,
|
||||
name.len(),
|
||||
value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds an bool property to the JSON.
|
||||
/// Prints: "<name>": <value>
|
||||
pub fn bool_property(&mut self, name: &str, value: bool) {
|
||||
unsafe {
|
||||
bindings::gecko_profiler_json_writer_bool_property(
|
||||
self.0,
|
||||
name.as_ptr() as *const c_char,
|
||||
name.len(),
|
||||
value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a string property to the JSON.
|
||||
/// Prints: "<name>": "<value>"
|
||||
pub fn string_property(&mut self, name: &str, value: &str) {
|
||||
unsafe {
|
||||
bindings::gecko_profiler_json_writer_string_property(
|
||||
self.0,
|
||||
name.as_ptr() as *const c_char,
|
||||
name.len(),
|
||||
value.as_ptr() as *const c_char,
|
||||
value.len(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a null property to the JSON.
|
||||
/// Prints: "<name>": null
|
||||
pub fn null_property(&mut self, name: &str) {
|
||||
unsafe {
|
||||
bindings::gecko_profiler_json_writer_null_property(
|
||||
self.0,
|
||||
name.as_ptr() as *const c_char,
|
||||
name.len(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
|
||||
///! Profiler Rust API
|
||||
pub mod gecko_bindings;
|
||||
mod json_writer;
|
||||
mod label;
|
||||
mod marker;
|
||||
mod profiler_state;
|
||||
@ -11,6 +12,7 @@ mod thread;
|
||||
mod time;
|
||||
|
||||
pub use gecko_bindings::profiling_categories::*;
|
||||
pub use json_writer::*;
|
||||
pub use label::*;
|
||||
pub use marker::options::*;
|
||||
pub use marker::schema::MarkerSchema;
|
||||
|
Loading…
Reference in New Issue
Block a user