github.com/waldiirawan/apm-agent-go/v2@v2.2.2/tracer_stats.go (about)

     1  // Licensed to Elasticsearch B.V. under one or more contributor
     2  // license agreements. See the NOTICE file distributed with
     3  // this work for additional information regarding copyright
     4  // ownership. Elasticsearch B.V. licenses this file to you under
     5  // the Apache License, Version 2.0 (the "License"); you may
     6  // 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,
    12  // software distributed under the License is distributed on an
    13  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14  // KIND, either express or implied.  See the License for the
    15  // specific language governing permissions and limitations
    16  // under the License.
    17  
    18  package apm // import "github.com/waldiirawan/apm-agent-go/v2"
    19  
    20  import "sync/atomic"
    21  
    22  // TracerStats holds statistics for a Tracer.
    23  type TracerStats struct {
    24  	Errors              TracerStatsErrors
    25  	ErrorsSent          uint64
    26  	ErrorsDropped       uint64
    27  	TransactionsSent    uint64
    28  	TransactionsDropped uint64
    29  	SpansSent           uint64
    30  	SpansDropped        uint64
    31  }
    32  
    33  // TracerStatsErrors holds error statistics for a Tracer.
    34  type TracerStatsErrors struct {
    35  	SendStream uint64
    36  }
    37  
    38  func (s TracerStats) isZero() bool {
    39  	return s == TracerStats{}
    40  }
    41  
    42  // accumulate updates the stats by accumulating them with
    43  // the values in rhs.
    44  func (s *TracerStats) accumulate(rhs TracerStats) {
    45  	atomic.AddUint64(&s.Errors.SendStream, rhs.Errors.SendStream)
    46  	atomic.AddUint64(&s.ErrorsSent, rhs.ErrorsSent)
    47  	atomic.AddUint64(&s.ErrorsDropped, rhs.ErrorsDropped)
    48  	atomic.AddUint64(&s.SpansSent, rhs.SpansSent)
    49  	atomic.AddUint64(&s.SpansDropped, rhs.SpansDropped)
    50  	atomic.AddUint64(&s.TransactionsSent, rhs.TransactionsSent)
    51  	atomic.AddUint64(&s.TransactionsDropped, rhs.TransactionsDropped)
    52  }
    53  
    54  // copy returns a copy of the most recent tracer stats.
    55  func (s *TracerStats) copy() TracerStats {
    56  	return TracerStats{
    57  		Errors: TracerStatsErrors{
    58  			SendStream: atomic.LoadUint64(&s.Errors.SendStream),
    59  		},
    60  		ErrorsSent:          atomic.LoadUint64(&s.ErrorsSent),
    61  		ErrorsDropped:       atomic.LoadUint64(&s.ErrorsDropped),
    62  		TransactionsSent:    atomic.LoadUint64(&s.TransactionsSent),
    63  		TransactionsDropped: atomic.LoadUint64(&s.TransactionsDropped),
    64  		SpansSent:           atomic.LoadUint64(&s.SpansSent),
    65  		SpansDropped:        atomic.LoadUint64(&s.SpansDropped),
    66  	}
    67  }