• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <stdexcept>
8 #include <string>
9 #include <sstream>
10 
11 namespace arm
12 {
13 
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 
Locationarm::pipe::Location23     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 
AsStringarm::pipe::Location32     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 
FileLinearm::pipe::Location40     std::string FileLine() const
41     {
42         std::stringstream ss;
43         ss << " [" << m_File << ':' << m_Line << "]";
44         return ss.str();
45     }
46 };
47 
48 /// General Exception class for Profiling code
49 class ProfilingException : public std::exception
50 {
51 public:
ProfilingException(const std::string & message)52     explicit ProfilingException(const std::string& message) : m_Message(message) {};
53 
ProfilingException(const std::string & message,const Location & location)54     explicit ProfilingException(const std::string& message,
55                                 const Location& location) : m_Message(message + location.AsString()) {};
56 
57     /// @return - Error message of ProfilingException
what() const58     virtual const char *what() const noexcept override
59     {
60          return m_Message.c_str();
61     }
62 
63 private:
64     std::string m_Message;
65 };
66 
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__)
83