/Users/deen/code/yugabyte-db/src/yb/util/flag_tags.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #include "yb/util/flag_tags.h" |
34 | | |
35 | | #include <map> |
36 | | #include <string> |
37 | | #include <unordered_set> |
38 | | #include <utility> |
39 | | #include <vector> |
40 | | |
41 | | #include "yb/gutil/map-util.h" |
42 | | #include "yb/gutil/singleton.h" |
43 | | |
44 | | using std::multimap; |
45 | | using std::pair; |
46 | | using std::string; |
47 | | using std::unordered_set; |
48 | | using std::vector; |
49 | | |
50 | | DEFINE_test_flag(bool, running_test, false, "Flag that is set to true when we running a test"); |
51 | | |
52 | | namespace yb { |
53 | | namespace flag_tags_internal { |
54 | | |
55 | | // Singleton registry storing the set of tags for each flag. |
56 | | class FlagTagRegistry { |
57 | | public: |
58 | 16.6M | static FlagTagRegistry* GetInstance() { |
59 | 16.6M | return Singleton<FlagTagRegistry>::get(); |
60 | 16.6M | } |
61 | | |
62 | 16.6M | void Tag(const string& name, const string& tag) { |
63 | 16.6M | tag_map_.insert(TagMap::value_type(name, tag)); |
64 | 16.6M | } |
65 | | |
66 | 562 | void GetTags(const string& name, unordered_set<string>* tags) { |
67 | 562 | tags->clear(); |
68 | 562 | pair<TagMap::const_iterator, TagMap::const_iterator> range = |
69 | 562 | tag_map_.equal_range(name); |
70 | 1.32k | for (auto it = range.first; it != range.second; ++it765 ) { |
71 | 765 | if (!InsertIfNotPresent(tags, it->second)) { |
72 | 0 | LOG(DFATAL) << "Flag " << name << " was tagged more than once with the tag '" |
73 | 0 | << it->second << "'"; |
74 | 0 | } |
75 | 765 | } |
76 | 562 | } |
77 | | |
78 | | private: |
79 | | friend class Singleton<FlagTagRegistry>; |
80 | 32.7k | FlagTagRegistry() {} |
81 | | |
82 | | typedef multimap<string, string> TagMap; |
83 | | TagMap tag_map_; |
84 | | |
85 | | DISALLOW_COPY_AND_ASSIGN(FlagTagRegistry); |
86 | | }; |
87 | | |
88 | | |
89 | 16.6M | FlagTagger::FlagTagger(const char* name, const char* tag) { |
90 | 16.6M | FlagTagRegistry::GetInstance()->Tag(name, tag); |
91 | 16.6M | } |
92 | | |
93 | 7.69M | FlagTagger::~FlagTagger() { |
94 | 7.69M | } |
95 | | |
96 | | } // namespace flag_tags_internal |
97 | | |
98 | | using flag_tags_internal::FlagTagRegistry; |
99 | | |
100 | | void GetFlagTags(const string& flag_name, |
101 | 562 | unordered_set<string>* tags) { |
102 | 562 | FlagTagRegistry::GetInstance()->GetTags(flag_name, tags); |
103 | 562 | } |
104 | | |
105 | | } // namespace yb |