Log saved modules

This commit is contained in:
Andrzej Janik 2025-09-16 23:09:53 +00:00
commit 0f04a40e92
2 changed files with 87 additions and 81 deletions

View file

@ -303,6 +303,7 @@ pub(crate) enum ErrorEntry {
}, },
NullPointer(&'static str), NullPointer(&'static str),
UnknownLibrary(CUlibrary), UnknownLibrary(CUlibrary),
SavedModule(String),
} }
unsafe impl Send for ErrorEntry {} unsafe impl Send for ErrorEntry {}
@ -344,93 +345,94 @@ impl Display for ErrorEntry {
match self { match self {
ErrorEntry::IoError(e) => e.fmt(f), ErrorEntry::IoError(e) => e.fmt(f),
ErrorEntry::CreatedDumpDirectory(dir) => { ErrorEntry::CreatedDumpDirectory(dir) => {
write!( write!(
f, f,
"Created trace directory {} ", "Created trace directory {} ",
dir.as_os_str().to_string_lossy() dir.as_os_str().to_string_lossy()
) )
} }
ErrorEntry::ErrorBox(e) => e.fmt(f), ErrorEntry::ErrorBox(e) => e.fmt(f),
ErrorEntry::UnsupportedModule { ErrorEntry::UnsupportedModule {
module, module,
raw_image, raw_image,
kind, kind,
} => { } => {
write!( write!(
f, f,
"Unsupported {} module {:?} loaded from module image {:?}", "Unsupported {} module {:?} loaded from module image {:?}",
kind, module, raw_image kind, module, raw_image
) )
} }
ErrorEntry::MalformedModulePath(e) => e.fmt(f), ErrorEntry::MalformedModulePath(e) => e.fmt(f),
ErrorEntry::NonUtf8ModuleText(e) => e.fmt(f), ErrorEntry::NonUtf8ModuleText(e) => e.fmt(f),
ErrorEntry::ModuleParsingError(file_name) => { ErrorEntry::ModuleParsingError(file_name) => {
write!( write!(
f, f,
"Error parsing module, log has been written to {}", "Error parsing module, log has been written to {}",
file_name file_name
) )
} }
ErrorEntry::NulInsideModuleText(e) => e.fmt(f), ErrorEntry::NulInsideModuleText(e) => e.fmt(f),
ErrorEntry::Lz4DecompressionFailure => write!(f, "LZ4 decompression failure"), ErrorEntry::Lz4DecompressionFailure => write!(f, "LZ4 decompression failure"),
ErrorEntry::ZstdDecompressionFailure(err_code) => write!(f, "Zstd decompression failure: {}", zstd_safe::get_error_name(*err_code)), ErrorEntry::ZstdDecompressionFailure(err_code) => write!(f, "Zstd decompression failure: {}", zstd_safe::get_error_name(*err_code)),
ErrorEntry::UnexpectedBinaryField { ErrorEntry::UnexpectedBinaryField {
field_name, field_name,
expected, expected,
observed, observed,
} => write!( } => write!(
f, f,
"Unexpected field {}. Expected one of: [{}], observed: {}", "Unexpected field {}. Expected one of: [{}], observed: {}",
field_name, field_name,
expected expected
.iter() .iter()
.map(|x| x.to_string()) .map(|x| x.to_string())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
observed observed
), ),
ErrorEntry::UnexpectedArgument { ErrorEntry::UnexpectedArgument {
arg_name, arg_name,
expected, expected,
observed, observed,
} => write!( } => write!(
f, f,
"Unexpected argument {}. Expected one of: {{{}}}, observed: {}", "Unexpected argument {}. Expected one of: {{{}}}, observed: {}",
arg_name, arg_name,
expected expected
.iter() .iter()
.map(|x| x.to_string()) .map(|x| x.to_string())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
observed observed
), ),
ErrorEntry::InvalidEnvVar { ErrorEntry::InvalidEnvVar {
var, var,
pattern, pattern,
value, value,
} => write!( } => write!(
f, f,
"Unexpected value of environment variable {var}. Expected pattern: {pattern}, got value: {value}" "Unexpected value of environment variable {var}. Expected pattern: {pattern}, got value: {value}"
), ),
ErrorEntry::FunctionNotFound(cuda_function_name) => write!( ErrorEntry::FunctionNotFound(cuda_function_name) => write!(
f, f,
"No function {cuda_function_name} in the underlying library" "No function {cuda_function_name} in the underlying library"
), ),
ErrorEntry::UnexpectedExportTableSize { expected, computed } => { ErrorEntry::UnexpectedExportTableSize { expected, computed } => {
write!(f, "Table length mismatch. Expected: {expected}, got: {computed}") write!(f, "Table length mismatch. Expected: {expected}, got: {computed}")
} }
ErrorEntry::IntegrityCheck { original, overriden } => { ErrorEntry::IntegrityCheck { original, overriden } => {
write!(f, "Overriding integrity check hash. Original: {original:?}, overriden: {overriden:?}") write!(f, "Overriding integrity check hash. Original: {original:?}, overriden: {overriden:?}")
} }
ErrorEntry::NullPointer(type_) => { ErrorEntry::NullPointer(type_) => {
write!(f, "Null pointer of type {type_} encountered") write!(f, "Null pointer of type {type_} encountered")
} }
ErrorEntry::UnknownLibrary(culibrary) => { ErrorEntry::UnknownLibrary(culibrary) => {
write!(f, "Unknown library: ")?; write!(f, "Unknown library: ")?;
let mut temp_buffer = Vec::new(); let mut temp_buffer = Vec::new();
CudaDisplay::write(culibrary, "", 0, &mut temp_buffer).ok(); CudaDisplay::write(culibrary, "", 0, &mut temp_buffer).ok();
f.write_str(&unsafe { String::from_utf8_unchecked(temp_buffer) }) f.write_str(&unsafe { String::from_utf8_unchecked(temp_buffer) })
} }
ErrorEntry::SavedModule(file) => write!(f, "Saved module to {file}"),
} }
} }
} }

View file

@ -128,12 +128,11 @@ impl StateTracker {
fn_logger: &mut FnCallLog, fn_logger: &mut FnCallLog,
type_: &'static str, type_: &'static str,
) { ) {
fn_logger.log_io_error(self.writer.save_module( fn_logger.try_(|fn_logger| {
self.library_counter, self.writer
index, .save_module(fn_logger, self.library_counter, index, submodule, type_)
submodule, .map_err(ErrorEntry::IoError)
type_, });
));
if type_ == "ptx" { if type_ == "ptx" {
match CString::new(submodule) { match CString::new(submodule) {
Err(e) => fn_logger.log(log::ErrorEntry::NulInsideModuleText(e)), Err(e) => fn_logger.log(log::ErrorEntry::NulInsideModuleText(e)),
@ -323,6 +322,7 @@ impl DumpWriter {
fn save_module( fn save_module(
&self, &self,
fn_logger: &mut FnCallLog,
module_index: usize, module_index: usize,
submodule_index: Option<(usize, Option<usize>)>, submodule_index: Option<(usize, Option<usize>)>,
buffer: &[u8], buffer: &[u8],
@ -332,9 +332,13 @@ impl DumpWriter {
None => return Ok(()), None => return Ok(()),
Some(d) => d.clone(), Some(d) => d.clone(),
}; };
dump_file.push(Self::get_file_name(module_index, submodule_index, kind)); let file_name = Self::get_file_name(module_index, submodule_index, kind);
let mut file = File::create_new(dump_file)?; dump_file.push(&file_name);
file.write_all(buffer)?; {
let mut file = File::create_new(dump_file)?;
file.write_all(buffer)?;
}
fn_logger.log(ErrorEntry::SavedModule(file_name));
Ok(()) Ok(())
} }
@ -349,7 +353,7 @@ impl DumpWriter {
Some(d) => d.clone(), Some(d) => d.clone(),
}; };
log_file.push(Self::get_file_name(module_index, submodule_index, "log")); log_file.push(Self::get_file_name(module_index, submodule_index, "log"));
let mut file = File::create(log_file)?; let mut file = File::create_new(log_file)?;
for error in errors { for error in errors {
writeln!(file, "{}", error)?; writeln!(file, "{}", error)?;
} }