blob: 135798817a71d35554aaa00981e9dab0e33fe9cd [file] [log] [blame]
Jim Flynn4e755a52020-03-29 17:48:26 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Jim Flynn4e755a52020-03-29 17:48:26 +01003// SPDX-License-Identifier: MIT
4//
5#pragma once
6
7#include <stdexcept>
8#include <string>
Jim Flynnbbfe6032020-07-20 16:57:44 +01009#include <sstream>
Jim Flynn4e755a52020-03-29 17:48:26 +010010
Jim Flynnbbfe6032020-07-20 16:57:44 +010011namespace arm
Jim Flynn4e755a52020-03-29 17:48:26 +010012{
13
Jim Flynnbbfe6032020-07-20 16:57:44 +010014namespace pipe
15{
16
17struct Location
18{
19 const char* m_Function;
20 const char* m_File;
21 unsigned int m_Line;
22
23 Location(const char* func,
24 const char* file,
25 unsigned int line)
26 : m_Function{func}
27 , m_File{file}
28 , m_Line{line}
29 {
30 }
31
32 std::string AsString() const
33 {
34 std::stringstream ss;
35 ss << " at function " << m_Function
36 << " [" << m_File << ':' << m_Line << "]";
37 return ss.str();
38 }
39
40 std::string FileLine() const
41 {
42 std::stringstream ss;
43 ss << " [" << m_File << ':' << m_Line << "]";
44 return ss.str();
45 }
46};
47
Jim Flynn4e755a52020-03-29 17:48:26 +010048/// General Exception class for Profiling code
49class ProfilingException : public std::exception
50{
51public:
52 explicit ProfilingException(const std::string& message) : m_Message(message) {};
53
Jim Flynnbbfe6032020-07-20 16:57:44 +010054 explicit ProfilingException(const std::string& message,
55 const Location& location) : m_Message(message + location.AsString()) {};
56
Jim Flynn4e755a52020-03-29 17:48:26 +010057 /// @return - Error message of ProfilingException
Jim Flynnbbfe6032020-07-20 16:57:44 +010058 virtual const char *what() const noexcept override
Jim Flynn4e755a52020-03-29 17:48:26 +010059 {
Jim Flynnbbfe6032020-07-20 16:57:44 +010060 return m_Message.c_str();
Jim Flynn4e755a52020-03-29 17:48:26 +010061 }
62
63private:
64 std::string m_Message;
65};
66
Jim Flynnf9db3ef2022-03-08 21:23:44 +000067class BackendProfilingException : public ProfilingException
68{
69public:
70 using ProfilingException::ProfilingException;
71};
72
Jim Flynndecd08b2022-03-13 22:35:46 +000073class BadOptionalAccessException : public ProfilingException
74{
75 using ProfilingException::ProfilingException;
76};
77
Jim Flynnf9db3ef2022-03-08 21:23:44 +000078class BufferExhaustion : public ProfilingException
Jim Flynnbbfe6032020-07-20 16:57:44 +010079{
80public:
81 using ProfilingException::ProfilingException;
82};
83
84class InvalidArgumentException : public ProfilingException
85{
86public:
87 using ProfilingException::ProfilingException;
88};
89
Jim Flynnf9db3ef2022-03-08 21:23:44 +000090class TimeoutException : public ProfilingException
91{
92public:
93 using ProfilingException::ProfilingException;
94};
95
96class UnimplementedException : public ProfilingException
97{
98public:
99 using ProfilingException::ProfilingException;
100};
101
Jim Flynnbbfe6032020-07-20 16:57:44 +0100102} // namespace pipe
103} // namespace arm
104
105#define LOCATION() arm::pipe::Location(__func__, __FILE__, __LINE__)