// Copyright (c) 2012 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. #include "chrome/browser/performance_monitor/database.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/format_macros.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/logging.h" #include "base/path_service.h" #include "base/string_number_conversions.h" #include "base/string_split.h" #include "base/stringprintf.h" #include "base/time.h" #include "base/utf_string_conversions.h" #include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_thread.h" #include "third_party/leveldatabase/src/include/leveldb/db.h" namespace { const char kDbDir[] = "Performance Monitor Databases"; const char kRecentDb[] = "Recent Metrics"; const char kEventDb[] = "Events"; const char kStateDb[] = "Configuration"; const char kActiveIntervalDb[] = "Active Interval"; const char kMetricDb[] = "Metrics"; const char kDelimiter = '!'; struct RecentKey { RecentKey(const std::string& recent_time, const std::string& recent_metric, const std::string& recent_activity) : time(recent_time), metric(recent_metric), activity(recent_activity) {} ~RecentKey() {} const std::string time; const std::string metric; const std::string activity; }; struct MetricKey { MetricKey(const std::string& metric_time, const std::string& metric_metric, const std::string& metric_activity) : time(metric_time), metric(metric_metric), activity(metric_activity) {} ~MetricKey() {} const std::string time; const std::string metric; const std::string activity; }; // The position of different elements in the key for the event db. enum EventKeyPosition { EVENT_TIME, // The time the event was generated. EVENT_TYPE // The type of event. }; // The position of different elements in the key for the recent db. enum RecentKeyPosition { RECENT_TIME, // The time the stat was gathered. RECENT_METRIC, // The unique identifier for the type of metric gathered. RECENT_ACTIVITY // The unique identifier for the activity. }; // The position of different elements in the key for a metric db. enum MetricKeyPosition { METRIC_METRIC, // The unique identifier for the metric. METRIC_TIME, // The time the stat was gathered. METRIC_ACTIVITY // The unique identifier for the activity. }; // If the db is quiet for this number of microseconds, then it is considered // down. const base::TimeDelta kActiveIntervalTimeout = base::TimeDelta::FromSeconds(5); // Create the key used for internal active interval monitoring. // Key Schema: