summaryrefslogtreecommitdiffstats
path: root/components/startup_metric_utils/common/pre_read_field_trial_utils_win.h
blob: cacf4b389cc7762c1299e1cee82b68d5f8d2a229 (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
// Copyright 2015 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 COMPONENTS_STARTUP_METRIC_UTILS_COMMON_PRE_READ_FIELD_TRIAL_UTILS_WIN_H_
#define COMPONENTS_STARTUP_METRIC_UTILS_COMMON_PRE_READ_FIELD_TRIAL_UTILS_WIN_H_

#include <string>

#include "base/callback_forward.h"
#include "base/strings/string16.h"

// Utility functions to support the PreRead field trial. The PreRead field trial
// changes the way DLLs are pre-read during startup.

namespace startup_metric_utils {

// Callback to register a synthetic field trial.
using RegisterPreReadSyntheticFieldTrialCallback =
    const base::Callback<bool(const std::string&, const std::string&)>;

// The options controlled by the PreRead field trial.
struct PreReadOptions {
  // No explicit DLL pre-reading.
  bool no_pre_read;

  // Pre-read DLLs with a high thread priority.
  bool high_priority;

  // Pre-read DLLs only when they are cold.
  bool only_if_cold;

  // Pre-read DLLs using the ::PrefetchVirtualMemory function, if available.
  bool prefetch_virtual_memory;
};

// Initializes DLL pre-reading options from the registry.
// |product_registry_path| is the registry path under which the registry key for
// this field trial resides.
void InitializePreReadOptions(const base::string16& product_registry_path);

// Returns the bitfield of the DLL pre-reading options to use for the current
// process. InitializePreReadOptions() must have been called before this.
PreReadOptions GetPreReadOptions();

// Updates DLL pre-reading options in the registry with the latest info for the
// next startup. |product_registry_path| is the registry path under which the
// registry key for this field trial resides.
void UpdatePreReadOptions(const base::string16& product_registry_path);

// Registers a synthetic field trial with the PreRead group currently stored in
// the registry. This must be done before the first metric log
// (metrics::MetricsLog) is created. Otherwise, UMA metrics generated during
// startup won't be correctly annotated. |product_registry_path| is the registry
// path under which the key for this field trial resides.
void RegisterPreReadSyntheticFieldTrial(
    const base::string16& product_registry_path,
    const RegisterPreReadSyntheticFieldTrialCallback&
        register_synthetic_field_trial);

}  // namespace startup_metric_utils

#endif  // COMPONENTS_STARTUP_METRIC_UTILS_COMMON_PRE_READ_FIELD_TRIAL_UTILS_WIN_H_