1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 use crate::gecko_bindings::{bindings, structs::mozilla};
6 use crate::json_writer::JSONWriter;
7 use crate::marker::deserializer_tags_state::{
8     get_marker_type_functions_read_guard, MarkerTypeFunctions,
9 };
10 use std::ops::DerefMut;
11 use std::os::raw::{c_char, c_void};
12 
13 #[no_mangle]
gecko_profiler_serialize_marker_for_tag( deserializer_tag: u8, payload: *const u8, payload_size: usize, json_writer: &mut mozilla::baseprofiler::SpliceableJSONWriter, )14 pub unsafe extern "C" fn gecko_profiler_serialize_marker_for_tag(
15     deserializer_tag: u8,
16     payload: *const u8,
17     payload_size: usize,
18     json_writer: &mut mozilla::baseprofiler::SpliceableJSONWriter,
19 ) {
20     let marker_type_functions = get_marker_type_functions_read_guard();
21     let &MarkerTypeFunctions {
22         transmute_and_stream_fn,
23         marker_type_name_fn,
24         ..
25     } = marker_type_functions.get(deserializer_tag);
26     let mut json_writer = JSONWriter::new(&mut *json_writer);
27 
28     // Serialize the marker type name first.
29     json_writer.string_property("type", marker_type_name_fn());
30     // Serialize the marker payload now.
31     transmute_and_stream_fn(payload, payload_size, &mut json_writer);
32 }
33 
34 #[no_mangle]
gecko_profiler_stream_marker_schemas( json_writer: &mut mozilla::baseprofiler::SpliceableJSONWriter, streamed_names_set: *mut c_void, )35 pub unsafe extern "C" fn gecko_profiler_stream_marker_schemas(
36     json_writer: &mut mozilla::baseprofiler::SpliceableJSONWriter,
37     streamed_names_set: *mut c_void,
38 ) {
39     let marker_type_functions = get_marker_type_functions_read_guard();
40 
41     for funcs in marker_type_functions.iter() {
42         let marker_name = (funcs.marker_type_name_fn)();
43         let mut marker_schema = (funcs.marker_type_display_fn)();
44 
45         bindings::gecko_profiler_marker_schema_stream(
46             json_writer,
47             marker_name.as_ptr() as *const c_char,
48             marker_name.len(),
49             marker_schema.pin.deref_mut().as_mut_ptr(),
50             streamed_names_set,
51         )
52     }
53 }
54