1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_KEY_BUILDER_H_
6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_KEY_BUILDER_H_
10 #include "chrome/browser/performance_monitor/event.h"
11 #include "chrome/browser/performance_monitor/metric.h"
13 namespace performance_monitor
{
16 RecentKey(const std::string
& recent_time
,
17 MetricType recent_type
,
18 const std::string
& recent_activity
);
21 const std::string time
;
22 const MetricType type
;
23 const std::string activity
;
27 MaxValueKey(MetricType max_value_type
,
28 const std::string
& max_value_activity
)
29 : type(max_value_type
),
30 activity(max_value_activity
) {}
33 const MetricType type
;
34 const std::string activity
;
38 MetricKey(const std::string
& metric_time
,
39 MetricType metric_type
,
40 const std::string
& metric_activity
);
43 const std::string time
;
44 const MetricType type
;
45 const std::string activity
;
48 // This class is responsible for building the keys which are used internally by
49 // PerformanceMonitor's database. These keys should only be referenced by the
50 // database, and should not be used externally.
56 // Key Creation: Create the keys for different databases. The schemas are
57 // listed with the methods. A '-' in the schema represents kDelimeter.
60 std::string
CreateActiveIntervalKey(const base::Time
& time
);
62 // Key Schema: <Metric>-<Time>-<Activity>
63 std::string
CreateMetricKey(const base::Time
& time
,
64 const MetricType type
,
65 const std::string
& activity
);
67 // Key Schema: <Time>-<Event Type>
68 std::string
CreateEventKey(const base::Time
& time
, const EventType type
);
70 // Key Schema: <Time>-<Metric>-<Activity>
71 std::string
CreateRecentKey(const base::Time
& time
,
72 const MetricType type
,
73 const std::string
& activity
);
75 // Key Schema: <Activity>-<Metric>
76 std::string
CreateRecentMapKey(const MetricType type
,
77 const std::string
& activity
);
79 std::string
CreateMaxValueKey(const MetricType type
,
80 const std::string
& activity
);
82 EventType
EventKeyToEventType(const std::string
& key
);
83 RecentKey
SplitRecentKey(const std::string
& key
);
84 MetricKey
SplitMetricKey(const std::string
& key
);
87 // Populate the maps from [Event, Metric]Type to key characters.
88 void PopulateKeyMaps();
90 std::map
<EventType
, int> event_type_to_event_key_char_
;
91 std::map
<int, EventType
> event_key_char_to_event_type_
;
92 std::map
<MetricType
, int> metric_type_to_metric_key_char_
;
93 std::map
<int, MetricType
> metric_key_char_to_metric_type_
;
96 } // namespace performance_monitor
98 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_KEY_BUILDER_H_