1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2024 Melody Madeline Lyons
//
// 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 https://mozilla.org/MPL/2.0/.
use fmod_sys::*;
use std::mem::MaybeUninit;
use crate::studio::{BufferUsage, CpuUsage, MemoryUsage, System};
use crate::{FmodResultExt, Result};
#[cfg(doc)]
use crate::studio::SystemBuilder;
impl System {
/// Retrieves buffer usage information.
///
/// Stall count and time values are cumulative. They can be reset by calling [`System::reset_buffer_usage`].
///
/// Stalls due to the studio command queue overflowing can be avoided by setting a larger command queue size with [`SystemBuilder::settings`].
pub fn get_buffer_usage(&self) -> Result<BufferUsage> {
let mut usage = MaybeUninit::zeroed();
unsafe {
FMOD_Studio_System_GetBufferUsage(self.inner.as_ptr(), usage.as_mut_ptr())
.to_result()?;
let usage = usage.assume_init().into();
Ok(usage)
}
}
/// Resets memory buffer usage statistics.
///
/// This function resets the buffer usage data tracked by the FMOD Studio System.
pub fn reset_buffer_usage(&self) -> Result<()> {
unsafe { FMOD_Studio_System_ResetBufferUsage(self.inner.as_ptr()).to_result() }
}
/// Retrieves the amount of CPU used for different parts of the Studio engine.
///
/// For readability, the percentage values are smoothed to provide a more stable output.
pub fn get_cpu_usage(&self) -> Result<(CpuUsage, crate::CpuUsage)> {
let mut usage = MaybeUninit::zeroed();
let mut usage_core = MaybeUninit::zeroed();
unsafe {
FMOD_Studio_System_GetCPUUsage(
self.inner.as_ptr(),
usage.as_mut_ptr(),
usage_core.as_mut_ptr(),
)
.to_result()?;
let usage = usage.assume_init().into();
let usage_core = usage_core.assume_init().into();
Ok((usage, usage_core))
}
}
/// Retrieves memory usage statistics.
///
/// The memory usage `sample_data` field for the system is the total size of non-streaming sample data currently loaded.
///
/// Memory usage statistics are only available in logging builds, in release builds memoryusage will contain zero for all values after calling this function.
pub fn get_memory_usage(&self) -> Result<MemoryUsage> {
let mut usage = MaybeUninit::zeroed();
unsafe {
FMOD_Studio_System_GetMemoryUsage(self.inner.as_ptr(), usage.as_mut_ptr())
.to_result()?;
let usage = usage.assume_init().into();
Ok(usage)
}
}
}