1 // Copyright (c) 2021 Cisco and/or its affiliates.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
24 // trace is the API tracer object synchronizing and keeping recoded messages.
32 func (c *trace) Enable(enable bool) {
33 if enable && atomic.CompareAndSwapInt32(&c.isEnabled, 0, 1) {
34 log.Debugf("API trace enabled")
35 } else if atomic.CompareAndSwapInt32(&c.isEnabled, 1, 0) {
36 log.Debugf("API trace disabled")
40 func (c *trace) GetRecords() (list []*api.Record) {
42 for _, entry := range c.list {
43 list = append(list, entry)
46 sort.Slice(list, func(i, j int) bool {
47 return list[i].Timestamp.Before(list[j].Timestamp)
52 func (c *trace) GetRecordsForChannel(chId uint16) (list []*api.Record) {
54 for _, entry := range c.list {
55 if entry.ChannelID == chId {
56 list = append(list, entry)
60 sort.Slice(list, func(i, j int) bool {
61 return list[i].Timestamp.Before(list[j].Timestamp)
66 func (c *trace) Clear() {
68 c.list = make([]*api.Record, 0)