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 <lib/support/IntrusiveList.h>
20 : #include <tracing/log_declares.h>
21 :
22 : namespace chip {
23 : namespace Tracing {
24 :
25 : /// Represents a generic tracing back-end.
26 : ///
27 : /// Derived from an intrusive list base as multiple
28 : /// tracing back-ends may exist per application.
29 : ///
30 : /// THREAD SAFETY:
31 : /// Implementations of backends are expected to be thread safe as
32 : /// separate threads may call its functions (e.g. BLE and CASE processing
33 : /// may be traced and run on different threads)
34 : class Backend : public ::chip::IntrusiveListNodeBase<>
35 : {
36 : public:
37 10 : virtual ~Backend() = default;
38 :
39 : /// Guaranteed to be called before registering
40 0 : virtual void Open() {}
41 :
42 : /// Guaranteed to be called after un-registering.
43 0 : virtual void Close() {}
44 :
45 : /// Begin a trace for the specified scope.
46 : ///
47 : /// Scope WILL be completed by a corresponding TraceEnd call.
48 0 : virtual void TraceBegin(const char * label, const char * group) {}
49 :
50 : /// Tracing end assumes completing a previously started scope with TraceBegin
51 : /// and nesting is assumed.
52 : ///
53 : /// Expect scopes like:
54 : /// TraceBegin("foo", "A")
55 : /// TraceBegin("bar", "A")
56 : ///
57 : /// // NOT VALID HERE: TraceEnd("foo", "A")
58 : ///
59 : /// TraceEnd("bar", "A") // ends "BAR"
60 : /// TraceEnd("foo", "A") // ends "FOO"
61 0 : virtual void TraceEnd(const char * label, const char * group) {}
62 :
63 : /// Trace a zero-sized event
64 0 : virtual void TraceInstant(const char * label, const char * group) {}
65 :
66 0 : virtual void TraceCounter(const char * label) {}
67 0 : virtual void LogMessageSend(MessageSendInfo &) { TraceInstant("MessageSent", "Messaging"); }
68 0 : virtual void LogMessageReceived(MessageReceivedInfo &) { TraceInstant("MessageReceived", "Messaging"); }
69 :
70 0 : virtual void LogNodeLookup(NodeLookupInfo &) { TraceInstant("Lookup", "DNSSD"); }
71 0 : virtual void LogNodeDiscovered(NodeDiscoveredInfo &) { TraceInstant("Node Discovered", "DNSSD"); }
72 0 : virtual void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) { TraceInstant("Discovery Failed", "DNSSD"); }
73 0 : virtual void LogMetricEvent(const MetricEvent &) { TraceInstant("Metric Event", "Metric"); }
74 : };
75 :
76 : } // namespace Tracing
77 : } // namespace chip
|