2019-12-06 02:16:06 -05:00
|
|
|
/*
|
|
|
|
* MinIO Cloud Storage, (C) 2019 MinIO, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2020-05-04 01:35:40 -04:00
|
|
|
import "sync/atomic"
|
2019-12-06 02:16:06 -05:00
|
|
|
|
|
|
|
// CacheStats - represents bytes served from cache,
|
|
|
|
// cache hits and cache misses.
|
|
|
|
type CacheStats struct {
|
2020-05-04 01:35:40 -04:00
|
|
|
BytesServed uint64
|
|
|
|
Hits uint64
|
|
|
|
Misses uint64
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Increase total bytes served from cache
|
|
|
|
func (s *CacheStats) incBytesServed(n int64) {
|
2020-05-04 01:35:40 -04:00
|
|
|
atomic.AddUint64(&s.BytesServed, uint64(n))
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Increase cache hit by 1
|
|
|
|
func (s *CacheStats) incHit() {
|
2020-05-04 01:35:40 -04:00
|
|
|
atomic.AddUint64(&s.Hits, 1)
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Increase cache miss by 1
|
|
|
|
func (s *CacheStats) incMiss() {
|
2020-05-04 01:35:40 -04:00
|
|
|
atomic.AddUint64(&s.Misses, 1)
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get total bytes served
|
|
|
|
func (s *CacheStats) getBytesServed() uint64 {
|
2020-05-04 01:35:40 -04:00
|
|
|
return atomic.LoadUint64(&s.BytesServed)
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get total cache hits
|
|
|
|
func (s *CacheStats) getHits() uint64 {
|
2020-05-04 01:35:40 -04:00
|
|
|
return atomic.LoadUint64(&s.Hits)
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get total cache misses
|
|
|
|
func (s *CacheStats) getMisses() uint64 {
|
2020-05-04 01:35:40 -04:00
|
|
|
return atomic.LoadUint64(&s.Misses)
|
2019-12-06 02:16:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare new CacheStats structure
|
|
|
|
func newCacheStats() *CacheStats {
|
|
|
|
return &CacheStats{}
|
|
|
|
}
|