use crate::Client;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct PlotName(pub(crate) &'static str);
#[derive(Debug, Hash, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
#[non_exhaustive]
pub enum PlotFormat {
#[default]
Number,
Memory,
Percentage,
Watts,
}
#[derive(Debug, Hash, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
#[non_exhaustive]
pub enum PlotLineStyle {
Stepped,
#[default]
Smooth,
}
#[derive(Clone, PartialEq, Debug)]
pub struct PlotConfiguration {
format: PlotFormat,
line_style: PlotLineStyle,
fill: bool,
color: Option<u32>,
}
impl PlotConfiguration {
pub fn format(mut self, format: PlotFormat) -> Self {
self.format = format;
self
}
pub fn line_style(mut self, line_style: PlotLineStyle) -> Self {
self.line_style = line_style;
self
}
pub fn fill(mut self, fill: bool) -> Self {
self.fill = fill;
self
}
pub fn color(mut self, color: Option<u32>) -> Self {
self.color = color;
self
}
}
impl Default for PlotConfiguration {
fn default() -> Self {
Self {
format: Default::default(),
line_style: Default::default(),
fill: true,
color: None,
}
}
}
impl PlotName {
#[must_use]
pub fn new_leak(name: String) -> Self {
#[cfg(feature = "enable")]
{
let mut name = name;
name.push('\0');
let name = Box::leak(name.into_boxed_str());
Self(name)
}
#[cfg(not(feature = "enable"))]
{
drop(name);
Self("\0")
}
}
}
impl Client {
pub fn plot(&self, plot_name: PlotName, value: f64) {
#[cfg(feature = "enable")]
unsafe {
let () = sys::___tracy_emit_plot(plot_name.0.as_ptr().cast(), value);
}
}
pub fn plot_config(&self, plot_name: PlotName, configuration: PlotConfiguration) {
#[cfg(feature = "enable")]
{
let format = match configuration.format {
PlotFormat::Number => sys::TracyPlotFormatEnum_TracyPlotFormatNumber,
PlotFormat::Memory => sys::TracyPlotFormatEnum_TracyPlotFormatMemory,
PlotFormat::Percentage => sys::TracyPlotFormatEnum_TracyPlotFormatPercentage,
PlotFormat::Watts => sys::TracyPlotFormatEnum_TracyPlotFormatWatt,
} as std::os::raw::c_int;
let stepped = configuration.line_style == PlotLineStyle::Stepped;
let filled = configuration.fill;
let color = configuration.color.unwrap_or(0);
unsafe {
let () = sys::___tracy_emit_plot_config(
plot_name.0.as_ptr().cast(),
format,
stepped.into(),
filled.into(),
color,
);
}
}
}
}
#[macro_export]
macro_rules! plot_name {
($name: expr) => {
unsafe { $crate::internal::create_plot(concat!($name, "\0")) }
};
}
#[macro_export]
macro_rules! plot {
($name: expr, $value: expr) => {{
$crate::Client::running()
.expect("plot! without a running Client")
.plot($crate::plot_name!($name), $value)
}};
}