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 #include "chrome/browser/net/http_pipelining_compatibility_client.h" | 5 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 119 } |
120 | 120 |
121 MessageLoopForIO message_loop_; | 121 MessageLoopForIO message_loop_; |
122 net::TestServer test_server_; | 122 net::TestServer test_server_; |
123 TestURLRequestContextGetter* context_; | 123 TestURLRequestContextGetter* context_; |
124 content::TestBrowserThread io_thread_; | 124 content::TestBrowserThread io_thread_; |
125 | 125 |
126 private: | 126 private: |
127 base::Histogram::SampleSet GetHistogram(const char* name) { | 127 base::Histogram::SampleSet GetHistogram(const char* name) { |
128 base::Histogram::SampleSet sample; | 128 base::Histogram::SampleSet sample; |
129 base::Histogram* histogram; | 129 base::Histogram* current_histogram = NULL; |
130 base::Histogram* cached_histogram = NULL; | |
131 base::StatisticsRecorder::FindHistogram(name, ¤t_histogram); | |
130 if (ContainsKey(histograms_, name)) { | 132 if (ContainsKey(histograms_, name)) { |
131 histogram = histograms_[name]; | 133 cached_histogram = histograms_[name]; |
132 histogram->SnapshotSample(&sample); | 134 } |
133 } else if (base::StatisticsRecorder::FindHistogram(name, &histogram)) { | 135 |
134 histograms_[name] = histogram; | 136 // This is to work around the CACHE_HISTOGRAM_* macros caching the last used |
135 histogram->SnapshotSample(&sample); | 137 // histogram by name. So, even though we throw out the StatisticsRecorder |
138 // between tests, the CACHE_HISTOGRAM_* might still write into the old | |
139 // Histogram if it has the same name as the last run. We keep a cache of the | |
140 // last used Histogram and then update the cache if it's different than the | |
141 // current Histogram. | |
mmenke
2012/02/23 18:54:58
Why was this working before, but is now causing pr
James Simonsen
2012/02/23 23:49:46
The old version was broken, but just happened to w
| |
142 if (cached_histogram && current_histogram) { | |
143 cached_histogram->SnapshotSample(&sample); | |
144 if (cached_histogram != current_histogram) { | |
145 base::Histogram::SampleSet current_sample; | |
146 current_histogram->SnapshotSample(¤t_sample); | |
147 sample.Add(current_sample); | |
148 histograms_[name] = current_histogram; | |
149 } | |
150 } else if (current_histogram) { | |
151 current_histogram->SnapshotSample(&sample); | |
152 histograms_[name] = current_histogram; | |
153 } else if (cached_histogram) { | |
154 cached_histogram->SnapshotSample(&sample); | |
136 } | 155 } |
137 return sample; | 156 return sample; |
138 } | 157 } |
139 | 158 |
140 static std::map<std::string, base::Histogram*> histograms_; | 159 static std::map<std::string, base::Histogram*> histograms_; |
141 std::map<std::string, base::Histogram::SampleSet> samples_; | 160 std::map<std::string, base::Histogram::SampleSet> samples_; |
142 std::map<std::string, base::Histogram::SampleSet> original_samples_; | 161 std::map<std::string, base::Histogram::SampleSet> original_samples_; |
143 base::StatisticsRecorder recorder_; | 162 base::StatisticsRecorder recorder_; |
144 }; | 163 }; |
145 | 164 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 | 427 |
409 base::Histogram::SampleSet status_sample2 = | 428 base::Histogram::SampleSet status_sample2 = |
410 GetHistogramValue(1, FIELD_STATUS); | 429 GetHistogramValue(1, FIELD_STATUS); |
411 EXPECT_EQ(1, status_sample2.TotalCount()); | 430 EXPECT_EQ(1, status_sample2.TotalCount()); |
412 EXPECT_EQ(1, status_sample2.counts( | 431 EXPECT_EQ(1, status_sample2.counts( |
413 HttpPipeliningCompatibilityClient::NETWORK_ERROR)); | 432 HttpPipeliningCompatibilityClient::NETWORK_ERROR)); |
414 | 433 |
415 base::Histogram::SampleSet network_sample2 = | 434 base::Histogram::SampleSet network_sample2 = |
416 GetHistogramValue(1, FIELD_NETWORK_ERROR); | 435 GetHistogramValue(1, FIELD_NETWORK_ERROR); |
417 EXPECT_EQ(1, network_sample2.TotalCount()); | 436 EXPECT_EQ(1, network_sample2.TotalCount()); |
418 EXPECT_EQ(1, network_sample2.counts(-net::ERR_EMPTY_RESPONSE)); | 437 EXPECT_EQ(1, network_sample2.counts(-net::ERR_PIPELINE_EVICTION)); |
419 | 438 |
420 base::Histogram::SampleSet response_sample2 = | 439 base::Histogram::SampleSet response_sample2 = |
421 GetHistogramValue(1, FIELD_RESPONSE_CODE); | 440 GetHistogramValue(1, FIELD_RESPONSE_CODE); |
422 EXPECT_EQ(0, response_sample2.TotalCount()); | 441 EXPECT_EQ(0, response_sample2.TotalCount()); |
423 | 442 |
424 base::Histogram::SampleSet status_sample3 = | 443 base::Histogram::SampleSet status_sample3 = |
425 GetHistogramValue(2, FIELD_STATUS); | 444 GetHistogramValue(2, FIELD_STATUS); |
426 EXPECT_EQ(1, status_sample3.TotalCount()); | 445 EXPECT_EQ(1, status_sample3.TotalCount()); |
427 EXPECT_EQ(1, status_sample3.counts( | 446 EXPECT_EQ(1, status_sample3.counts( |
428 HttpPipeliningCompatibilityClient::BAD_RESPONSE_CODE)); | 447 HttpPipeliningCompatibilityClient::NETWORK_ERROR)); |
429 | 448 |
430 base::Histogram::SampleSet network_sample3 = | 449 base::Histogram::SampleSet network_sample3 = |
431 GetHistogramValue(2, FIELD_NETWORK_ERROR); | 450 GetHistogramValue(2, FIELD_NETWORK_ERROR); |
432 EXPECT_EQ(0, network_sample3.TotalCount()); | 451 EXPECT_EQ(1, network_sample3.TotalCount()); |
452 EXPECT_EQ(1, network_sample3.counts(-net::ERR_PIPELINE_EVICTION)); | |
433 | 453 |
434 base::Histogram::SampleSet response_sample3 = | 454 base::Histogram::SampleSet response_sample3 = |
435 GetHistogramValue(2, FIELD_RESPONSE_CODE); | 455 GetHistogramValue(2, FIELD_RESPONSE_CODE); |
436 EXPECT_EQ(1, response_sample3.TotalCount()); | 456 EXPECT_EQ(0, response_sample3.TotalCount()); |
437 EXPECT_EQ(1, response_sample3.counts(401)); | |
438 } | 457 } |
439 | 458 |
440 } // anonymous namespace | 459 } // anonymous namespace |
441 | 460 |
442 } // namespace chrome_browser_net | 461 } // namespace chrome_browser_net |
OLD | NEW |