OLD | NEW |
---|---|
(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/threading/thread_checker.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 { | |
Alexei Svitkine (slow)
2016/02/17 21:55:35
Nit: Fits on line above?
bcwhite
2016/02/18 01:46:57
Done.
| |
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; | |
Alexei Svitkine (slow)
2016/02/17 21:55:35
Nit: How about FileInfo and FileInfoList to make t
bcwhite
2016/02/18 01:46:57
Heh. I think this is the first time I've been ask
| |
59 | |
60 public: | |
61 using FileInformationList = std::list<scoped_ptr<FileInformation>>; | |
Alexei Svitkine (slow)
2016/02/17 21:55:35
Can this be moved to the private: section below? A
bcwhite
2016/02/18 01:46:57
Done.
| |
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); | |
Alexei Svitkine (slow)
2016/02/17 21:55:35
Pass by value. Same below.
bcwhite
2016/02/18 01:46:57
Done.
| |
73 | |
74 static void RegisterPrefs(PrefRegistrySimple* prefs, | |
Alexei Svitkine (slow)
2016/02/17 21:55:35
Add a comment.
bcwhite
2016/02/18 01:46:57
Done.
| |
75 const base::StringPiece& key); | |
76 | |
77 private: | |
78 friend class FileMetricsProviderTest; | |
79 FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics); | |
80 | |
81 static void CheckAndMapNewMetricFilesOnTaskRunner( | |
Alexei Svitkine (slow)
2016/02/17 21:55:35
Please add a short comment for each of these.
bcwhite
2016/02/18 01:46:57
Done.
| |
82 FileInformationList* files); | |
83 static void 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 scoped_refptr<base::TaskRunner> task_runner_; | |
94 FileInformationList files_to_check_; | |
Alexei Svitkine (slow)
2016/02/17 21:55:35
Add comments about all these members except for ob
bcwhite
2016/02/18 01:46:57
Done.
| |
95 FileInformationList files_to_read_; | |
96 PrefService* pref_service_; | |
97 | |
98 base::ThreadChecker thread_checker_; | |
99 base::WeakPtrFactory<FileMetricsProvider> weak_factory_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider); | |
102 }; | |
103 | |
104 } // namespace metrics | |
105 | |
106 #endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_ | |
OLD | NEW |