blob: 9ef435ed9ec36b86d360a45a41d06659b4d5e894 [file] [log] [blame]
[email protected]7c7a42752012-08-09 05:14:151// 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#ifndef BASE_METRICS_SPARSE_HISTOGRAM_H_
6#define BASE_METRICS_SPARSE_HISTOGRAM_H_
7
8#include <map>
9#include <string>
10
11#include "base/base_export.h"
12#include "base/basictypes.h"
13#include "base/compiler_specific.h"
14#include "base/metrics/histogram_base.h"
15#include "base/synchronization/lock.h"
16
17namespace base {
18
19class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase {
20 public:
21 // If there's one with same name, return the existing one. If not, create a
22 // new one.
23 static HistogramBase* FactoryGet(const std::string& name, int32 flags);
24
25 virtual ~SparseHistogram();
26
27 virtual void Add(Sample value) OVERRIDE;
28
29 virtual void SnapshotSample(std::map<Sample, Count>* sample) const;
30 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE;
31 virtual void WriteAscii(std::string* output) const OVERRIDE;
32
33 protected:
34 // Clients should always use FactoryGet to create SparseHistogram.
35 SparseHistogram(const std::string& name);
36
37 private:
38 friend class SparseHistogramTest; // For constuctor calling.
39
40 std::map<Sample, Count> samples_;
41
42 // Protects access to above map.
43 mutable base::Lock lock_;
44
45 DISALLOW_COPY_AND_ASSIGN(SparseHistogram);
46};
47
48} // namespace base
49
50#endif // BASE_METRICS_SPARSE_HISTOGRAM_H_