| OLD | NEW |
| 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 Loading... |
| 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_PERCENTAGE, |
| 64 HISTOGRAM_INTERMEDIATE_AGGREGATE, |
| 65 HISTOGRAM_INTERMEDIATE_CUMULATIVE_PERCENTAGE, |
| 66 HISTOGRAM_MAX |
| 67 }; |
| 56 | 68 |
| 57 void OnCacheWaitStateChange(const net::URLRequest& request, | 69 LoadTimeStats(); |
| 58 net::NetworkDelegate::CacheWaitState state); | 70 ~LoadTimeStats(); |
| 71 |
| 72 void OnRequestWaitStateChange(const net::URLRequest& request, |
| 73 net::NetworkDelegate::RequestWaitState state); |
| 59 void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event); | 74 void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event); |
| 60 void RegisterURLRequestContext(const net::URLRequestContext* context, | 75 void RegisterURLRequestContext(const net::URLRequestContext* context, |
| 61 ChromeURLRequestContext::ContextType type); | 76 ChromeURLRequestContext::ContextType type); |
| 62 void UnregisterURLRequestContext(const net::URLRequestContext* context); | 77 void UnregisterURLRequestContext(const net::URLRequestContext* context); |
| 63 | 78 |
| 64 private: | 79 private: |
| 65 struct TabLoadStats; | 80 class TabLoadStats; |
| 66 // A map mapping a renderer's process id and route id to a TabLoadStats, | 81 // A map mapping a renderer's process id and route id to a TabLoadStats, |
| 67 // representing that renderer's load statistics. | 82 // representing that renderer's load statistics. |
| 68 typedef std::map<std::pair<int, int>, TabLoadStats*> TabLoadStatsMap; | 83 typedef std::map<std::pair<int, int>, TabLoadStats*> TabLoadStatsMap; |
| 69 | 84 |
| 70 // Gets TabLoadStats for a given RenderView. | 85 // Gets TabLoadStats for a given RenderView. |
| 71 TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id); | 86 TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id); |
| 72 // Deletes TabLoadStats no longer needed for a render view. | 87 // Deletes TabLoadStats no longer needed for a render view. |
| 73 void RemoveTabLoadStats(std::pair<int, int> render_view_id); | 88 void RemoveTabLoadStats(std::pair<int, int> render_view_id); |
| 74 // Sets a timer for a given tab to collect stats. |timer_index| indicates | 89 // 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 | 90 // how many times stats have been collected since the navigation has started |
| 76 // for this tab. | 91 // for this tab. |
| 77 void ScheduleTimer(TabLoadStats* stats); | 92 void ScheduleTimer(TabLoadStats* stats); |
| 78 // The callback when a timer fires to collect stats again. | 93 // The callback when a timer fires to collect stats again. |
| 79 void TimerCallback(TabLoadStats* stats); | 94 void TimerCallback(TabLoadStats* stats); |
| 80 // Helper function to put the current set of cache statistics into an UMA | 95 // Helper function to put the current set of statistics into UMA histograms. |
| 81 // histogram. | 96 void RecordHistograms(base::TimeDelta elapsed, |
| 82 void RecordCacheFractionHistogram(base::TimeDelta elapsed, | 97 TabLoadStats* stats, |
| 83 base::TimeDelta cache_time, | 98 bool is_load_done); |
| 84 bool is_load_done, | |
| 85 int timer_index); | |
| 86 | 99 |
| 87 TabLoadStatsMap tab_load_stats_; | 100 TabLoadStatsMap tab_load_stats_; |
| 88 std::vector<base::Histogram*> final_histograms_; | 101 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_; | 102 base::hash_set<const net::URLRequestContext*> main_request_contexts_; |
| 91 | 103 |
| 92 DISALLOW_COPY_AND_ASSIGN(CacheStats); | 104 DISALLOW_COPY_AND_ASSIGN(LoadTimeStats); |
| 93 }; | 105 }; |
| 94 | 106 |
| 95 // A WebContentsObserver watching all tabs, notifying CacheStats | 107 // A WebContentsObserver watching all tabs, notifying LoadTimeStats |
| 96 // whenever the spinner starts or stops for a given tab, and when a renderer | 108 // whenever the spinner starts or stops for a given tab, and when a renderer |
| 97 // is no longer used. | 109 // is no longer used. |
| 98 class CacheStatsTabHelper : public content::WebContentsObserver { | 110 class LoadTimeStatsTabHelper : public content::WebContentsObserver { |
| 99 public: | 111 public: |
| 100 explicit CacheStatsTabHelper(TabContents* tab); | 112 explicit LoadTimeStatsTabHelper(TabContents* tab); |
| 101 virtual ~CacheStatsTabHelper(); | 113 virtual ~LoadTimeStatsTabHelper(); |
| 102 | 114 |
| 103 // content::WebContentsObserver implementation | 115 // content::WebContentsObserver implementation |
| 104 virtual void DidStartProvisionalLoadForFrame( | 116 virtual void DidStartProvisionalLoadForFrame( |
| 105 int64 frame_id, | 117 int64 frame_id, |
| 106 bool is_main_frame, | 118 bool is_main_frame, |
| 107 const GURL& validated_url, | 119 const GURL& validated_url, |
| 108 bool is_error_page, | 120 bool is_error_page, |
| 109 content::RenderViewHost* render_view_host) OVERRIDE; | 121 content::RenderViewHost* render_view_host) OVERRIDE; |
| 110 virtual void DidStopLoading( | 122 virtual void DidStopLoading( |
| 111 content::RenderViewHost* render_view_host) OVERRIDE; | 123 content::RenderViewHost* render_view_host) OVERRIDE; |
| 112 | 124 |
| 113 private: | 125 private: |
| 114 // Calls into CacheStats to notify that a reportable event has occurred | 126 // Calls into LoadTimeStats to notify that a reportable event has occurred |
| 115 // for the tab being observed. | 127 // for the tab being observed. |
| 116 void NotifyCacheStats(CacheStats::TabEvent event, | 128 void NotifyLoadTimeStats(LoadTimeStats::TabEvent event, |
| 117 content::RenderViewHost* render_view_host); | 129 content::RenderViewHost* render_view_host); |
| 118 | 130 |
| 119 CacheStats* cache_stats_; | |
| 120 bool is_otr_profile_; | 131 bool is_otr_profile_; |
| 121 | 132 |
| 122 DISALLOW_COPY_AND_ASSIGN(CacheStatsTabHelper); | 133 DISALLOW_COPY_AND_ASSIGN(LoadTimeStatsTabHelper); |
| 123 }; | 134 }; |
| 124 | 135 |
| 125 } // namespace chrome_browser_net | 136 } // namespace chrome_browser_net |
| 126 | 137 |
| 127 #endif // CHROME_BROWSER_NET_CACHE_STATS_H_ | 138 #endif // CHROME_BROWSER_NET_LOAD_TIME_STATS_H_ |
| OLD | NEW |