mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-22 21:41:37 +00:00
feat: add asynchronous log compression with thread priority adjustment
Implemented asynchronous log compression in the logging initialization process. A new function, `lower_thread_priority`, adjusts the thread priority to below normal for the compression task, improving overall application performance during logging operations.
This commit is contained in:
parent
c3af985026
commit
b1e2bee52a
1 changed files with 25 additions and 1 deletions
|
|
@ -92,7 +92,11 @@ pub fn init_logging(
|
||||||
|
|
||||||
match std::fs::create_dir_all(&log_dir) {
|
match std::fs::create_dir_all(&log_dir) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
compress_old_logs(&log_dir);
|
let compress_dir = log_dir.clone();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
lower_thread_priority();
|
||||||
|
compress_old_logs(&compress_dir);
|
||||||
|
});
|
||||||
|
|
||||||
let log_filename = session_log_filename(command_name);
|
let log_filename = session_log_filename(command_name);
|
||||||
let log_path = log_dir.join(&log_filename);
|
let log_path = log_dir.join(&log_filename);
|
||||||
|
|
@ -152,6 +156,26 @@ pub fn init_logging(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lower_thread_priority() {
|
||||||
|
#[cfg(windows)]
|
||||||
|
unsafe {
|
||||||
|
extern "system" {
|
||||||
|
fn GetCurrentThread() -> isize;
|
||||||
|
fn SetThreadPriority(handle: isize, priority: i32) -> i32;
|
||||||
|
}
|
||||||
|
const THREAD_PRIORITY_BELOW_NORMAL: i32 = -1;
|
||||||
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
unsafe {
|
||||||
|
extern "C" {
|
||||||
|
fn nice(inc: i32) -> i32;
|
||||||
|
}
|
||||||
|
nice(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn compress_old_logs(log_dir: &Path) {
|
fn compress_old_logs(log_dir: &Path) {
|
||||||
let now_secs = std::time::SystemTime::now()
|
let now_secs = std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue