joule_profiler_source_rapl/
error.rs1use crate::domain_type::RaplDomainType;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
6pub enum RaplError {
7 #[error("Intel RAPL not available: {0}")]
9 RaplNotAvailable(String),
10
11 #[error("No RAPL domains found")]
13 NoDomains,
14
15 #[error("Failed to read RAPL domain: {0}")]
17 RaplReadError(String),
18
19 #[error("Invalid RAPL domain path: {0}")]
21 InvalidRaplPath(String),
22
23 #[error("Invalid socket specification: {0}")]
25 InvalidSocketSpec(String),
26
27 #[error("Socket {0} not found in available RAPL domains")]
29 SocketNotFound(u32),
30
31 #[error("Command not found: {0}")]
33 CommandNotFound(String),
34
35 #[error("Unsupported operating system: {0}. Only Linux is supported")]
37 UnsupportedOS(String),
38
39 #[error("Insufficient permissions to access RAPL counters. Try running with sudo")]
41 InsufficientPermissions,
42
43 #[error("Unknown domain {0}")]
45 UnknownDomain(String),
46
47 #[error("Failed to open domain counter, {0}")]
50 FailToOpenDomainCounter(String),
51
52 #[error("Invalid event format for domain {0}")]
54 InvalidEventFormat(String),
55
56 #[error("Domain {0} not supported")]
58 DomainNotSupported(RaplDomainType),
59
60 #[error(transparent)]
62 PerfParanoid(#[from] PerfParanoidError),
63
64 #[error("Cannot retrieve perf RAPL scale")]
66 RetrieveScaleError,
67
68 #[error(transparent)]
70 IoError(std::io::Error),
71
72 #[error("Failed to parse energy value")]
74 ParseEnergyError(
75 #[from]
76 #[source]
77 std::num::ParseIntError,
78 ),
79
80 #[error("Failed to parse domain scale")]
82 ParseDomainScale(
83 #[from]
84 #[source]
85 std::num::ParseFloatError,
86 ),
87
88 #[error("Not enough measures to compute RAPL counters differences")]
90 NotEnoughSamples,
91
92 #[error("RAPL source mutex poisoned.")]
93 MutexPoisoned,
94}
95
96impl From<std::io::Error> for RaplError {
97 fn from(err: std::io::Error) -> Self {
98 match err.kind() {
99 std::io::ErrorKind::NotFound => RaplError::RaplNotAvailable(err.to_string()),
100 std::io::ErrorKind::PermissionDenied => RaplError::InsufficientPermissions,
101 _ => RaplError::IoError(err),
102 }
103 }
104}
105
106#[derive(Debug, Error)]
108pub enum PerfParanoidError {
109 #[error("perf_event_paranoid file not found")]
111 NotFound,
112
113 #[error("perf_event_paranoid not readable: {0}")]
115 PermissionDenied(String),
116
117 #[error(
119 "perf_event_paranoid level is {0}, try setting it to 0 or launch profiler with root rights"
120 )]
121 ParanoidLevelTooHigh(i8),
122
123 #[error(transparent)]
125 IoError(std::io::Error),
126
127 #[error("Failed to parse paranoid level")]
129 ParseParanoidLevelError(
130 #[from]
131 #[source]
132 std::num::ParseIntError,
133 ),
134}