| 674 | } |
| 675 | |
| 676 | fn capture_stack(&self) -> StackKey { |
| 677 | let mut key = StackKey::default(); |
| 678 | let mut index = 0_usize; |
| 679 | let mut skip = self.stack_skip; |
| 680 | let max_depth = self.max_stack_depth.min(MAX_STACK_DEPTH); |
| 681 | // SAFETY: trace_unsynchronized is safe for sampling the current |
| 682 | // thread's stack as long as we avoid concurrent symbolization here. |
| 683 | unsafe { |
| 684 | trace_unsynchronized(|frame| { |
| 685 | let ip = frame.ip() as usize; |
| 686 | if ip == 0 { |
| 687 | return true; |
| 688 | } |
| 689 | if skip > 0 { |
| 690 | skip -= 1; |
| 691 | return true; |
| 692 | } |
| 693 | if index >= max_depth { |
| 694 | return false; |
| 695 | } |
| 696 | key.frames[index] = ip; |
| 697 | index += 1; |
| 698 | true |
| 699 | }); |
| 700 | } |
| 701 | key.len = index as u8; |
| 702 | key |
| 703 | } |
| 704 | |
| 705 | fn resolve_symbol(&self, addr: usize) -> String { |
| 706 | if let Some(existing) = self.symbols.get(&addr) { |