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

Side by Side Diff: components/rappor/rappor_metric.h

Issue 1058333002: Multi-dimension rappor metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add xml support Created 5 years, 8 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 | « components/rappor/bloom_filter_unittest.cc ('k') | components/rappor/rappor_metric.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_RAPPOR_RAPPOR_METRIC_H_ 5 #ifndef COMPONENTS_RAPPOR_RAPPOR_METRIC_H_
6 #define COMPONENTS_RAPPOR_RAPPOR_METRIC_H_ 6 #define COMPONENTS_RAPPOR_RAPPOR_METRIC_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "components/rappor/bloom_filter.h"
13 #include "components/rappor/byte_vector_utils.h" 12 #include "components/rappor/byte_vector_utils.h"
14 #include "components/rappor/rappor_parameters.h" 13 #include "components/rappor/rappor_parameters.h"
15 14
16 namespace rappor { 15 namespace rappor {
17 16
18 // A RapporMetric is an object that collects string samples into a Bloom filter, 17 namespace internal {
18
19 // Use byte vectors to store samples.
20 typedef ByteVector Sample;
21
22 // Given a string and flags, pack a bloom filter representing the string
23 // and the flags directly into a single sample that supports seperable
24 // analysis. |parameters| will determine how many bytes are used for each
25 // part of the sample.
26 void SetSampleBits(const RapporParameters& parameters, int32_t cohort_seed,
27 const std::string& str, uint64_t flags, Sample* output);
28
29 // A RapporMetric is an object that collects samples of a metric
19 // and generates randomized reports about the collected data. 30 // and generates randomized reports about the collected data.
20 // 31 //
21 // This class should not be used directly by metrics clients. Record metrics 32 // This class should not be used directly by metrics clients. Record metrics
22 // using RapporService::RecordSample instead. 33 // using RapporService::RecordSample instead.
23 // 34 //
24 // For a full description of the rappor metrics, see 35 // For a full description of the rappor metrics, see
25 // http://www.chromium.org/developers/design-documents/rappor 36 // http://www.chromium.org/developers/design-documents/rappor
26 class RapporMetric { 37 class RapporMetric {
27 public: 38 public:
28 // Takes the |metric_name| that this will be reported to the server with, 39 // Takes the |metric_name| that this will be reported to the server with,
29 // a |parameters| describing size and probability weights used in recording 40 // a |parameters| describing size and probability weights used in recording
30 // this metric, and a |cohort| value, which determines the hash functions 41 // this metric.
31 // used in the Bloom filter.
32 RapporMetric(const std::string& metric_name, 42 RapporMetric(const std::string& metric_name,
33 const RapporParameters& parameters, 43 const RapporParameters& parameters);
34 int32_t cohort);
35 ~RapporMetric(); 44 ~RapporMetric();
36 45
37 // Records an additional sample in the Bloom filter. 46 // Records an additional sample.
38 // A random sample will be used when reporting this metric when more than one 47 // A random sample will be used when reporting this metric when more than one
39 // sample is collected in the same reporting interval. 48 // sample is collected in the same reporting interval.
40 void AddSample(const std::string& str); 49 void AddSample(const Sample& str);
41 50
42 // Retrieves the current Bloom filter bits. 51 // Retrieves the current Sample.
43 const ByteVector& bytes() const { return bloom_filter_.bytes(); } 52 const Sample& bytes() const { return sample_; }
44 53
45 // Gets the parameter values this metric was constructed with. 54 // Gets the parameter values this metric was constructed with.
46 const RapporParameters& parameters() const { return parameters_; } 55 const RapporParameters& parameters() const { return parameters_; }
47 56
48 // Generates the bits to report for this metric. Using the secret as a seed, 57 // Generates the bits to report for this metric. Using the secret as a seed,
49 // randomly selects bits for redaction. Then flips coins to generate the 58 // randomly selects bits for redaction. Then flips coins to generate the
50 // final report bits. 59 // final report bits.
51 ByteVector GetReport(const std::string& secret) const; 60 ByteVector GetReport(const std::string& secret) const;
52 61
53 // Specify the bytes to generate a report from, for testing purposes. 62 // Specify the Sample to generate a report from, for testing purposes.
54 void SetBytesForTesting(const ByteVector& bytes); 63 void SetSampleForTesting(const Sample& bytes);
55 64
56 private: 65 private:
57 const std::string metric_name_; 66 const std::string metric_name_;
58 const RapporParameters parameters_; 67 const RapporParameters parameters_;
59 uint32_t sample_count_; 68 uint32_t sample_count_;
60 BloomFilter bloom_filter_; 69 Sample sample_;
61 70
62 DISALLOW_COPY_AND_ASSIGN(RapporMetric); 71 DISALLOW_COPY_AND_ASSIGN(RapporMetric);
63 }; 72 };
64 73
74 } // namespace internal
75
65 } // namespace rappor 76 } // namespace rappor
66 77
67 #endif // COMPONENTS_RAPPOR_RAPPOR_METRIC_H_ 78 #endif // COMPONENTS_RAPPOR_RAPPOR_METRIC_H_
OLDNEW
« no previous file with comments | « components/rappor/bloom_filter_unittest.cc ('k') | components/rappor/rappor_metric.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698