OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // RapporRecorder holds all Histograms and BucketRanges that are used by |
| 6 // Histograms in the system. It provides a general place for |
| 7 // Histograms/BucketRanges to register, and supports a global API for accessing |
| 8 // (i.e., dumping, or graphing) the data. |
| 9 |
| 10 #ifndef CHROME_BROWSER_RAPPOR_RAPPOR_RECORDER_H_ |
| 11 #define CHROME_BROWSER_RAPPOR_RAPPOR_RECORDER_H_ |
| 12 |
| 13 #include <map> |
| 14 #include <string> |
| 15 #include <vector> |
| 16 |
| 17 #include "base/basictypes.h" |
| 18 #include "base/gtest_prod_util.h" |
| 19 #include "base/lazy_instance.h" |
| 20 #include "base/synchronization/lock.h" |
| 21 #include "components/rappor/rappor.h" |
| 22 |
| 23 #define RAPPOR_SAMPLE(name, sample) \ |
| 24 rappor::g_rappor_recorder.Get().GetRappor(name)->Add(sample); |
| 25 |
| 26 namespace rappor { |
| 27 |
| 28 class RapporRecorder { |
| 29 public: |
| 30 typedef std::vector<Rappor*> Rappors; |
| 31 |
| 32 // Method for extracting rappors for use by UMA. |
| 33 void GetRappors(Rappors* output); |
| 34 |
| 35 // Clears all recorded rappors. |
| 36 void ClearRappors(); |
| 37 |
| 38 // Find a rappor by name, and create it if it doesn't already exist. It |
| 39 // matches the exact name. This method is thread safe. |
| 40 Rappor* GetRappor(const std::string& name); |
| 41 |
| 42 // The constructor just initializes static members. Usually client code should |
| 43 // use Initialize to do this. But in test code, you can friend this class and |
| 44 // call destructor/constructor to get a clean RapporRecorder. |
| 45 RapporRecorder(); |
| 46 ~RapporRecorder(); |
| 47 |
| 48 private: |
| 49 // We keep all registered histograms in a map, from name to histogram. |
| 50 typedef std::map<std::string, Rappor*> RapporMap; |
| 51 |
| 52 RapporMap rappors_; |
| 53 |
| 54 // Lock protects access to above map. |
| 55 base::Lock lock_; |
| 56 }; |
| 57 |
| 58 extern base::LazyInstance<RapporRecorder>::Leaky g_rappor_recorder; |
| 59 |
| 60 } // namespace rappor |
| 61 |
| 62 #endif // CHROME_BROWSER_RAPPOR_RAPPOR_RECORDER_H_ |
OLD | NEW |