MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / maybe_write_file_header

Method maybe_write_file_header

crates/jit-debug/src/perf_jitdump.rs:244–270  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

242 }
243
244 fn maybe_write_file_header(&self) -> io::Result<()> {
245 let header = FileHeader {
246 timestamp: self.get_time_stamp(),
247 e_machine: self.e_machine,
248 magic: 0x4A695444,
249 version: 1,
250 size: mem::size_of::<FileHeader>() as u32,
251 pad1: 0,
252 pid: process::id(),
253 flags: 0,
254 };
255
256 // If it looks like some other engine in the same process has opened the
257 // file and added data already then assume that they were the ones to
258 // add the file header. If it's empty, though, assume we're the ones to
259 // add the file header.
260 //
261 // This is subject to a TOCTOU-style race condition but there's not
262 // really anything we can do about that. That'd require higher-level
263 // coordination in the application to boot up profiling agents serially
264 // or something like that. Either that or a better dump format where we
265 // can place output in our own engine-specific file. Alas.
266 if self.jitdump_file.metadata()?.len() == 0 {
267 self.maybe_atomic_write_all(object::bytes_of(&header))?;
268 }
269 Ok(())
270 }
271
272 /// Get raw access to the underlying file that is being written to.
273 pub fn file(&self) -> &File {

Callers 1

newMethod · 0.80

Calls 5

OkFunction · 0.85
get_time_stampMethod · 0.80
metadataMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected