Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1122)

Side by Side Diff: net/tools/ct_mapper/metrics.h

Issue 1238413004: Framework for iterating over certificates in CT database from Chromium code. (not for review) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make samples page work Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/ct_mapper/mapper.cc ('k') | net/tools/ct_mapper/metrics.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 NET_TOOLS_CT_MAPPER_METRICS_H_
6 #define NET_TOOLS_CT_MAPPER_METRICS_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/compiler_specific.h"
12 #include "net/tools/ct_mapper/entry.h"
13
14 namespace net {
15
16 struct Sample {
17 Sample();
18 Sample(const Sample& other);
19 Sample(Sample&& other);
20 Sample& operator=(const Sample& other);
21 Sample& operator=(Sample&& other);
22 ~Sample();
23
24 // If just 1 entry, means a single cert. Otherwise means a chain of
25 // certificates.
26 std::vector<der::Input> certs;
27 };
28
29 struct BucketValue {
30 BucketValue();
31 BucketValue(const BucketValue&);
32 BucketValue(BucketValue&&);
33 BucketValue& operator=(const BucketValue& other);
34 BucketValue& operator=(BucketValue&& other);
35 ~BucketValue();
36
37 void IncrementTotal() { total += 1; }
38
39 void AddSampleChain(const Entry& entry);
40 void AddSampleCert(const der::Input& cert);
41
42 void Merge(const BucketValue& other);
43 void Finalize();
44
45 static void SetMaxSamples(size_t limit);
46
47 size_t total = 0;
48 std::vector<Sample> samples;
49 };
50
51 class MetricsItem {
52 public:
53 MetricsItem();
54 MetricsItem(const MetricsItem&);
55 MetricsItem(MetricsItem&&);
56 MetricsItem& operator=(const MetricsItem& other);
57 MetricsItem& operator=(MetricsItem&& other);
58 ~MetricsItem();
59
60 using BucketMap = std::map<std::string, BucketValue>;
61
62 BucketValue* GetAndIncrementTotal(const std::string& bucket_name);
63
64 void IncrementTotal() { total_ += 1; };
65
66 void Merge(const MetricsItem& other);
67
68 void Finalize();
69
70 const BucketMap& buckets() const { return buckets_; }
71 size_t total() const { return total_; }
72
73 private:
74 // This is probably going to be equal to the total across buckets_, but
75 // doesn't necessarily have to be. For instance with errors, there may be
76 // multiple errors emitted per certificate processed. So MetricsItem will have
77 // a total that is number of paths processed, whereas buckets total will be
78 // all the errors.
79 size_t total_ = 0;
80 BucketMap buckets_;
81 };
82
83 class Metrics {
84 public:
85 Metrics();
86 ~Metrics();
87
88 using ItemMap = std::map<std::string, MetricsItem>;
89
90 MetricsItem* GetAndIncrementTotal(const std::string& item_name);
91
92 void Merge(const Metrics& metrics);
93 void Finalize();
94
95 const ItemMap& items() const { return items_; }
96
97 private:
98 ItemMap items_;
99 };
100
101 } // namespace net
102
103 #endif // NET_TOOLS_CT_MAPPER_METRICS_H_
OLDNEW
« no previous file with comments | « net/tools/ct_mapper/mapper.cc ('k') | net/tools/ct_mapper/metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698