1
// Copyright 2022 The CubeFS Authors.
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
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
23
type timeReadWrite struct {
24
a int64 // alloc buffer
25
r int64 // PUT: read from client, GET: read from blobnode
26
w int64 // PUT: write to blobnode, GET: write to client
29
func (t *timeReadWrite) IncA(dur time.Duration) {
30
atomic.AddInt64(&t.a, int64(dur))
33
func (t *timeReadWrite) IncR(dur time.Duration) {
34
atomic.AddInt64(&t.r, int64(dur))
37
func (t *timeReadWrite) IncW(dur time.Duration) {
38
atomic.AddInt64(&t.w, int64(dur))
41
// String within milliseconds
42
func (t *timeReadWrite) String() string {
43
a := atomic.LoadInt64(&t.a) / 1e6
44
r := atomic.LoadInt64(&t.r) / 1e6
45
w := atomic.LoadInt64(&t.w) / 1e6
46
return fmt.Sprintf("a_%d_r_%d_w_%d", a, r, w)