blob: 2b4bc5381a5c81f5a9a64bee3fbc02a297c17b4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_
#define CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_
#include <string>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
namespace metrics {
class MetricSample;
} // namespace metrics
namespace chromecast {
namespace metrics {
class CastStabilityMetricsProvider;
// ExternalMetrics service allows processes outside of the Chromecast browser
// process to upload metrics via reading/writing to a known shared file.
class ExternalMetrics {
public:
explicit ExternalMetrics(CastStabilityMetricsProvider* stability_provider);
~ExternalMetrics();
// Begins external data collection. Calls to RecordAction originate in the
// File thread but are executed in the UI thread.
void Start();
private:
// The max length of a message (name-value pair, plus header)
static const int kMetricsMessageMaxLength = 1024; // be generous
// Passes an action event to the UMA service.
void RecordAction(const std::string& action_name);
// Records an external crash of the given string description.
void RecordCrash(const std::string& crash_kind);
// Records a sparse histogram. |sample| is expected to be a sparse histogram.
void RecordSparseHistogram(const ::metrics::MetricSample& sample);
// Collects external events from metrics log file. This is run at periodic
// intervals.
//
// Returns the number of events collected.
int CollectEvents();
// Calls CollectEvents and reschedules a future collection.
void CollectEventsAndReschedule();
// Schedules a metrics event collection in the future.
void ScheduleCollector();
// Reference to stability metrics provider, for reporting external crashes.
CastStabilityMetricsProvider* stability_provider_;
// File used by libmetrics to send metrics to the browser process.
std::string uma_events_file_;
base::WeakPtrFactory<ExternalMetrics> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ExternalMetrics);
};
} // namespace metrics
} // namespace chromecast
#endif // CHROMECAST_BROWSER_METRICS_EXTERNAL_METRICS_H_
|