blob: 746b82928ed9185126643e0361f9a99aa28291ff [file] [log] [blame]
wittmand19f5202015-03-24 03:25:471// 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 COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_
6#define COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_
7
8#include <vector>
9
avi26062922015-12-26 00:14:1810#include "base/macros.h"
wittmanae2a08a2015-04-08 02:20:3511#include "base/memory/ref_counted.h"
wittmand19f5202015-03-24 03:25:4712#include "base/profiler/stack_sampling_profiler.h"
13#include "components/metrics/metrics_provider.h"
14
15namespace metrics {
16class ChromeUserMetricsExtension;
17
18// Performs metrics logging for the stack sampling profiler.
19class CallStackProfileMetricsProvider : public MetricsProvider {
20 public:
wittman878ef2a2015-04-10 09:32:4121 // The event that triggered the profile collection.
sydlif192d052015-09-16 22:24:5822 // This enum should be kept in sync with content/common/profiled_stack_state.h
wittman878ef2a2015-04-10 09:32:4123 enum Trigger {
24 UNKNOWN,
25 PROCESS_STARTUP,
26 JANKY_TASK,
sydlif192d052015-09-16 22:24:5827 THREAD_HUNG,
28 TRIGGER_LAST = THREAD_HUNG
wittman878ef2a2015-04-10 09:32:4129 };
30
wittman622851e2015-07-31 18:13:4031 // Parameters to pass back to the metrics provider.
32 struct Params {
33 explicit Params(Trigger trigger);
34 Params(Trigger trigger, bool preserve_sample_ordering);
35
36 // The triggering event.
37 Trigger trigger;
38
39 // True if sample ordering is important and should be preserved when the
40 // associated profiles are compressed. This should only be set to true if
41 // the intended use of the requires that the sequence of call stacks within
42 // a particular profile be preserved. The default value of false provides
43 // better compression of the encoded profile and is sufficient for the
44 // typical use case of recording profiles for stack frequency analysis in
45 // aggregate.
46 bool preserve_sample_ordering;
47 };
48
wittmand19f5202015-03-24 03:25:4749 CallStackProfileMetricsProvider();
50 ~CallStackProfileMetricsProvider() override;
51
wittman622851e2015-07-31 18:13:4052 // Get a callback for use with StackSamplingProfiler that provides completed
53 // profiles to this object. The callback should be immediately passed to the
54 // StackSamplingProfiler, and should not be reused between
55 // StackSamplingProfilers. This function may be called on any thread.
56 static base::StackSamplingProfiler::CompletedCallback GetProfilerCallback(
57 const Params& params);
58
wittmand19f5202015-03-24 03:25:4759 // MetricsProvider:
wittmanae2a08a2015-04-08 02:20:3560 void OnRecordingEnabled() override;
61 void OnRecordingDisabled() override;
wittmand19f5202015-03-24 03:25:4762 void ProvideGeneralMetrics(ChromeUserMetricsExtension* uma_proto) override;
63
wittmanae2a08a2015-04-08 02:20:3564 protected:
65 // Finch field trial and group for reporting profiles. Provided here for test
66 // use.
67 static const char kFieldTrialName[];
68 static const char kReportProfilesGroupName[];
69
wittman622851e2015-07-31 18:13:4070 // Reset the static state to the defaults after startup.
71 static void ResetStaticStateForTesting();
72
wittmand19f5202015-03-24 03:25:4773 private:
wittmanae2a08a2015-04-08 02:20:3574 // Returns true if reporting of profiles is enabled according to the
75 // controlling Finch field trial.
wittman622851e2015-07-31 18:13:4076 static bool IsReportingEnabledByFieldTrial();
wittmand19f5202015-03-24 03:25:4777
78 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProvider);
79};
80
81} // namespace metrics
82
83#endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_METRICS_PROVIDER_H_