fmod/studio/event_instance/profiling.rs
1// Copyright (c) 2024 Melody Madeline Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use std::{ffi::c_uint, mem::MaybeUninit};
8
9use fmod_sys::*;
10
11use crate::studio::{EventInstance, MemoryUsage};
12use crate::{FmodResultExt, Result};
13
14impl EventInstance {
15 /// Retrieves the event CPU usage data.
16 ///
17 /// [`crate::InitFlags::PROFILE_ENABLE`] with [`crate::SystemBuilder::build`] is required to call this function.
18 pub fn get_cpu_usage(&self) -> Result<(c_uint, c_uint)> {
19 let mut exclusive = 0;
20 let mut inclusive = 0;
21 unsafe {
22 FMOD_Studio_EventInstance_GetCPUUsage(
23 self.inner.as_ptr(),
24 &raw mut exclusive,
25 &raw mut inclusive,
26 )
27 .to_result()?;
28 }
29 Ok((exclusive, inclusive))
30 }
31
32 /// Retrieves memory usage statistics.
33 ///
34 /// Memory usage statistics are only available in logging builds, in release builds the return value will contain zero for all values this function.
35 pub fn get_memory_usage(&self) -> Result<MemoryUsage> {
36 let mut memory_usage = MaybeUninit::zeroed();
37 unsafe {
38 FMOD_Studio_EventInstance_GetMemoryUsage(
39 self.inner.as_ptr(),
40 memory_usage.as_mut_ptr(),
41 )
42 .to_result()?;
43
44 let memory_usage = memory_usage.assume_init().into();
45 Ok(memory_usage)
46 }
47 }
48}