Adds a new function that may be sampled in the future. This must be given `code` where it resides and will be executed in the host address space.
(&mut self, name: &str, code: &[u8])
| 107 | /// This must be given `code` where it resides and will be executed in the |
| 108 | /// host address space. |
| 109 | pub fn add_function(&mut self, name: &str, code: &[u8]) -> Result<()> { |
| 110 | self.file.write_all(&[ID_FUNCTION])?; |
| 111 | self.file |
| 112 | .write_all(&u64::try_from(code.as_ptr() as usize)?.to_le_bytes())?; |
| 113 | self.file |
| 114 | .write_all(&u32::try_from(name.len())?.to_le_bytes())?; |
| 115 | self.file.write_all(name.as_bytes())?; |
| 116 | self.file |
| 117 | .write_all(&u32::try_from(code.len())?.to_le_bytes())?; |
| 118 | self.file.write_all(code)?; |
| 119 | Ok(()) |
| 120 | } |
| 121 | |
| 122 | /// Adds a new set of samples to this recorded. |
| 123 | pub fn add_samples(&mut self, samples: &mut Samples) -> Result<()> { |