]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/monitoring/in_memory_stats_history.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style license that can be
7 // found in the LICENSE file. See the AUTHORS file for names of contributors.
9 #include "monitoring/in_memory_stats_history.h"
10 #include "db/db_impl/db_impl.h"
12 namespace ROCKSDB_NAMESPACE
{
14 InMemoryStatsHistoryIterator::~InMemoryStatsHistoryIterator() {}
16 bool InMemoryStatsHistoryIterator::Valid() const { return valid_
; }
18 Status
InMemoryStatsHistoryIterator::status() const { return status_
; }
20 // Because of garbage collection, the next stats snapshot may or may not be
21 // right after the current one. When reading from DBImpl::stats_history_, this
22 // call will be protected by DB Mutex so it will not return partial or
24 void InMemoryStatsHistoryIterator::Next() {
25 // increment start_time by 1 to avoid infinite loop
26 AdvanceIteratorByTime(GetStatsTime() + 1, end_time_
);
29 uint64_t InMemoryStatsHistoryIterator::GetStatsTime() const { return time_
; }
31 const std::map
<std::string
, uint64_t>&
32 InMemoryStatsHistoryIterator::GetStatsMap() const {
36 // advance the iterator to the next time between [start_time, end_time)
37 // if success, update time_ and stats_map_ with new_time and stats_map
38 void InMemoryStatsHistoryIterator::AdvanceIteratorByTime(uint64_t start_time
,
40 // try to find next entry in stats_history_ map
41 if (db_impl_
!= nullptr) {
43 db_impl_
->FindStatsByTime(start_time
, end_time
, &time_
, &stats_map_
);
49 } // namespace ROCKSDB_NAMESPACE