Skip to content

Commit 17f252d

Browse files
Razvan Becheriutmarkwalder
Razvan Becheriu
authored andcommitted
[#3253] addresed review
1 parent 0d3b014 commit 17f252d

9 files changed

+76
-76
lines changed

src/hooks/dhcp/perfmon/alarm_store.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ AlarmStore::checkDurationSample(DurationKeyPtr key, const Duration& sample,
4848
auto& index = alarms_.get<AlarmPrimaryKeyTag>();
4949
auto alarm_iter = index.find(*key);
5050

51-
// If we find an alarm the check the sample. Alarm::checkSample()
52-
//does not alter the key so it can be done in-place.
51+
// If we find an alarm then we check the sample. Alarm::checkSample()
52+
// does not alter the key so it can be done in-place.
5353
if (alarm_iter != index.end()) {
5454
bool should_report = false;
5555
bool modified = index.modify(alarm_iter,
@@ -87,7 +87,7 @@ AlarmStore::addAlarm(AlarmPtr alarm) {
8787

8888
AlarmPtr
8989
AlarmStore::addAlarm(DurationKeyPtr key, const Duration& low_water,
90-
const Duration& high_water, bool enabled /* = true */) {
90+
const Duration& high_water, bool enabled /* = true */) {
9191
validateKey("addAlarm", key);
9292

9393
// Create the alarm instance.
@@ -149,8 +149,8 @@ AlarmStore::getAll() {
149149
MultiThreadingLock lock(*mutex_);
150150
const auto& index = alarms_.get<AlarmPrimaryKeyTag>();
151151
AlarmCollectionPtr collection(new AlarmCollection());
152-
for (auto alarm_iter = index.begin(); alarm_iter != index.end(); ++alarm_iter) {
153-
collection->push_back(AlarmPtr(new Alarm(**alarm_iter)));
152+
for (auto const& alarm : index) {
153+
collection->push_back(AlarmPtr(new Alarm(*alarm)));
154154
}
155155

156156
return (collection);

src/hooks/dhcp/perfmon/alarm_store.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DuplicateAlarm : public Exception {
3636
/// @brief Tag for index by primary key (DurationKey).
3737
struct AlarmPrimaryKeyTag { };
3838

39-
/// @brief A multi index container holding pointers to Alarms.
39+
/// @brief A multi index container holding pointers to alarms.
4040
///
4141
/// The alarms in the container may be accessed using different indexes:
4242
/// - using the index on DurationKey members, AlarmPrimaryKeyTag
@@ -64,10 +64,10 @@ typedef std::vector<AlarmPtr> AlarmCollection;
6464
/// @brief Type for a pointer to a collection of AlarmPtrs.
6565
typedef boost::shared_ptr<AlarmCollection> AlarmCollectionPtr;
6666

67-
/// @brief Maintains an in-memory store of Alarms
67+
/// @brief Maintains an in-memory store of alarms
6868
///
6969
/// Provides essential CRUD functions for managing a collection of
70-
/// Alarms. Additionally there are finders that can return
70+
/// alarms. Additionally there are finders that can return
7171
/// durations by DurationKey (others are TBD).
7272
/// All finders return copies of the durations found, rather than the
7373
/// stored duration itself.
@@ -102,22 +102,22 @@ class AlarmStore {
102102
AlarmPtr checkDurationSample(DurationKeyPtr key, const Duration& sample,
103103
const Duration& report_interval);
104104

105-
/// @brief Creates a new Alarm and adds it to the store
105+
/// @brief Creates a new alarm and adds it to the store
106106
///
107-
/// @param key key value of the Alarm to create.
107+
/// @param key key value of the alarm to create.
108108
/// @param low_water threshold below which the average duration must fall to clear the alarm
109109
/// @param high_water threshold above which the average duration must rise to trigger the alarm.
110110
/// @param enabled true sets state to CLEAR, otherwise DISABLED, defaults to true.
111111
///
112-
/// @return pointer to the newly created Alarm.
112+
/// @return pointer to the newly created alarm.
113113
/// @throw DuplicateAlarm if a duration for the given key already exists in
114114
/// the store.
115115
AlarmPtr addAlarm(DurationKeyPtr key, const Duration& low_water,
116116
const Duration& high_water, bool enabled = true);
117117

118-
/// @brief Adds an Alarm to the store.
118+
/// @brief Adds an alarm to the store.
119119
///
120-
/// @return pointer to a copy of the Alarm added.
120+
/// @return pointer to a copy of the alarm added.
121121
AlarmPtr addAlarm(AlarmPtr alarm);
122122

123123
/// @brief Fetches a duration from the store for a given key.
@@ -162,7 +162,7 @@ class AlarmStore {
162162
/// @brief Convenience method to verify a key is valid for an operation.
163163
///
164164
/// @param label description of where the check is being made, appears in exception text.
165-
/// @param key key to validate
165+
/// @param key key to validate.
166166
///
167167
/// @throw BadValue if the key is either empty or its family does not
168168
/// match the store.

src/hooks/dhcp/perfmon/monitored_duration.cc

+16-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ namespace perfmon {
2323
DurationDataInterval::DurationDataInterval(const Timestamp& start_time /* = PktEvent::now()*/)
2424
: start_time_(start_time), occurrences_(0),
2525
min_duration_(pos_infin), max_duration_(neg_infin),
26-
total_duration_(microseconds(0)) { } void
26+
total_duration_(microseconds(0)) {
27+
}
28+
29+
void
2730
DurationDataInterval::addDuration(const Duration& duration) {
2831
++occurrences_;
2932
if (duration < min_duration_) {
@@ -48,13 +51,11 @@ DurationDataInterval::getAverageDuration() const {
4851

4952
bool
5053
DurationDataInterval::operator==(const DurationDataInterval& other) const {
51-
return (
52-
(start_time_ == other.start_time_) &&
53-
(occurrences_ == other.occurrences_) &&
54-
(min_duration_ == other.min_duration_) &&
55-
(max_duration_ == other.max_duration_) &&
56-
(total_duration_ == other.total_duration_)
57-
);
54+
return ((start_time_ == other.start_time_) &&
55+
(occurrences_ == other.occurrences_) &&
56+
(min_duration_ == other.min_duration_) &&
57+
(max_duration_ == other.max_duration_) &&
58+
(total_duration_ == other.total_duration_));
5859
}
5960

6061
// DurationKey methods
@@ -190,13 +191,11 @@ DurationKey::operator!=(const DurationKey& other) const {
190191

191192
bool
192193
DurationKey::operator<(const DurationKey& other) const {
193-
return (
194-
(query_type_ < other.query_type_) ||
195-
(response_type_ < other.response_type_) ||
196-
(start_event_label_ < other.start_event_label_) ||
197-
(stop_event_label_ < other.stop_event_label_) ||
198-
(subnet_id_ < other.subnet_id_)
199-
);
194+
return ((query_type_ < other.query_type_) ||
195+
(response_type_ < other.response_type_) ||
196+
(start_event_label_ < other.start_event_label_) ||
197+
(stop_event_label_ < other.stop_event_label_) ||
198+
(subnet_id_ < other.subnet_id_));
200199
}
201200

202201

@@ -237,11 +236,11 @@ MonitoredDuration::MonitoredDuration(const MonitoredDuration& rhs)
237236
current_interval_(0),
238237
previous_interval_(0) {
239238
if (rhs.current_interval_) {
240-
current_interval_.reset(new DurationDataInterval(*rhs.current_interval_));
239+
current_interval_.reset(new DurationDataInterval(*rhs.current_interval_));
241240
}
242241

243242
if (rhs.previous_interval_) {
244-
previous_interval_.reset(new DurationDataInterval(*rhs.previous_interval_));
243+
previous_interval_.reset(new DurationDataInterval(*rhs.previous_interval_));
245244
}
246245
}
247246

src/hooks/dhcp/perfmon/monitored_duration.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class DurationKey {
237237
///
238238
/// less than operator to compare two DurationKey objects.
239239
/// @param other DurationKey to be compared against.
240-
/// @return True other is less than this key
240+
/// @return True key is less than the other key
241241
bool operator<(const DurationKey& other) const;
242242

243243
protected:

src/hooks/dhcp/perfmon/monitored_duration_store.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ MonitoredDurationStore::addDurationSample(DurationKeyPtr key, const Duration& sa
5959
bool should_report = false;
6060
// Modify updates in place and only re-indexes if keys change.
6161
bool modified = index.modify(duration_iter,
62-
[sample, &should_report](MonitoredDurationPtr mond){
62+
[sample, &should_report](MonitoredDurationPtr mond) {
6363
should_report = mond->addSample(sample);
6464
});
6565

@@ -126,7 +126,7 @@ MonitoredDurationStore::getDuration(DurationKeyPtr key) {
126126
const auto& index = durations_.get<DurationKeyTag>();
127127
auto duration_iter = index.find(*key);
128128
return (duration_iter == index.end() ? MonitoredDurationPtr()
129-
: MonitoredDurationPtr(new MonitoredDuration(**duration_iter)));
129+
: MonitoredDurationPtr(new MonitoredDuration(**duration_iter)));
130130
}
131131

132132
void
@@ -166,8 +166,8 @@ MonitoredDurationStore::getAll() {
166166
MultiThreadingLock lock(*mutex_);
167167
const auto& index = durations_.get<DurationKeyTag>();
168168
MonitoredDurationCollectionPtr collection(new MonitoredDurationCollection());
169-
for (auto duration_iter = index.begin(); duration_iter != index.end(); ++duration_iter) {
170-
collection->push_back(MonitoredDurationPtr(new MonitoredDuration(**duration_iter)));
169+
for (auto const& mond : index) {
170+
collection->push_back(MonitoredDurationPtr(new MonitoredDuration(*mond)));
171171
}
172172

173173
return (collection);
@@ -186,7 +186,7 @@ MonitoredDurationStore::getReportsNext() {
186186
// We want to find the oldest interval that is less than interval_duration in the past.
187187
auto duration_iter = index.lower_bound(dhcp::PktEvent::now() - interval_duration_);
188188
return (duration_iter == index.end() ? MonitoredDurationPtr()
189-
: MonitoredDurationPtr(new MonitoredDuration(**duration_iter)));
189+
: MonitoredDurationPtr(new MonitoredDuration(**duration_iter)));
190190
}
191191

192192
MonitoredDurationCollectionPtr
@@ -195,7 +195,7 @@ MonitoredDurationStore::getOverdueReports(const Timestamp& since /* = PktEvent::
195195
// We use a lower bound of MIN + 1us to avoid dormant durations
196196
static Timestamp lower_limit_time(PktEvent::MIN_TIME() + microseconds(1));
197197

198-
// We want to find anything since the start of time that who's start time
198+
// We want to find anything since the start of time who's start time
199199
// is more than interval_duration_ in the past.
200200
const auto& index = durations_.get<IntervalStartTag>();
201201
auto lower_limit = index.lower_bound(lower_limit_time);

src/hooks/dhcp/perfmon/monitored_duration_store.h

+9-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct DurationKeyTag { };
3939
/// @brief Tag for index by interval start time.
4040
struct IntervalStartTag { };
4141

42-
/// @brief A multi index container holding pointers to MonitoredDurations.
42+
/// @brief A multi index container holding pointers to durations.
4343
///
4444
/// The durations in the container may be accessed using different indexes:
4545
/// - using the index on DurationKey members, DurationKeyTag
@@ -75,10 +75,10 @@ typedef std::vector<MonitoredDurationPtr> MonitoredDurationCollection;
7575
/// @brief Type for a pointer to a collection of MonitoredDurationPtrs.
7676
typedef boost::shared_ptr<MonitoredDurationCollection> MonitoredDurationCollectionPtr;
7777

78-
/// @brief Maintains an in-memory store of MonitoredDurations
78+
/// @brief Maintains an in-memory store of durations
7979
///
8080
/// Provides essential CRUD functions for managing a collection of
81-
/// MonitoredDurations. Additionally there are finders that can return
81+
/// durations. Additionally there are finders that can return
8282
/// durations by DurationKey (others are TBD)
8383
/// All finders return copies of the durations found, rather than the
8484
/// stored duration itself.
@@ -100,7 +100,7 @@ class MonitoredDurationStore {
100100
/// condition, then a copy of the in-store duration is returned, otherwise an empty
101101
/// pointer is returned.
102102
///
103-
/// If The duration does not exist in the store, then one is created and inserted
103+
/// If the duration does not exist in the store, then one is created and inserted
104104
/// into the store after adding the sample. An empty pointer is returned.
105105
///
106106
/// This function does not/must not modify any index keys.
@@ -112,7 +112,7 @@ class MonitoredDurationStore {
112112
/// pointer otherwise.
113113
MonitoredDurationPtr addDurationSample(DurationKeyPtr key, const Duration& sample);
114114

115-
/// @brief Creates a new MonitoredDuration and adds it to the store
115+
/// @brief Creates a new duration and adds it to the store
116116
///
117117
/// @param key key value of the duration to create.
118118
///
@@ -134,7 +134,7 @@ class MonitoredDurationStore {
134134
///
135135
/// @param duration duration to update.
136136
///
137-
/// @throw InvalidOperation if MonitoredDuration does not exist in the store.
137+
/// @throw InvalidOperation if duration does not exist in the store.
138138
void updateDuration(MonitoredDurationPtr& duration);
139139

140140
/// @brief Removes the duration from the store.
@@ -161,8 +161,7 @@ class MonitoredDurationStore {
161161
///
162162
/// @return a collection of the matching durations, ordered by current interval
163163
/// start time.
164-
MonitoredDurationCollectionPtr getOverdueReports(const Timestamp& since
165-
= dhcp::PktEvent::now());
164+
MonitoredDurationCollectionPtr getOverdueReports(const Timestamp& since = dhcp::PktEvent::now());
166165

167166
/// @brief Removes all durations from the store.
168167
void clear();
@@ -178,7 +177,7 @@ class MonitoredDurationStore {
178177
/// @brief Convenience method to verify a key is valid for an operation.
179178
///
180179
/// @param label description of where the check is being made, appears in exception text.
181-
/// @param key key to validate
180+
/// @param key key to validate.
182181
///
183182
/// @throw BadValue if the key is either empty or its family does not
184183
/// match the store.
@@ -187,7 +186,7 @@ class MonitoredDurationStore {
187186
/// @brief Protocol family AF_INET or AF_INET6.
188187
uint16_t family_;
189188

190-
/// @brief The length of time over data for a single MonitoredDuration is
189+
/// @brief The length of time over data for a single duration is
191190
/// accumulated before reporting.
192191
Duration interval_duration_;
193192

0 commit comments

Comments
 (0)