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

Side by Side Diff: components/metrics/file_metrics_provider.h

Issue 1537743006: Persist setup metrics and have Chrome report them during UMA upload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: addressed review comments by Greg Created 4 years, 10 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/metrics/BUILD.gn ('k') | components/metrics/file_metrics_provider.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 2016 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_FILE_METRICS_PROVIDER_H_
6 #define COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
7
8 #include <list>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/synchronization/lock.h"
17 #include "base/time/time.h"
18 #include "components/metrics/metrics_provider.h"
19
20 class PrefRegistrySimple;
21 class PrefService;
22
23 namespace base {
24 class MemoryMappedFile;
25 class PersistentMemoryAllocator;
26 class TaskRunner;
27 }
28
29 namespace metrics {
30
31 // FileMetricsProvider gathers and logs histograms written to files on disk.
32 // Any number of files can be registered and will be polled once per upload
33 // cycle (at startup and about every 30 minutes thereafter) for data to send.
34 class FileMetricsProvider
35 : public metrics::MetricsProvider {
36 public:
37 enum FileType {
38 // "Atomic" files are a collection of histograms that are written
39 // completely in a single atomic operation (typically a write followed
40 // by an atomic rename) and the file is never updated again except to
41 // be replaced by a completely new set of histograms. This is the only
42 // option that can be used if the file is not writeable by *this*
43 // process.
44 FILE_HISTOGRAMS_ATOMIC,
45
46 // "Active" files may be open by one or more other processes and updated
47 // at any time with new samples or new histograms. Such files may also be
48 // inactive for any period of time only to be opened again and have new
49 // data written to them. The file should probably never be deleted because
50 // there would be no guarantee that the data has been reported.
51 // TODO(bcwhite): Enable when read/write mem-mapped files are supported.
52 //FILE_HISTOGRAMS_ACTIVE,
53 };
54
55 private:
56 // Information about files being monitored, defined and used exclusively
57 // inside the .cc file.
58 struct FileInformation;
59
60 public:
61 using FileInformationList = std::list<scoped_ptr<FileInformation>>;
62
63 FileMetricsProvider(const scoped_refptr<base::TaskRunner>& task_runner,
64 PrefService* local_state);
65 ~FileMetricsProvider() override;
66
67 // Indicate a file to be monitored and how the file is used. Because some
68 // metadata must persist across process restarts, preferences entries are
69 // used based on the |prefs_key| name. Call RegisterPrefs() with the same
70 // name to create the necessary keys in advance.
71 void RegisterFile(const base::FilePath& path, FileType type,
72 const base::StringPiece& prefs_key);
73
74 static void RegisterPrefs(PrefRegistrySimple* prefs,
75 const base::StringPiece& key);
76
77 private:
78 friend class FileMetricsProviderTest;
79 FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics);
80
81 static void CheckAndMapNewMetricFilesOnTaskRunner(
82 FileInformationList* files);
83 static bool CheckAndMapNewMetrics(FileInformation* file);
84
85 void ScheduleFilesCheck();
86 void RecordFilesChecked(FileInformationList* checked);
87 void RecordFileAsSeen(FileInformation* file);
88
89 // metrics::MetricsDataProvider:
90 void OnDidCreateMetricsLog() override;
91 void RecordHistogramSnapshots(base::HistogramSnapshotManager* hsm) override;
92
93 base::WeakPtrFactory<FileMetricsProvider> weak_factory_;
grt (UTC plus 2) 2016/02/15 19:53:55 move this down so it's the last data member as per
bcwhite 2016/02/15 21:46:00 Done.
94 scoped_refptr<base::TaskRunner> task_runner_;
95 FileInformationList files_to_check_;
96 FileInformationList files_to_read_;
97 PrefService* pref_service_;
98
99 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider);
100 };
101
102 } // namespace metrics
103
104 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
OLDNEW
« no previous file with comments | « components/metrics/BUILD.gn ('k') | components/metrics/file_metrics_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698