Line data Source code
1 : /*
2 : * Copyright (c) 2023 Project CHIP Authors
3 : * All rights reserved.
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 : #pragma once
18 :
19 : #include <tracing/log_declares.h>
20 :
21 : namespace chip {
22 : namespace Tracing {
23 :
24 : /// Represents a generic tracing back-end.
25 : ///
26 : /// THREAD SAFETY:
27 : /// Implementations of backends are expected to be thread safe as
28 : /// separate threads may call its functions (e.g. BLE and CASE processing
29 : /// may be traced and run on different threads)
30 : class Backend
31 : {
32 : public:
33 10 : virtual ~Backend() = default;
34 :
35 : /// Guaranteed to be called before registering
36 0 : virtual void Open() {}
37 :
38 : /// Guaranteed to be called after un-registering.
39 0 : virtual void Close() {}
40 :
41 : /// Begin a trace for the specified scope.
42 : ///
43 : /// Scope WILL be completed by a corresponding TraceEnd call.
44 0 : virtual void TraceBegin(const char * label, const char * group) {}
45 :
46 : /// Tracing end assumes completing a previously started scope with TraceBegin
47 : /// and nesting is assumed.
48 : ///
49 : /// Expect scopes like:
50 : /// TraceBegin("foo", "A")
51 : /// TraceBegin("bar", "A")
52 : ///
53 : /// // NOT VALID HERE: TraceEnd("foo", "A")
54 : ///
55 : /// TraceEnd("bar", "A") // ends "BAR"
56 : /// TraceEnd("foo", "A") // ends "FOO"
57 0 : virtual void TraceEnd(const char * label, const char * group) {}
58 :
59 : /// Trace a zero-sized event
60 0 : virtual void TraceInstant(const char * label, const char * group) {}
61 :
62 0 : virtual void TraceCounter(const char * label) {}
63 0 : virtual void LogMessageSend(MessageSendInfo &) { TraceInstant("MessageSent", "Messaging"); }
64 0 : virtual void LogMessageReceived(MessageReceivedInfo &) { TraceInstant("MessageReceived", "Messaging"); }
65 :
66 0 : virtual void LogNodeLookup(NodeLookupInfo &) { TraceInstant("Lookup", "DNSSD"); }
67 0 : virtual void LogNodeDiscovered(NodeDiscoveredInfo &) { TraceInstant("Node Discovered", "DNSSD"); }
68 0 : virtual void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) { TraceInstant("Discovery Failed", "DNSSD"); }
69 0 : virtual void LogMetricEvent(const MetricEvent &) { TraceInstant("Metric Event", "Metric"); }
70 : };
71 :
72 : } // namespace Tracing
73 : } // namespace chip
|