Skip to content

Commit

Permalink
simplify macros
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@intel.com>
  • Loading branch information
rojkov committed Jan 12, 2021
1 parent 618a203 commit 0ad2460
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
14 changes: 7 additions & 7 deletions source/common/stats/tag_extractor_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool regexStartsWithDot(absl::string_view regex) {
TagExtractorImplBase::TagExtractorImplBase(absl::string_view name, absl::string_view regex,
absl::string_view substr)
: name_(name), prefix_(std::string(extractRegexPrefix(regex))), substr_(substr) {
PERF_TAG_COUNTERS_INIT(counters_);
PERF_TAG_INIT;
}

std::string TagExtractorImplBase::extractRegexPrefix(absl::string_view regex) {
Expand Down Expand Up @@ -92,7 +92,7 @@ bool TagExtractorStdRegexImpl::extractTag(absl::string_view stat_name, std::vect

if (substrMismatch(stat_name)) {
PERF_RECORD(perf, "re-skip", name_);
PERF_TAG_SKIPPED_INC(counters_);
PERF_TAG_INC(skipped_);
return false;
}

Expand All @@ -116,11 +116,11 @@ bool TagExtractorStdRegexImpl::extractTag(absl::string_view stat_name, std::vect
std::string::size_type end = remove_subexpr.second - stat_name.begin();
remove_characters.insert(start, end);
PERF_RECORD(perf, "re-match", name_);
PERF_TAG_MATCHED_INC(counters_);
PERF_TAG_INC(matched_);
return true;
}
PERF_RECORD(perf, "re-miss", name_);
PERF_TAG_MISSED_INC(counters_);
PERF_TAG_INC(missed_);
return false;
}

Expand All @@ -134,7 +134,7 @@ bool TagExtractorRe2Impl::extractTag(absl::string_view stat_name, std::vector<Ta

if (substrMismatch(stat_name)) {
PERF_RECORD(perf, "re2-skip", name_);
PERF_TAG_SKIPPED_INC(counters_);
PERF_TAG_INC(skipped_);
return false;
}

Expand All @@ -161,11 +161,11 @@ bool TagExtractorRe2Impl::extractTag(absl::string_view stat_name, std::vector<Ta
remove_characters.insert(start, end);

PERF_RECORD(perf, "re2-match", name_);
PERF_TAG_MATCHED_INC(counters_);
PERF_TAG_INC(matched_);
return true;
}
PERF_RECORD(perf, "re2-miss", name_);
PERF_TAG_MISSED_INC(counters_);
PERF_TAG_INC(missed_);
return false;
}

Expand Down
22 changes: 9 additions & 13 deletions source/common/stats/tag_extractor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,22 @@ struct Counters {
uint32_t missed_{};
};

#define PERF_TAG_COUNTERS(var) \
#define PERF_TAG_COUNTERS \
~TagExtractorImplBase() override { \
std::cout << fmt::format("TagStats for {} tag extractor: skipped {}, matched {}, missing {}", \
name_, var->skipped_, var->matched_, var->missed_) \
name_, counters_->skipped_, counters_->matched_, counters_->missed_) \
<< std::endl; \
} \
std::unique_ptr<Counters> var
std::unique_ptr<Counters> counters_

#define PERF_TAG_COUNTERS_INIT(var) var = std::make_unique<Counters>()
#define PERF_TAG_SKIPPED_INC(var) var->skipped_++
#define PERF_TAG_MISSED_INC(var) var->missed_++
#define PERF_TAG_MATCHED_INC(var) var->matched_++
#define PERF_TAG_INIT counters_ = std::make_unique<Counters>()
#define PERF_TAG_INC(member) ++(counters_->member)

#else

#define PERF_TAG_COUNTERS(var)
#define PERF_TAG_COUNTERS_INIT(var)
#define PERF_TAG_SKIPPED_INC(var)
#define PERF_TAG_MISSED_INC(var)
#define PERF_TAG_MATCHED_INC(var)
#define PERF_TAG_COUNTERS
#define PERF_TAG_INIT
#define PERF_TAG_INC(member)

#endif

Expand Down Expand Up @@ -100,7 +96,7 @@ class TagExtractorImplBase : public TagExtractor {
const std::string prefix_;
const std::string substr_;

PERF_TAG_COUNTERS(counters_);
PERF_TAG_COUNTERS;

This comment has been minimized.

Copy link
@jmarantz

jmarantz Jan 12, 2021

Contributor

nit: in the case where PERF_TAG_COUNTERS is defined as empty, we'll get a stray semi-colon. Not sure if clang-tiny might care. You could put the semi-colon in the macro definition and remove it here.

OTOH if clang-tidy is OK with this then so am I.

};

class TagExtractorStdRegexImpl : public TagExtractorImplBase {
Expand Down

0 comments on commit 0ad2460

Please sign in to comment.