refactor: 迁出日志宏,移除直接依赖
This commit is contained in:
Generated
+4
-3
@@ -1060,6 +1060,7 @@ dependencies = [
|
|||||||
"indexmap",
|
"indexmap",
|
||||||
"memchr",
|
"memchr",
|
||||||
"oxide_kernel",
|
"oxide_kernel",
|
||||||
|
"oxide_log",
|
||||||
"oxide_runtime_api",
|
"oxide_runtime_api",
|
||||||
"oxide_types",
|
"oxide_types",
|
||||||
"regex",
|
"regex",
|
||||||
@@ -1105,6 +1106,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"oxide_bytecode",
|
"oxide_bytecode",
|
||||||
"oxide_code_cache",
|
"oxide_code_cache",
|
||||||
|
"oxide_log",
|
||||||
"oxide_parser",
|
"oxide_parser",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -1120,11 +1122,10 @@ dependencies = [
|
|||||||
"hashbrown 0.14.5",
|
"hashbrown 0.14.5",
|
||||||
"oxide_bytecode",
|
"oxide_bytecode",
|
||||||
"oxide_code_cache",
|
"oxide_code_cache",
|
||||||
|
"oxide_log",
|
||||||
"oxide_parser",
|
"oxide_parser",
|
||||||
"oxide_types",
|
"oxide_types",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"tracing",
|
|
||||||
"tracing-subscriber",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1195,6 +1196,7 @@ dependencies = [
|
|||||||
"oxide_bytecode",
|
"oxide_bytecode",
|
||||||
"oxide_compiler",
|
"oxide_compiler",
|
||||||
"oxide_kernel",
|
"oxide_kernel",
|
||||||
|
"oxide_log",
|
||||||
"oxide_parser",
|
"oxide_parser",
|
||||||
"oxide_runtime_api",
|
"oxide_runtime_api",
|
||||||
"oxide_types",
|
"oxide_types",
|
||||||
@@ -1204,7 +1206,6 @@ dependencies = [
|
|||||||
"ryu",
|
"ryu",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"tracing",
|
|
||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ description = "OxideJS - Generic builtin JS functions parameterized over VmHost"
|
|||||||
oxide_runtime_api = { path = "../oxide_runtime_api" }
|
oxide_runtime_api = { path = "../oxide_runtime_api" }
|
||||||
oxide_types = { path = "../oxide_types" }
|
oxide_types = { path = "../oxide_types" }
|
||||||
oxide_kernel = { path = "../oxide_kernel" }
|
oxide_kernel = { path = "../oxide_kernel" }
|
||||||
|
oxide_log = { path = "../oxide_log" }
|
||||||
fast-float.workspace = true
|
fast-float.workspace = true
|
||||||
ryu.workspace = true
|
ryu.workspace = true
|
||||||
memchr.workspace = true
|
memchr.workspace = true
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! builtins_error {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::builtins", oxide_log::tracing::Level::ERROR, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! builtins_warn {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::builtins", oxide_log::tracing::Level::WARN, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! builtins_info {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::builtins", oxide_log::tracing::Level::INFO, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! builtins_debug {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::builtins", oxide_log::tracing::Level::DEBUG, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! builtins_trace {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::builtins", oxide_log::tracing::Level::TRACE, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod array;
|
pub mod array;
|
||||||
pub mod array_buffer;
|
pub mod array_buffer;
|
||||||
pub mod boolean;
|
pub mod boolean;
|
||||||
|
pub mod builtins_log;
|
||||||
pub mod data_view;
|
pub mod data_view;
|
||||||
pub mod date;
|
pub mod date;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ description = "OxideJS - AST to bytecode compiler"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
oxide_bytecode = { path = "../oxide_bytecode" }
|
oxide_bytecode = { path = "../oxide_bytecode" }
|
||||||
oxide_parser = { path = "../oxide_parser" }
|
oxide_parser = { path = "../oxide_parser" }
|
||||||
|
oxide_log = { path = "../oxide_log" }
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
rustc-hash.workspace = true
|
rustc-hash.workspace = true
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! compiler_error {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::ERROR, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! compiler_warn {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::WARN, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! compiler_info {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::INFO, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! compiler_debug {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::DEBUG, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! compiler_trace {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::TRACE, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#![doc = "OxideJS - AST to bytecode compiler"]
|
#![doc = "OxideJS - AST to bytecode compiler"]
|
||||||
|
|
||||||
pub mod compiler;
|
pub mod compiler;
|
||||||
|
pub mod compiler_log;
|
||||||
pub mod counter;
|
pub mod counter;
|
||||||
pub mod emit_ctx;
|
pub mod emit_ctx;
|
||||||
pub mod emitter;
|
pub mod emitter;
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ oxide_bytecode = { path = "../oxide_bytecode" }
|
|||||||
oxide_code_cache = { path = "../oxide_code_cache" }
|
oxide_code_cache = { path = "../oxide_code_cache" }
|
||||||
oxide_parser = { path = "../oxide_parser" }
|
oxide_parser = { path = "../oxide_parser" }
|
||||||
oxide_types = { path = "../oxide_types" }
|
oxide_types = { path = "../oxide_types" }
|
||||||
dashmap.workspace = true
|
oxide_log = { path = "../oxide_log" }
|
||||||
hashbrown.workspace = true
|
|
||||||
rustc-hash.workspace = true
|
|
||||||
bumpalo.workspace = true
|
bumpalo.workspace = true
|
||||||
tracing.workspace = true
|
hashbrown.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
dashmap.workspace = true
|
||||||
|
rustc-hash.workspace = true
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ use oxide_types::value::JsValue;
|
|||||||
|
|
||||||
use crate::builtin::BuiltinWorld;
|
use crate::builtin::BuiltinWorld;
|
||||||
use crate::code_forge::CodeForge;
|
use crate::code_forge::CodeForge;
|
||||||
use crate::logging::{init_logging, LogLevel, SUBSYSTEM_COUNT};
|
|
||||||
use crate::prop_forge::PropForge;
|
use crate::prop_forge::PropForge;
|
||||||
use crate::shape_forge::{ShapeForge, EMPTY_SHAPE_ID};
|
use crate::shape_forge::{ShapeForge, EMPTY_SHAPE_ID};
|
||||||
use crate::string_forge::PermInterner;
|
use crate::string_forge::PermInterner;
|
||||||
|
use oxide_log;
|
||||||
|
use oxide_log::{Level, SUBSYSTEM_COUNT};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct KernelConfig {
|
pub struct KernelConfig {
|
||||||
@@ -23,7 +24,7 @@ pub struct KernelConfig {
|
|||||||
pub max_call_depth: usize,
|
pub max_call_depth: usize,
|
||||||
pub session_gc_threshold: usize,
|
pub session_gc_threshold: usize,
|
||||||
pub max_cached_modules: usize,
|
pub max_cached_modules: usize,
|
||||||
pub log_levels: [LogLevel; SUBSYSTEM_COUNT],
|
pub log_levels: [Level; SUBSYSTEM_COUNT],
|
||||||
pub warmup_builtin_shapes: bool,
|
pub warmup_builtin_shapes: bool,
|
||||||
pub warmup_builtin_code: bool,
|
pub warmup_builtin_code: bool,
|
||||||
pub warmup_builtin_ic: bool,
|
pub warmup_builtin_ic: bool,
|
||||||
@@ -39,7 +40,7 @@ impl KernelConfig {
|
|||||||
max_call_depth: 1024,
|
max_call_depth: 1024,
|
||||||
session_gc_threshold: 8_388_608,
|
session_gc_threshold: 8_388_608,
|
||||||
max_cached_modules: 512,
|
max_cached_modules: 512,
|
||||||
log_levels: [LogLevel::Off; SUBSYSTEM_COUNT],
|
log_levels: [Level::Off; SUBSYSTEM_COUNT],
|
||||||
warmup_builtin_shapes: true,
|
warmup_builtin_shapes: true,
|
||||||
warmup_builtin_code: false,
|
warmup_builtin_code: false,
|
||||||
warmup_builtin_ic: false,
|
warmup_builtin_ic: false,
|
||||||
@@ -55,7 +56,7 @@ impl KernelConfig {
|
|||||||
max_call_depth: 1024,
|
max_call_depth: 1024,
|
||||||
session_gc_threshold: 8_388_608,
|
session_gc_threshold: 8_388_608,
|
||||||
max_cached_modules: 512,
|
max_cached_modules: 512,
|
||||||
log_levels: [LogLevel::Off; SUBSYSTEM_COUNT],
|
log_levels: [Level::Off; SUBSYSTEM_COUNT],
|
||||||
warmup_builtin_shapes: true,
|
warmup_builtin_shapes: true,
|
||||||
warmup_builtin_code: true,
|
warmup_builtin_code: true,
|
||||||
warmup_builtin_ic: false,
|
warmup_builtin_ic: false,
|
||||||
@@ -71,7 +72,7 @@ impl KernelConfig {
|
|||||||
max_call_depth: 1024,
|
max_call_depth: 1024,
|
||||||
session_gc_threshold: 8_388_608,
|
session_gc_threshold: 8_388_608,
|
||||||
max_cached_modules: 512,
|
max_cached_modules: 512,
|
||||||
log_levels: [LogLevel::Off; SUBSYSTEM_COUNT],
|
log_levels: [Level::Off; SUBSYSTEM_COUNT],
|
||||||
warmup_builtin_shapes: true,
|
warmup_builtin_shapes: true,
|
||||||
warmup_builtin_code: true,
|
warmup_builtin_code: true,
|
||||||
warmup_builtin_ic: true,
|
warmup_builtin_ic: true,
|
||||||
@@ -113,7 +114,10 @@ pub struct KernelCore {
|
|||||||
|
|
||||||
impl KernelCore {
|
impl KernelCore {
|
||||||
pub fn new(config: KernelConfig) -> Arc<Self> {
|
pub fn new(config: KernelConfig) -> Arc<Self> {
|
||||||
init_logging(&config.log_levels);
|
oxide_log::init(&oxide_log::LogConfig {
|
||||||
|
output: oxide_log::Output::Stderr,
|
||||||
|
levels: config.log_levels,
|
||||||
|
});
|
||||||
let perm_interner = Arc::new(PermInterner::new());
|
let perm_interner = Arc::new(PermInterner::new());
|
||||||
let shape_forge = Arc::new(ShapeForge::new());
|
let shape_forge = Arc::new(ShapeForge::new());
|
||||||
let code_forge = Arc::new(CodeForge::new(
|
let code_forge = Arc::new(CodeForge::new(
|
||||||
@@ -603,7 +607,7 @@ mod tests {
|
|||||||
assert_eq!(KernelConfig::minimal().max_steps, None);
|
assert_eq!(KernelConfig::minimal().max_steps, None);
|
||||||
assert_eq!(KernelConfig::standard().max_steps, None);
|
assert_eq!(KernelConfig::standard().max_steps, None);
|
||||||
assert_eq!(KernelConfig::full().max_steps, None);
|
assert_eq!(KernelConfig::full().max_steps, None);
|
||||||
assert_eq!(KernelConfig::minimal().log_levels, [LogLevel::Off; SUBSYSTEM_COUNT]);
|
assert_eq!(KernelConfig::minimal().log_levels, [Level::Off; SUBSYSTEM_COUNT]);
|
||||||
assert!(!KernelConfig::minimal().warmup_builtin_ic);
|
assert!(!KernelConfig::minimal().warmup_builtin_ic);
|
||||||
assert!(KernelConfig::full().warmup_builtin_ic);
|
assert!(KernelConfig::full().warmup_builtin_ic);
|
||||||
assert_eq!(KernelConfig::full().max_pool_size, None);
|
assert_eq!(KernelConfig::full().max_pool_size, None);
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! kernel_error {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::ERROR, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! kernel_warn {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::WARN, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! kernel_info {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::INFO, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! kernel_debug {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::DEBUG, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! kernel_trace {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::kernel", oxide_log::tracing::Level::TRACE, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
pub mod builtin;
|
pub mod builtin;
|
||||||
pub mod code_forge;
|
pub mod code_forge;
|
||||||
pub mod kernel;
|
pub mod kernel;
|
||||||
pub mod logging;
|
pub mod kernel_log;
|
||||||
pub mod prop_forge;
|
pub mod prop_forge;
|
||||||
pub mod shape_forge;
|
pub mod shape_forge;
|
||||||
pub mod string_forge;
|
pub mod string_forge;
|
||||||
|
|||||||
@@ -1,235 +0,0 @@
|
|||||||
use std::sync::atomic::{AtomicU8, Ordering};
|
|
||||||
use std::sync::Once;
|
|
||||||
|
|
||||||
use tracing_subscriber::EnvFilter;
|
|
||||||
|
|
||||||
#[repr(u8)]
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub enum LogLevel {
|
|
||||||
Off = 0,
|
|
||||||
Error = 1,
|
|
||||||
Warn = 2,
|
|
||||||
Info = 3,
|
|
||||||
Debug = 4,
|
|
||||||
Trace = 5,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(usize)]
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub enum Subsystem {
|
|
||||||
Vm = 0,
|
|
||||||
Ic = 1,
|
|
||||||
Kernel = 2,
|
|
||||||
Builtins = 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const SUBSYSTEM_COUNT: usize = 4;
|
|
||||||
|
|
||||||
pub struct SubsystemLevel(AtomicU8);
|
|
||||||
|
|
||||||
impl SubsystemLevel {
|
|
||||||
pub const fn new() -> Self {
|
|
||||||
Self(AtomicU8::new(LogLevel::Off as u8))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set(&self, level: LogLevel) {
|
|
||||||
self.0.store(level as u8, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(&self) -> LogLevel {
|
|
||||||
match self.0.load(Ordering::Relaxed) {
|
|
||||||
1 => LogLevel::Error,
|
|
||||||
2 => LogLevel::Warn,
|
|
||||||
3 => LogLevel::Info,
|
|
||||||
4 => LogLevel::Debug,
|
|
||||||
5 => LogLevel::Trace,
|
|
||||||
_ => LogLevel::Off,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_enabled(&self, level: LogLevel) -> bool {
|
|
||||||
self.0.load(Ordering::Relaxed) >= level as u8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for SubsystemLevel {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub static VM_LEVEL: SubsystemLevel = SubsystemLevel::new();
|
|
||||||
pub static IC_LEVEL: SubsystemLevel = SubsystemLevel::new();
|
|
||||||
pub static KERNEL_LEVEL: SubsystemLevel = SubsystemLevel::new();
|
|
||||||
pub static BUILTINS_LEVEL: SubsystemLevel = SubsystemLevel::new();
|
|
||||||
|
|
||||||
pub fn apply_log_levels(levels: &[LogLevel; SUBSYSTEM_COUNT]) {
|
|
||||||
VM_LEVEL.set(levels[Subsystem::Vm as usize]);
|
|
||||||
IC_LEVEL.set(levels[Subsystem::Ic as usize]);
|
|
||||||
KERNEL_LEVEL.set(levels[Subsystem::Kernel as usize]);
|
|
||||||
BUILTINS_LEVEL.set(levels[Subsystem::Builtins as usize]);
|
|
||||||
apply_env_log_levels();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_logging(log_levels: &[LogLevel; SUBSYSTEM_COUNT]) {
|
|
||||||
static LOGGING_INIT: Once = Once::new();
|
|
||||||
|
|
||||||
LOGGING_INIT.call_once(|| {
|
|
||||||
let filter = EnvFilter::try_from_env("OXIDE_LOG").unwrap_or_else(|_| EnvFilter::new("oxide=off"));
|
|
||||||
let subscriber = tracing_subscriber::fmt()
|
|
||||||
.with_env_filter(filter)
|
|
||||||
.with_writer(std::io::stderr)
|
|
||||||
.with_ansi(false)
|
|
||||||
.without_time()
|
|
||||||
.compact()
|
|
||||||
.finish();
|
|
||||||
let _ = tracing::subscriber::set_global_default(subscriber);
|
|
||||||
});
|
|
||||||
|
|
||||||
apply_log_levels(log_levels);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn apply_env_log_levels() {
|
|
||||||
let Ok(spec) = std::env::var("OXIDE_LOG") else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
for directive in spec.split(',') {
|
|
||||||
let Some((target, level)) = directive.split_once('=') else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let Some(level) = parse_level(level.trim()) else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
match target.trim() {
|
|
||||||
"oxide" => {
|
|
||||||
VM_LEVEL.set(level);
|
|
||||||
IC_LEVEL.set(level);
|
|
||||||
KERNEL_LEVEL.set(level);
|
|
||||||
BUILTINS_LEVEL.set(level);
|
|
||||||
}
|
|
||||||
"oxide::vm" => VM_LEVEL.set(level),
|
|
||||||
"oxide::ic" => IC_LEVEL.set(level),
|
|
||||||
"oxide::kernel" => KERNEL_LEVEL.set(level),
|
|
||||||
"oxide::builtins" => BUILTINS_LEVEL.set(level),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_level(level: &str) -> Option<LogLevel> {
|
|
||||||
if level.eq_ignore_ascii_case("off") {
|
|
||||||
Some(LogLevel::Off)
|
|
||||||
} else if level.eq_ignore_ascii_case("error") {
|
|
||||||
Some(LogLevel::Error)
|
|
||||||
} else if level.eq_ignore_ascii_case("warn") {
|
|
||||||
Some(LogLevel::Warn)
|
|
||||||
} else if level.eq_ignore_ascii_case("info") {
|
|
||||||
Some(LogLevel::Info)
|
|
||||||
} else if level.eq_ignore_ascii_case("debug") {
|
|
||||||
Some(LogLevel::Debug)
|
|
||||||
} else if level.eq_ignore_ascii_case("trace") {
|
|
||||||
Some(LogLevel::Trace)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! vm_debug {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::VM_LEVEL.is_enabled($crate::logging::LogLevel::Debug) {
|
|
||||||
tracing::event!(target: "oxide::vm", tracing::Level::DEBUG, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! vm_trace {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::VM_LEVEL.is_enabled($crate::logging::LogLevel::Trace) {
|
|
||||||
tracing::event!(target: "oxide::vm", tracing::Level::TRACE, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! ic_debug {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::IC_LEVEL.is_enabled($crate::logging::LogLevel::Debug) {
|
|
||||||
tracing::event!(target: "oxide::ic", tracing::Level::DEBUG, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! ic_trace {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::IC_LEVEL.is_enabled($crate::logging::LogLevel::Trace) {
|
|
||||||
tracing::event!(target: "oxide::ic", tracing::Level::TRACE, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! kernel_info {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::KERNEL_LEVEL.is_enabled($crate::logging::LogLevel::Info) {
|
|
||||||
tracing::event!(target: "oxide::kernel", tracing::Level::INFO, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! kernel_debug {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::KERNEL_LEVEL.is_enabled($crate::logging::LogLevel::Debug) {
|
|
||||||
tracing::event!(target: "oxide::kernel", tracing::Level::DEBUG, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! kernel_trace {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::KERNEL_LEVEL.is_enabled($crate::logging::LogLevel::Trace) {
|
|
||||||
tracing::event!(target: "oxide::kernel", tracing::Level::TRACE, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! builtins_debug {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::BUILTINS_LEVEL.is_enabled($crate::logging::LogLevel::Debug) {
|
|
||||||
tracing::event!(target: "oxide::builtins", tracing::Level::DEBUG, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! builtins_trace {
|
|
||||||
($($arg:tt)*) => {
|
|
||||||
if $crate::logging::BUILTINS_LEVEL.is_enabled($crate::logging::LogLevel::Trace) {
|
|
||||||
tracing::event!(target: "oxide::builtins", tracing::Level::TRACE, $($arg)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::{LogLevel, SubsystemLevel};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn log_level_ordinals_match_gate_contract() {
|
|
||||||
assert_eq!(LogLevel::Off as u8, 0);
|
|
||||||
assert_eq!(LogLevel::Trace as u8, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn subsystem_level_defaults_off() {
|
|
||||||
let level = SubsystemLevel::new();
|
|
||||||
assert_eq!(level.get(), LogLevel::Off);
|
|
||||||
assert!(!level.is_enabled(LogLevel::Error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,12 +15,7 @@ pub struct SubsystemFilter {
|
|||||||
impl SubsystemFilter {
|
impl SubsystemFilter {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
levels: Arc::new([
|
levels: Arc::new([AtomicU8::new(0), AtomicU8::new(0), AtomicU8::new(0), AtomicU8::new(0)]),
|
||||||
AtomicU8::new(0),
|
|
||||||
AtomicU8::new(0),
|
|
||||||
AtomicU8::new(0),
|
|
||||||
AtomicU8::new(0),
|
|
||||||
]),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,11 +58,7 @@ impl Default for SubsystemFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Subscriber> Filter<S> for SubsystemFilter {
|
impl<S: Subscriber> Filter<S> for SubsystemFilter {
|
||||||
fn enabled(
|
fn enabled(&self, meta: &tracing::Metadata<'_>, _cx: &tracing_subscriber::layer::Context<'_, S>) -> bool {
|
||||||
&self,
|
|
||||||
meta: &tracing::Metadata<'_>,
|
|
||||||
_cx: &tracing_subscriber::layer::Context<'_, S>,
|
|
||||||
) -> bool {
|
|
||||||
self.is_enabled_for(meta.target(), meta.level())
|
self.is_enabled_for(meta.target(), meta.level())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ pub enum Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Level {
|
impl Level {
|
||||||
pub fn as_tracing_level(self) -> tracing::Level {
|
pub const fn as_tracing_level(self) -> tracing::Level {
|
||||||
match self {
|
match self {
|
||||||
Level::Off | Level::Error => tracing::Level::ERROR,
|
Level::Off | Level::Error => tracing::Level::ERROR,
|
||||||
Level::Warn => tracing::Level::WARN,
|
Level::Warn => tracing::Level::WARN,
|
||||||
|
|||||||
@@ -8,3 +8,6 @@ pub use filter::SubsystemFilter;
|
|||||||
pub use init::{init, set_level, LogConfig, Output};
|
pub use init::{init, set_level, LogConfig, Output};
|
||||||
pub use level::Level;
|
pub use level::Level;
|
||||||
pub use subsystem::{SubsystemId, SUBSYSTEM_COUNT};
|
pub use subsystem::{SubsystemId, SUBSYSTEM_COUNT};
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub use tracing;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! __log_event {
|
macro_rules! __log_event {
|
||||||
($target:expr, $level:expr, $($arg:tt)*) => {
|
($target:expr, $level:expr, $($arg:tt)*) => {
|
||||||
tracing::event!(target: $target, $level, $($arg)*)
|
$crate::tracing::event!(target: $target, $level, $($arg)*)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ oxide_kernel = { path = "../oxide_kernel" }
|
|||||||
oxide_runtime_api = { path = "../oxide_runtime_api" }
|
oxide_runtime_api = { path = "../oxide_runtime_api" }
|
||||||
oxide_builtins = { path = "../oxide_builtins" }
|
oxide_builtins = { path = "../oxide_builtins" }
|
||||||
oxide_types = { path = "../oxide_types" }
|
oxide_types = { path = "../oxide_types" }
|
||||||
|
oxide_log = { path = "../oxide_log" }
|
||||||
bumpalo.workspace = true
|
bumpalo.workspace = true
|
||||||
fast-float.workspace = true
|
fast-float.workspace = true
|
||||||
ryu.workspace = true
|
ryu.workspace = true
|
||||||
@@ -22,7 +23,6 @@ chrono.workspace = true
|
|||||||
indexmap.workspace = true
|
indexmap.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
unicode-normalization.workspace = true
|
unicode-normalization.workspace = true
|
||||||
tracing.workspace = true
|
|
||||||
rustc-hash.workspace = true
|
rustc-hash.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::native::NativeFn;
|
use crate::native::NativeFn;
|
||||||
use crate::vm::{native_fn_ptr_to_fn, CallFrame, FrameContinuation, Vm};
|
use crate::vm::{native_fn_ptr_to_fn, CallFrame, FrameContinuation, Vm};
|
||||||
|
use oxide_builtins::{builtins_debug, builtins_trace};
|
||||||
use oxide_bytecode::opcode;
|
use oxide_bytecode::opcode;
|
||||||
use oxide_kernel::{builtins_debug, builtins_trace};
|
|
||||||
use oxide_runtime_api::NativeResult;
|
use oxide_runtime_api::NativeResult;
|
||||||
use oxide_types::object::JsObject;
|
use oxide_types::object::JsObject;
|
||||||
use oxide_types::value::JsValue;
|
use oxide_types::value::JsValue;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
use crate::{ic_debug, ic_trace};
|
||||||
use oxide_bytecode::opcode::OpCode;
|
use oxide_bytecode::opcode::OpCode;
|
||||||
use oxide_kernel::prop_forge::PropTemplate;
|
use oxide_kernel::prop_forge::PropTemplate;
|
||||||
use oxide_kernel::{ic_debug, ic_trace};
|
|
||||||
use oxide_types::object::JsObject;
|
use oxide_types::object::JsObject;
|
||||||
use oxide_types::private_key::make_private_name_id;
|
use oxide_types::private_key::make_private_name_id;
|
||||||
use oxide_types::value::JsValue;
|
use oxide_types::value::JsValue;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ pub mod session_gc;
|
|||||||
pub mod vm;
|
pub mod vm;
|
||||||
mod vm_dispatch_ctrl;
|
mod vm_dispatch_ctrl;
|
||||||
mod vm_dispatch_misc;
|
mod vm_dispatch_misc;
|
||||||
|
pub mod vm_log;
|
||||||
pub mod vm_pool;
|
pub mod vm_pool;
|
||||||
mod vm_props;
|
mod vm_props;
|
||||||
mod vm_runtime;
|
mod vm_runtime;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
|
|||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use oxide_kernel::vm_debug;
|
use crate::vm_debug;
|
||||||
use oxide_types::object::{JsObject, JsString, PropMetaEntry};
|
use oxide_types::object::{JsObject, JsString, PropMetaEntry};
|
||||||
use oxide_types::value::JsValue;
|
use oxide_types::value::JsValue;
|
||||||
use rustc_hash::FxBuildHasher;
|
use rustc_hash::FxBuildHasher;
|
||||||
|
|||||||
@@ -23,13 +23,7 @@ impl Vm {
|
|||||||
let ext = self.bytecode[self.pc];
|
let ext = self.bytecode[self.pc];
|
||||||
self.pc += 1;
|
self.pc += 1;
|
||||||
let arg_count = (ext & 0xFF) as usize;
|
let arg_count = (ext & 0xFF) as usize;
|
||||||
oxide_kernel::vm_debug!(
|
crate::vm_debug!("CALL rd={} this={} args={} depth={}", rd, this_reg, arg_count, self.frames.len());
|
||||||
"CALL rd={} this={} args={} depth={}",
|
|
||||||
rd,
|
|
||||||
this_reg,
|
|
||||||
arg_count,
|
|
||||||
self.frames.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
if obj.native_fn().is_some() {
|
if obj.native_fn().is_some() {
|
||||||
self.dispatch_native_call(obj, callee, this_reg, first_arg_reg, arg_count)?;
|
self.dispatch_native_call(obj, callee, this_reg, first_arg_reg, arg_count)?;
|
||||||
@@ -77,7 +71,7 @@ impl Vm {
|
|||||||
let ext = self.bytecode[self.pc];
|
let ext = self.bytecode[self.pc];
|
||||||
self.pc += 1;
|
self.pc += 1;
|
||||||
let arg_count = (ext & 0xFF) as usize;
|
let arg_count = (ext & 0xFF) as usize;
|
||||||
oxide_kernel::vm_debug!("CALL_NATIVE rd={} args={}", rd, arg_count);
|
crate::vm_debug!("CALL_NATIVE rd={} args={}", rd, arg_count);
|
||||||
self.dispatch_native_call(obj, callee, this_reg, first_arg_reg, arg_count)
|
self.dispatch_native_call(obj, callee, this_reg, first_arg_reg, arg_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +109,7 @@ impl Vm {
|
|||||||
|
|
||||||
pub(crate) fn dispatch_return(&mut self, rd: usize) -> Result<Option<JsValue>, String> {
|
pub(crate) fn dispatch_return(&mut self, rd: usize) -> Result<Option<JsValue>, String> {
|
||||||
let result = self.regs[rd];
|
let result = self.regs[rd];
|
||||||
oxide_kernel::vm_debug!("RETURN depth={}", self.frames.len());
|
crate::vm_debug!("RETURN depth={}", self.frames.len());
|
||||||
if let Some(frame) = self.frames.pop() {
|
if let Some(frame) = self.frames.pop() {
|
||||||
let construct_result_reg = frame.construct_result_reg;
|
let construct_result_reg = frame.construct_result_reg;
|
||||||
let constructed_this = frame.constructed_this;
|
let constructed_this = frame.constructed_this;
|
||||||
@@ -144,7 +138,7 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn dispatch_throw(&mut self, rd: usize) -> Result<bool, String> {
|
pub(crate) fn dispatch_throw(&mut self, rd: usize) -> Result<bool, String> {
|
||||||
oxide_kernel::vm_debug!("THROW pc={}", self.pc);
|
crate::vm_debug!("THROW pc={}", self.pc);
|
||||||
let exc_value = self.regs[rd];
|
let exc_value = self.regs[rd];
|
||||||
self.exception_value = Some(exc_value);
|
self.exception_value = Some(exc_value);
|
||||||
self.pending_error_kind = Some(self.thrown_error_kind(exc_value));
|
self.pending_error_kind = Some(self.thrown_error_kind(exc_value));
|
||||||
@@ -152,7 +146,7 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn dispatch_try_begin(&mut self, instr: u32) {
|
pub(crate) fn dispatch_try_begin(&mut self, instr: u32) {
|
||||||
oxide_kernel::vm_trace!("TRY_BEGIN frame_depth={}", self.frames.len());
|
crate::vm_trace!("TRY_BEGIN frame_depth={}", self.frames.len());
|
||||||
let offset = opcode::offset16(instr) as isize;
|
let offset = opcode::offset16(instr) as isize;
|
||||||
let catch_pc = if offset == 0 {
|
let catch_pc = if offset == 0 {
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use crate::native::NativeFn;
|
use crate::native::NativeFn;
|
||||||
use crate::vm::{native_fn_ptr_to_fn, CallFrame, ForInIter, FrameContinuation, Vm, MAX_PROTO_CHAIN_DEPTH};
|
use crate::vm::{native_fn_ptr_to_fn, CallFrame, ForInIter, FrameContinuation, Vm, MAX_PROTO_CHAIN_DEPTH};
|
||||||
|
use crate::vm_debug;
|
||||||
use oxide_runtime_api::{to_boolean, NativeResult};
|
use oxide_runtime_api::{to_boolean, NativeResult};
|
||||||
use oxide_types::object::{JsObject, PropAttributes};
|
use oxide_types::object::{JsObject, PropAttributes};
|
||||||
use oxide_types::private_key::is_private_name_key;
|
use oxide_types::private_key::is_private_name_key;
|
||||||
@@ -11,7 +12,7 @@ impl Vm {
|
|||||||
pub(crate) fn dispatch_new_expression(&mut self, rd: usize, a: usize, b: usize) -> Result<bool, String> {
|
pub(crate) fn dispatch_new_expression(&mut self, rd: usize, a: usize, b: usize) -> Result<bool, String> {
|
||||||
let constructor_reg = a;
|
let constructor_reg = a;
|
||||||
let first_arg_reg = b as u8;
|
let first_arg_reg = b as u8;
|
||||||
oxide_kernel::vm_debug!("NEW_EXPRESSION rd={}", rd);
|
vm_debug!("NEW_EXPRESSION rd={}", rd);
|
||||||
|
|
||||||
let constructor = self.regs[constructor_reg];
|
let constructor = self.regs[constructor_reg];
|
||||||
if !constructor.is_object() {
|
if !constructor.is_object() {
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! vm_error {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::vm", oxide_log::tracing::Level::ERROR, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! vm_warn {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::vm", oxide_log::tracing::Level::WARN, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! vm_info {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::vm", oxide_log::tracing::Level::INFO, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! vm_debug {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::vm", oxide_log::tracing::Level::DEBUG, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! vm_trace {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::vm", oxide_log::tracing::Level::TRACE, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ic_error {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::ic", oxide_log::tracing::Level::ERROR, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ic_warn {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::ic", oxide_log::tracing::Level::WARN, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ic_info {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::ic", oxide_log::tracing::Level::INFO, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ic_debug {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::ic", oxide_log::tracing::Level::DEBUG, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ic_trace {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
oxide_log::__log_event!("oxide::ic", oxide_log::tracing::Level::TRACE, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user