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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/metrics/file_metrics_provider.h
diff --git a/components/metrics/file_metrics_provider.h b/components/metrics/file_metrics_provider.h
new file mode 100644
index 0000000000000000000000000000000000000000..0def5c58540c31b0bb2edbf9167676ee7991810a
--- /dev/null
+++ b/components/metrics/file_metrics_provider.h
@@ -0,0 +1,106 @@
+// Copyright 2016 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_METRICS_FILE_METRICS_PROVIDER_H_
+#define COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
+
+#include <list>
+#include <string>
+
+#include "base/callback.h"
+#include "base/files/file_path.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "base/time/time.h"
+#include "components/metrics/metrics_provider.h"
+
+class PrefRegistrySimple;
+class PrefService;
+
+namespace base {
+class MemoryMappedFile;
+class PersistentMemoryAllocator;
+class TaskRunner;
+}
+
+namespace metrics {
+
+// FileMetricsProvider gathers and logs histograms written to files on disk.
+// Any number of files can be registered and will be polled once per upload
+// cycle (at startup and about every 30 minutes thereafter) for data to send.
+class FileMetricsProvider
+ : 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.
+ public:
+ enum FileType {
+ // "Atomic" files are a collection of histograms that are written
+ // completely in a single atomic operation (typically a write followed
+ // by an atomic rename) and the file is never updated again except to
+ // be replaced by a completely new set of histograms. This is the only
+ // option that can be used if the file is not writeable by *this*
+ // process.
+ FILE_HISTOGRAMS_ATOMIC,
+
+ // "Active" files may be open by one or more other processes and updated
+ // at any time with new samples or new histograms. Such files may also be
+ // inactive for any period of time only to be opened again and have new
+ // data written to them. The file should probably never be deleted because
+ // there would be no guarantee that the data has been reported.
+ // TODO(bcwhite): Enable when read/write mem-mapped files are supported.
+ //FILE_HISTOGRAMS_ACTIVE,
+ };
+
+ private:
+ // Information about files being monitored, defined and used exclusively
+ // inside the .cc file.
+ 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
+
+ public:
+ 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.
+
+ FileMetricsProvider(const scoped_refptr<base::TaskRunner>& task_runner,
+ PrefService* local_state);
+ ~FileMetricsProvider() override;
+
+ // Indicate a file to be monitored and how the file is used. Because some
+ // metadata must persist across process restarts, preferences entries are
+ // used based on the |prefs_key| name. Call RegisterPrefs() with the same
+ // name to create the necessary keys in advance.
+ void RegisterFile(const base::FilePath& path, FileType type,
+ 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.
+
+ 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.
+ const base::StringPiece& key);
+
+ private:
+ friend class FileMetricsProviderTest;
+ FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics);
+
+ 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.
+ FileInformationList* files);
+ static void CheckAndMapNewMetrics(FileInformation* file);
+
+ void ScheduleFilesCheck();
+ void RecordFilesChecked(FileInformationList* checked);
+ void RecordFileAsSeen(FileInformation* file);
+
+ // metrics::MetricsDataProvider:
+ void OnDidCreateMetricsLog() override;
+ void RecordHistogramSnapshots(base::HistogramSnapshotManager* hsm) override;
+
+ scoped_refptr<base::TaskRunner> task_runner_;
+ 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.
+ FileInformationList files_to_read_;
+ PrefService* pref_service_;
+
+ base::ThreadChecker thread_checker_;
+ base::WeakPtrFactory<FileMetricsProvider> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider);
+};
+
+} // namespace metrics
+
+#endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_

Powered by Google App Engine
This is Rietveld 408576698