blob: abdc0dc02588d832de4a7b7131e5a20ca4a34916 [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 Flynnbbfe6032020-07-20 16:57:44 +010067class TimeoutException : public ProfilingException
68{
69public:
70 using ProfilingException::ProfilingException;
71};
72
73class InvalidArgumentException : public ProfilingException
74{
75public:
76 using ProfilingException::ProfilingException;
77};
78
79} // namespace pipe
80} // namespace arm
81
82#define LOCATION() arm::pipe::Location(__func__, __FILE__, __LINE__)