MCPcopy Index your code
hub / github.com/RustPython/RustPython / stw_trace

Function stw_trace

crates/vm/src/vm/mod.rs:533–572  ·  view source on GitHub ↗
(msg: core::fmt::Arguments<'_>)

Source from the content-addressed store, hash-verified

531
532#[cfg(all(unix, feature = "threading"))]
533pub(super) fn stw_trace(msg: core::fmt::Arguments<'_>) {
534 if stw_trace_enabled() {
535 use core::fmt::Write as _;
536
537 // Avoid stdio locking here: this path runs around fork where a child
538 // may inherit a borrowed stderr lock and panic on eprintln!/stderr.
539 struct FixedBuf {
540 buf: [u8; 512],
541 len: usize,
542 }
543
544 impl core::fmt::Write for FixedBuf {
545 fn write_str(&mut self, s: &str) -> core::fmt::Result {
546 if self.len >= self.buf.len() {
547 return Ok(());
548 }
549 let remain = self.buf.len() - self.len;
550 let src = s.as_bytes();
551 let n = src.len().min(remain);
552 self.buf[self.len..self.len + n].copy_from_slice(&src[..n]);
553 self.len += n;
554 Ok(())
555 }
556 }
557
558 let mut out = FixedBuf {
559 buf: [0u8; 512],
560 len: 0,
561 };
562 let _ = writeln!(
563 &mut out,
564 "[rp-stw tid={}] {}",
565 crate::stdlib::_thread::get_ident(),
566 msg
567 );
568 unsafe {
569 let _ = libc::write(libc::STDERR_FILENO, out.buf.as_ptr().cast(), out.len);
570 }
571 }
572}
573
574#[derive(Clone, Debug, Default)]
575pub(crate) struct CallableCache {

Callers 6

attach_threadFunction · 0.85
detach_threadFunction · 0.85
do_suspendFunction · 0.85
stop_the_worldMethod · 0.85
start_the_worldMethod · 0.85
reset_after_forkMethod · 0.85

Calls 4

stw_trace_enabledFunction · 0.85
writeFunction · 0.50
castMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected