-
-
Notifications
You must be signed in to change notification settings - Fork 611
Expand file tree
/
Copy pathapp_monitor.h
More file actions
167 lines (141 loc) · 4.7 KB
/
app_monitor.h
File metadata and controls
167 lines (141 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#pragma once
#include <kicommon.h>
#include <string>
#include <set>
#include <wx/string.h>
#include <wx/filename.h>
namespace APP_MONITOR
{
enum class BREADCRUMB_TYPE
{
DEFAULT,
DBG,
ERR,
NAVIGATION,
INFO,
QUERY,
TRANSACTION,
UI,
USER,
};
enum class BREADCRUMB_LEVEL
{
FATAL,
ERR,
WARNING,
INFO,
DBG
};
class TRANSACTION_IMPL;
/**
* This represents a sentry transaction which is used for time-performance metrics
* You start a transaction and can denote "spans" inside the transaction for specific
* portions of the transaction.
*/
class KICOMMON_API TRANSACTION
{
public:
TRANSACTION( const std::string& aName, const std::string& aOperation );
~TRANSACTION();
void Start();
void StartSpan( const std::string& aOperation, const std::string& aDescription );
void FinishSpan();
void Finish();
#ifdef KICAD_USE_SENTRY
private:
// We use a IMPL to avoid seeding sentry everywhere
TRANSACTION_IMPL* m_impl = nullptr;
#endif
};
/**
* This struct represents a key being used for the std::set that deduplicates asserts
* during this running session.
*
* The elements are meant to make the assert sufficiently unique but at the same time
* avoid unnecessary noise. One notable issue was we used to use msg as a key but
* asserts with args in loops would defeat it and cause noise
*/
struct KICOMMON_API ASSERT_CACHE_KEY
{
wxString file;
int line;
wxString func;
wxString cond;
};
KICOMMON_API
bool operator<( const ASSERT_CACHE_KEY& aKey1, const ASSERT_CACHE_KEY& aKey2 );
/**
* This is a singleton class intended to manage sentry
*
* The inards of the api in this class are meant to be compiled out when KICAD_USE_SENTRY
* is not defined and become "inert" in order to reduce the need to sprinkle #ifdef checks
* everywhere.
*/
class KICOMMON_API SENTRY
{
public:
SENTRY( const SENTRY& obj ) = delete;
static SENTRY* Instance()
{
if( m_instance == nullptr )
m_instance = new SENTRY();
return m_instance;
}
void Init();
void Cleanup();
bool IsOptedIn();
void AddTag( const wxString& aKey, const wxString& aValue );
void SetSentryOptIn( bool aOptIn );
const wxString& GetSentryId();
void ResetSentryId();
void LogAssert( const ASSERT_CACHE_KEY& aKey, const wxString& aMsg );
void LogException( const wxString& aMsg, bool aUnhandled );
private:
SENTRY();
bool isConfiguredOptedIn();
void sentryInit();
wxString sentryCreateUid();
void readOrCreateUid();
static SENTRY* m_instance;
bool m_isOptedIn;
wxFileName m_sentry_optin_fn;
wxFileName m_sentry_uid_fn;
wxString m_sentryUid;
std::set<ASSERT_CACHE_KEY> m_assertCache;
};
/**
* Add a sentry breadcrumb
*/
KICOMMON_API void AddBreadcrumb( BREADCRUMB_TYPE aType, const wxString& aMsg, const wxString& aCategory,
BREADCRUMB_LEVEL aLevel = BREADCRUMB_LEVEL::INFO );
/**
* Add a navigation breadcrumb
*/
KICOMMON_API void AddNavigationBreadcrumb( const wxString& aMsg, const wxString& aCategory );
/**
* Add a transaction breadcrumb
*/
KICOMMON_API void AddTransactionBreadcrumb( const wxString& aMsg, const wxString& aCategory );
}