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

Side by Side Diff: chrome/browser/net/load_time_stats.h

Issue 10834313: Add histograms for network activity, and total/cumulative (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NET_CACHE_STATS_H_ 5 #ifndef CHROME_BROWSER_NET_LOAD_TIME_STATS_H_
6 #define CHROME_BROWSER_NET_CACHE_STATS_H_ 6 #define CHROME_BROWSER_NET_LOAD_TIME_STATS_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/time.h" 16 #include "base/time.h"
(...skipping 21 matching lines...) Expand all
38 return reinterpret_cast<std::size_t>(value); 38 return reinterpret_cast<std::size_t>(value);
39 } 39 }
40 }; 40 };
41 } 41 }
42 42
43 #endif 43 #endif
44 44
45 namespace chrome_browser_net { 45 namespace chrome_browser_net {
46 46
47 // This class collects UMA stats about cache performance. 47 // This class collects UMA stats about cache performance.
48 class CacheStats { 48 class LoadTimeStats {
49 public: 49 public:
50 enum TabEvent { 50 enum TabEvent {
51 SPINNER_START, 51 SPINNER_START,
52 SPINNER_STOP 52 SPINNER_STOP
53 }; 53 };
54 CacheStats(); 54 enum RequestStatus {
55 ~CacheStats(); 55 REQUEST_STATUS_CACHE_WAIT,
56 REQUEST_STATUS_NETWORK_WAIT,
57 REQUEST_STATUS_ACTIVE,
58 REQUEST_STATUS_NONE,
59 REQUEST_STATUS_MAX
60 };
61 enum HistogramType {
62 HISTOGRAM_FINAL_AGGREGATE,
63 HISTOGRAM_FINAL_CUMULATIVE,
64 HISTOGRAM_FINAL_CUMULATIVE_PERCENTAGE,
65 HISTOGRAM_INTERMEDIATE_AGGREGATE,
66 HISTOGRAM_INTERMEDIATE_CUMULATIVE,
67 HISTOGRAM_INTERMEDIATE_CUMULATIVE_PERCENTAGE,
68 HISTOGRAM_MAX
69 };
56 70
57 void OnCacheWaitStateChange(const net::URLRequest& request, 71 LoadTimeStats();
58 net::NetworkDelegate::CacheWaitState state); 72 ~LoadTimeStats();
73
74 void OnRequestWaitStateChange(const net::URLRequest& request,
75 net::NetworkDelegate::RequestWaitState state);
59 void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event); 76 void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event);
60 void RegisterURLRequestContext(const net::URLRequestContext* context, 77 void RegisterURLRequestContext(const net::URLRequestContext* context,
61 ChromeURLRequestContext::ContextType type); 78 ChromeURLRequestContext::ContextType type);
62 void UnregisterURLRequestContext(const net::URLRequestContext* context); 79 void UnregisterURLRequestContext(const net::URLRequestContext* context);
63 80
64 private: 81 private:
65 struct TabLoadStats; 82 class TabLoadStats;
66 // A map mapping a renderer's process id and route id to a TabLoadStats, 83 // A map mapping a renderer's process id and route id to a TabLoadStats,
67 // representing that renderer's load statistics. 84 // representing that renderer's load statistics.
68 typedef std::map<std::pair<int, int>, TabLoadStats*> TabLoadStatsMap; 85 typedef std::map<std::pair<int, int>, TabLoadStats*> TabLoadStatsMap;
69 86
70 // Gets TabLoadStats for a given RenderView. 87 // Gets TabLoadStats for a given RenderView.
71 TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id); 88 TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id);
72 // Deletes TabLoadStats no longer needed for a render view. 89 // Deletes TabLoadStats no longer needed for a render view.
73 void RemoveTabLoadStats(std::pair<int, int> render_view_id); 90 void RemoveTabLoadStats(std::pair<int, int> render_view_id);
74 // Sets a timer for a given tab to collect stats. |timer_index| indicates 91 // Sets a timer for a given tab to collect stats. |timer_index| indicates
75 // how many times stats have been collected since the navigation has started 92 // how many times stats have been collected since the navigation has started
76 // for this tab. 93 // for this tab.
77 void ScheduleTimer(TabLoadStats* stats); 94 void ScheduleTimer(TabLoadStats* stats);
78 // The callback when a timer fires to collect stats again. 95 // The callback when a timer fires to collect stats again.
79 void TimerCallback(TabLoadStats* stats); 96 void TimerCallback(TabLoadStats* stats);
80 // Helper function to put the current set of cache statistics into an UMA 97 // Helper function to put the current set of statistics into UMA histograms.
81 // histogram. 98 void RecordHistograms(base::TimeDelta elapsed,
82 void RecordCacheFractionHistogram(base::TimeDelta elapsed, 99 TabLoadStats* stats,
83 base::TimeDelta cache_time, 100 bool is_load_done);
84 bool is_load_done,
85 int timer_index);
86 101
87 TabLoadStatsMap tab_load_stats_; 102 TabLoadStatsMap tab_load_stats_;
88 std::vector<base::Histogram*> final_histograms_; 103 std::vector<base::Histogram*> histograms_[REQUEST_STATUS_MAX][HISTOGRAM_MAX];
89 std::vector<base::Histogram*> intermediate_histograms_;
90 base::hash_set<const net::URLRequestContext*> main_request_contexts_; 104 base::hash_set<const net::URLRequestContext*> main_request_contexts_;
91 105
92 DISALLOW_COPY_AND_ASSIGN(CacheStats); 106 DISALLOW_COPY_AND_ASSIGN(LoadTimeStats);
93 }; 107 };
94 108
95 // A WebContentsObserver watching all tabs, notifying CacheStats 109 // A WebContentsObserver watching all tabs, notifying LoadTimeStats
96 // whenever the spinner starts or stops for a given tab, and when a renderer 110 // whenever the spinner starts or stops for a given tab, and when a renderer
97 // is no longer used. 111 // is no longer used.
98 class CacheStatsTabHelper : public content::WebContentsObserver { 112 class LoadTimeStatsTabHelper : public content::WebContentsObserver {
99 public: 113 public:
100 explicit CacheStatsTabHelper(TabContents* tab); 114 explicit LoadTimeStatsTabHelper(TabContents* tab);
101 virtual ~CacheStatsTabHelper(); 115 virtual ~LoadTimeStatsTabHelper();
102 116
103 // content::WebContentsObserver implementation 117 // content::WebContentsObserver implementation
104 virtual void DidStartProvisionalLoadForFrame( 118 virtual void DidStartProvisionalLoadForFrame(
105 int64 frame_id, 119 int64 frame_id,
106 bool is_main_frame, 120 bool is_main_frame,
107 const GURL& validated_url, 121 const GURL& validated_url,
108 bool is_error_page, 122 bool is_error_page,
109 content::RenderViewHost* render_view_host) OVERRIDE; 123 content::RenderViewHost* render_view_host) OVERRIDE;
110 virtual void DidStopLoading( 124 virtual void DidStopLoading(
111 content::RenderViewHost* render_view_host) OVERRIDE; 125 content::RenderViewHost* render_view_host) OVERRIDE;
112 126
113 private: 127 private:
114 // Calls into CacheStats to notify that a reportable event has occurred 128 // Calls into LoadTimeStats to notify that a reportable event has occurred
115 // for the tab being observed. 129 // for the tab being observed.
116 void NotifyCacheStats(CacheStats::TabEvent event, 130 void NotifyLoadTimeStats(LoadTimeStats::TabEvent event,
117 content::RenderViewHost* render_view_host); 131 content::RenderViewHost* render_view_host);
118 132
119 CacheStats* cache_stats_;
120 bool is_otr_profile_; 133 bool is_otr_profile_;
121 134
122 DISALLOW_COPY_AND_ASSIGN(CacheStatsTabHelper); 135 DISALLOW_COPY_AND_ASSIGN(LoadTimeStatsTabHelper);
123 }; 136 };
124 137
125 } // namespace chrome_browser_net 138 } // namespace chrome_browser_net
126 139
127 #endif // CHROME_BROWSER_NET_CACHE_STATS_H_ 140 #endif // CHROME_BROWSER_NET_LOAD_TIME_STATS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698