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

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
« no previous file with comments | « components/metrics/BUILD.gn ('k') | components/metrics/file_metrics_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..180c703404e48695ddc3c0130e235b74d98f94ac
--- /dev/null
+++ b/components/metrics/file_metrics_provider.h
@@ -0,0 +1,104 @@
+// 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/synchronization/lock.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 {
+ 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;
+
+ public:
+ using FileInformationList = std::list<scoped_ptr<FileInformation>>;
+
+ 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);
+
+ static void RegisterPrefs(PrefRegistrySimple* prefs,
+ const base::StringPiece& key);
+
+ private:
+ friend class FileMetricsProviderTest;
+ FRIEND_TEST_ALL_PREFIXES(FileMetricsProviderTest, AccessMetrics);
+
+ static void CheckAndMapNewMetricFilesOnTaskRunner(
+ FileInformationList* files);
+ static bool CheckAndMapNewMetrics(FileInformation* file);
+
+ void ScheduleFilesCheck();
+ void RecordFilesChecked(FileInformationList* checked);
+ void RecordFileAsSeen(FileInformation* file);
+
+ // metrics::MetricsDataProvider:
+ void OnDidCreateMetricsLog() override;
+ void RecordHistogramSnapshots(base::HistogramSnapshotManager* hsm) override;
+
+ 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.
+ scoped_refptr<base::TaskRunner> task_runner_;
+ FileInformationList files_to_check_;
+ FileInformationList files_to_read_;
+ PrefService* pref_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileMetricsProvider);
+};
+
+} // namespace metrics
+
+#endif // COMPONENTS_METRICS_FILE_METRICS_PROVIDER_H_
« 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