Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | #include <stdexcept> |
| 8 | #include <string> |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 9 | #include <sstream> |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 10 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 11 | namespace arm |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 12 | { |
| 13 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 14 | namespace pipe |
| 15 | { |
| 16 | |
| 17 | struct 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 Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 48 | /// General Exception class for Profiling code |
| 49 | class ProfilingException : public std::exception |
| 50 | { |
| 51 | public: |
| 52 | explicit ProfilingException(const std::string& message) : m_Message(message) {}; |
| 53 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 54 | explicit ProfilingException(const std::string& message, |
| 55 | const Location& location) : m_Message(message + location.AsString()) {}; |
| 56 | |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 57 | /// @return - Error message of ProfilingException |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 58 | virtual const char *what() const noexcept override |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 59 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 60 | return m_Message.c_str(); |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | private: |
| 64 | std::string m_Message; |
| 65 | }; |
| 66 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 67 | class TimeoutException : public ProfilingException |
| 68 | { |
| 69 | public: |
| 70 | using ProfilingException::ProfilingException; |
| 71 | }; |
| 72 | |
| 73 | class InvalidArgumentException : public ProfilingException |
| 74 | { |
| 75 | public: |
| 76 | using ProfilingException::ProfilingException; |
| 77 | }; |
| 78 | |
| 79 | } // namespace pipe |
| 80 | } // namespace arm |
| 81 | |
| 82 | #define LOCATION() arm::pipe::Location(__func__, __FILE__, __LINE__) |