| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/renderer/renderer_histogram_snapshots.h" | 5 #include "chrome/renderer/renderer_histogram_snapshots.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
| 13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 14 #include "chrome/renderer/render_process.h" | 14 #include "chrome/renderer/render_process.h" |
| 15 #include "chrome/renderer/render_thread.h" | 15 #include "chrome/renderer/render_thread.h" |
| 16 | 16 |
| 17 // TODO(raman): Before renderer shuts down send final snapshot lists. | 17 // TODO(raman): Before renderer shuts down send final snapshot lists. |
| 18 | 18 |
| 19 RendererHistogramSnapshots::RendererHistogramSnapshots() | 19 RendererHistogramSnapshots::RendererHistogramSnapshots() |
| 20 : ALLOW_THIS_IN_INITIALIZER_LIST( | 20 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 21 renderer_histogram_snapshots_factory_(this)) { | 21 renderer_histogram_snapshots_factory_(this)) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 // Send data quickly! | 24 // Send data quickly! |
| 25 void RendererHistogramSnapshots::SendHistograms() { | 25 void RendererHistogramSnapshots::SendHistograms(int sequence_number) { |
| 26 RenderThread::current()->message_loop()->PostTask(FROM_HERE, | 26 RenderThread::current()->message_loop()->PostTask(FROM_HERE, |
| 27 renderer_histogram_snapshots_factory_.NewRunnableMethod( | 27 renderer_histogram_snapshots_factory_.NewRunnableMethod( |
| 28 &RendererHistogramSnapshots::UploadAllHistrograms)); | 28 &RendererHistogramSnapshots::UploadAllHistrograms, sequence_number)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void RendererHistogramSnapshots::UploadAllHistrograms() { | 31 void RendererHistogramSnapshots::UploadAllHistrograms(int sequence_number) { |
| 32 StatisticsRecorder::Histograms histograms; | 32 StatisticsRecorder::Histograms histograms; |
| 33 StatisticsRecorder::GetHistograms(&histograms); | 33 StatisticsRecorder::GetHistograms(&histograms); |
| 34 | 34 |
| 35 HistogramPickledList pickled_histograms; | 35 HistogramPickledList pickled_histograms; |
| 36 | 36 |
| 37 for (StatisticsRecorder::Histograms::iterator it = histograms.begin(); | 37 for (StatisticsRecorder::Histograms::iterator it = histograms.begin(); |
| 38 histograms.end() != it; | 38 histograms.end() != it; |
| 39 it++) { | 39 it++) { |
| 40 UploadHistrogram(**it, &pickled_histograms); | 40 UploadHistrogram(**it, &pickled_histograms); |
| 41 } | 41 } |
| 42 // Send the handle over synchronous IPC. | 42 // Send the sequence number and list of pickled histograms over synchronous |
| 43 if (pickled_histograms.size() > 0) { | 43 // IPC. |
| 44 RenderThread::current()->Send( | 44 RenderThread::current()->Send( |
| 45 new ViewHostMsg_RendererHistograms(pickled_histograms)); | 45 new ViewHostMsg_RendererHistograms( |
| 46 } | 46 sequence_number, pickled_histograms)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Extract snapshot data and then send it off the the Browser process | 49 // Extract snapshot data and then send it off the the Browser process |
| 50 // to save it. | 50 // to save it. |
| 51 void RendererHistogramSnapshots::UploadHistrogram( | 51 void RendererHistogramSnapshots::UploadHistrogram( |
| 52 const Histogram& histogram, | 52 const Histogram& histogram, |
| 53 HistogramPickledList* pickled_histograms) { | 53 HistogramPickledList* pickled_histograms) { |
| 54 | 54 |
| 55 // Get up-to-date snapshot of sample stats. | 55 // Get up-to-date snapshot of sample stats. |
| 56 Histogram::SampleSet snapshot; | 56 Histogram::SampleSet snapshot; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 const Histogram::SampleSet& snapshot, | 84 const Histogram::SampleSet& snapshot, |
| 85 HistogramPickledList* pickled_histograms) { | 85 HistogramPickledList* pickled_histograms) { |
| 86 | 86 |
| 87 DCHECK(0 != snapshot.TotalCount()); | 87 DCHECK(0 != snapshot.TotalCount()); |
| 88 snapshot.CheckSize(histogram); | 88 snapshot.CheckSize(histogram); |
| 89 | 89 |
| 90 std::string histogram_info = | 90 std::string histogram_info = |
| 91 Histogram::SerializeHistogramInfo(histogram, snapshot); | 91 Histogram::SerializeHistogramInfo(histogram, snapshot); |
| 92 pickled_histograms->push_back(histogram_info); | 92 pickled_histograms->push_back(histogram_info); |
| 93 } | 93 } |
| OLD | NEW |