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

Unified Diff: chrome/browser/net/cache_stats.h

Issue 10736066: Adding histograms showing fraction of page load times (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
Index: chrome/browser/net/cache_stats.h
===================================================================
--- chrome/browser/net/cache_stats.h (revision 0)
+++ chrome/browser/net/cache_stats.h (revision 0)
@@ -0,0 +1,109 @@
+// 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.
+
+#ifndef CHROME_BROWSER_NET_CACHE_STATS_H_
+#define CHROME_BROWSER_NET_CACHE_STATS_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/hash_tables.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/singleton.h"
+#include "base/message_loop.h"
+#include "base/time.h"
+#include "content/public/browser/render_view_host_observer.h"
+#include "net/base/network_delegate.h"
+
+class TabContents;
+
+namespace base {
+class Histogram;
+}
+
+namespace net {
+class URLRequest;
+}
+
+namespace chrome_browser_net {
+
+// This class collects UMA stats about cache performance. It is a singleton
+// and lives on the IO thread.
+
rvargas (doing something else) 2012/07/23 22:22:36 nit: remove line
tburkard 2012/07/24 01:03:12 Done.
+class CacheStats : public MessageLoop::DestructionObserver {
+ public:
+ enum TabEvent {
+ SPINNER_START,
+ SPINNER_STOP,
+ RENDERER_DESTROY
+ };
+ static CacheStats* GetInstance();
+ void OnCacheWaitStateChange(const net::URLRequest& request,
+ net::NetworkDelegate::CacheWaitState state);
+ void OnTabEvent(std::pair<int, int> render_view_id, TabEvent event);
+ virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
+ virtual ~CacheStats();
+
+ private:
+ friend struct DefaultSingletonTraits<CacheStats>;
+ struct TabLoadStats;
+ typedef std::map< std::pair<int, int>, TabLoadStats*> TabLoadStatsMap;
rvargas (doing something else) 2012/07/23 22:22:36 nit: remove extra space before std
tburkard 2012/07/24 01:03:12 Done.
+
+ CacheStats();
+ // Gets TabLoadStats for a given render view.
+ TabLoadStats* GetTabLoadStats(std::pair<int, int> render_view_id);
+ // Deletes TabLoadStats no longer needed for a render view.
+ void RemoveTabLoadStats(std::pair<int, int> render_view_id);
+ // Sets a timer for a given tab to collect stats. timer_index indicates
+ // how many times stats have been collected since the navigation has started
+ // for this tab.
+ void ScheduleTimer(TabLoadStats* stats, int timer_index);
+ // The callback when a timer fires to collect stats again.
+ void TimerCb(TabLoadStats* stats, int timer_index);
+ // Helper function to put the current set of cache statistics into an UMA
+ // histogram.
+ void RecordCacheFractionHistogram(base::TimeDelta elapsed,
+ base::TimeDelta cache_time,
+ bool is_load_done);
+
+ TabLoadStatsMap tab_load_stats_;
+ std::vector<base::Histogram*> final_histograms_;
+ std::vector<base::Histogram*> intermediate_histograms_;
+ bool registered_message_loop_destruction_observer_;
+};
+
+// Helper class observing all RenderViewHosts, notifying CacheStats
+// whenever the spinner starts or stops for a given tab, and when a renderer
+// is no longer used.
+
rvargas (doing something else) 2012/07/23 22:22:36 nit: remove line
tburkard 2012/07/24 01:03:12 Done.
+class CacheStatsRenderViewHostObserver
+ : public content::RenderViewHostObserver {
+ public:
+ explicit CacheStatsRenderViewHostObserver(content::RenderViewHost* host);
+
+ protected:
+ virtual ~CacheStatsRenderViewHostObserver();
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ private:
+ // Calls into CacheStats to notify that a reportable event has occurred
+ // for the tab being observed.
+ void NotifyCacheStats(CacheStats::TabEvent event);
+ void OnDidStartProvisionalLoadForFrame(
+ int64 frame_id,
+ bool is_main_frame,
+ const GURL& opener_url,
+ const GURL& url);
+ void OnDidStopLoading();
+
+ CacheStats* cache_stats_;
+ std::pair<int, int> render_view_id_;
+ bool is_loading_;
+};
+
+} // namespace chrome_browser_net
+
+#endif // CHROME_BROWSER_NET_CACHE_STATS_H_

Powered by Google App Engine
This is Rietveld 408576698