linux_perf_data/
error.rs

1use std::io;
2
3/// The error type used in this crate.
4#[derive(thiserror::Error, Debug)]
5#[non_exhaustive]
6pub enum Error {
7    /// The data slice was not big enough to read the struct, or we
8    /// were trying to follow an invalid offset to somewhere outside
9    /// of the data bounds.
10    #[error("Read error: {0}")]
11    Read(#[from] ReadError),
12
13    #[error("I/O error: {0}")]
14    IoError(#[from] io::Error),
15
16    #[error("Did not recognize magic value {0:?}")]
17    UnrecognizedMagicValue([u8; 8]),
18
19    #[error("Section size did not fit into usize")]
20    SectionSizeTooBig,
21
22    #[error("The file declares no perf event attributes, so samples cannot be parsed")]
23    NoAttributes,
24
25    #[error("Inconsistent attribute sizes: The self-reported size in the attribute was {0} bytes, which is larger than the the attribute size specified in the file header ({1} bytes)")]
26    InconsistentAttributeSizes(u64, u64),
27
28    #[error("The file contains multiple events but attr {0} does not specify IDENTIFIER")]
29    NoIdentifierDespiteMultiEvent(usize),
30
31    #[error("The file contains multiple events but attr {0} does not agree with attr zero about SAMPLE_ID_ALL")]
32    InconsistentSampleIdAllWithMultiEvent(usize),
33
34    #[error("The section wasn't big enough to contain the u32 string length")]
35    NotEnoughSpaceForStringLen,
36
37    #[error("The section wasn't big enough to contain the u32 string list length")]
38    NotEnoughSpaceForStringListLen,
39
40    #[error("The feature section wasn't big enough")]
41    FeatureSectionTooSmall,
42
43    #[error("No event types found in the simpleperf meta info section")]
44    NoEventTypesInSimpleperfMetaInfo,
45
46    #[error("Protobuf parsing error in Simpleperf file feature: {0}")]
47    ProtobufParsingSimpleperfFileSection(prost::DecodeError),
48
49    #[error("Parsing error in Simpleperf file v1 feature: {0}")]
50    ParsingSimpleperfFileV1Section(io::Error),
51
52    #[error("The indicated string length wouldn't fit in the indicated section size")]
53    StringLengthTooLong,
54
55    #[error("The indicated string list length wouldn't fit into usize")]
56    StringListLengthBiggerThanUsize,
57
58    #[error("The indicated string length wouldn't fit into usize")]
59    StringLengthBiggerThanUsize,
60
61    #[error("The string was not valid utf-8")]
62    StringUtf8,
63
64    #[error("The specified size in the perf event header was smaller than the header itself")]
65    InvalidPerfEventSize,
66}
67
68impl From<std::str::Utf8Error> for Error {
69    fn from(_: std::str::Utf8Error) -> Self {
70        Error::StringUtf8
71    }
72}
73
74/// This error indicates that the data slice was not large enough to
75/// read the respective item.
76#[derive(thiserror::Error, Debug, Clone, Copy, PartialEq, Eq)]
77#[non_exhaustive]
78pub enum ReadError {
79    #[error("Could not read PerfHeader")]
80    PerfHeader,
81
82    #[error("Could not read FeatureSection")]
83    FeatureSection,
84
85    #[error("Could not read BuildIdSection")]
86    BuildIdSection,
87
88    #[error("Could not read StringLen")]
89    StringLen,
90
91    #[error("Could not read String")]
92    String,
93
94    #[error("Could not read NrCpus")]
95    NrCpus,
96
97    #[error("Could not read AttrsSection")]
98    AttrsSection,
99
100    #[error("Could not read PerfEventAttr")]
101    PerfEventAttr,
102
103    #[error("Could not read PerfEventHeader")]
104    PerfEventHeader,
105
106    #[error("Could not read PerfEvent data")]
107    PerfEventData,
108}