libdd_profiling/internal/
location.rs

1// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4use super::*;
5
6/// Represents a [pprof::Location] with some space-saving changes:
7///  - The id is not stored on the struct. It's stored in the container that holds the struct.
8///  - ids for linked objects use 32-bit numbers instead of 64 bit ones.
9///  - in libdatadog, we always use 1 Line per Location, so this is directly inlined into the
10///    struct.
11#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
12pub struct Location {
13    pub mapping_id: Option<MappingId>,
14    pub function_id: FunctionId,
15    pub address: u64,
16    pub line: i64,
17}
18
19impl Item for Location {
20    type Id = LocationId;
21}
22
23#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
24#[repr(C)]
25pub struct LocationId(NonZeroU32);
26
27impl Id for LocationId {
28    type RawId = u64;
29
30    fn from_offset(offset: usize) -> Self {
31        #[allow(clippy::expect_used)]
32        Self(small_non_zero_pprof_id(offset).expect("LocationId to fit into a u32"))
33    }
34
35    fn to_raw_id(&self) -> Self::RawId {
36        self.0.get().into()
37    }
38}