luaur_repl_cli/functions/
profiler_start.rs1use core::sync::atomic::Ordering;
4use std::thread;
5
6use luaur_vm::functions::lua_callbacks::lua_callbacks;
7use luaur_vm::records::lua_state::lua_State;
8
9use crate::functions::profiler_loop::profiler_loop;
10use crate::functions::profiler_trigger::G_PROFILER;
11
12pub fn profiler_start(l: *mut lua_State, frequency: i32) {
13 unsafe {
14 let profiler = core::ptr::addr_of_mut!(G_PROFILER).as_mut().unwrap();
15
16 profiler.frequency = frequency;
17 profiler.callbacks = lua_callbacks(l);
18
19 profiler.exit.store(false, Ordering::Relaxed);
20 profiler.thread = Some(thread::spawn(profiler_loop));
21 }
22}