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

Side by Side Diff: base/metrics/stats_table_unittest.cc

Issue 10538027: Add shared memory cleanup before/after all tests (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/metrics/stats_counters.h" 5 #include "base/metrics/stats_counters.h"
6 #include "base/metrics/stats_table.h" 6 #include "base/metrics/stats_table.h"
7 #include "base/shared_memory.h" 7 #include "base/shared_memory.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/test/multiprocess_test.h" 10 #include "base/test/multiprocess_test.h"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 TimeTicks start_time() { return start_time_; } 305 TimeTicks start_time() { return start_time_; }
306 TimeTicks stop_time() { return stop_time_; } 306 TimeTicks stop_time() { return stop_time_; }
307 }; 307 };
308 308
309 // Test some basic StatsCounterTimer operations 309 // Test some basic StatsCounterTimer operations
310 TEST_F(StatsTableTest, StatsCounterTimer) { 310 TEST_F(StatsTableTest, StatsCounterTimer) {
311 // Create a stats table. 311 // Create a stats table.
312 const std::string kTableName = "StatTable"; 312 const std::string kTableName = "StatTable";
313 const int kMaxThreads = 20; 313 const int kMaxThreads = 20;
314 const int kMaxCounter = 5; 314 const int kMaxCounter = 5;
315 DeleteShmem(kTableName);
315 StatsTable table(kTableName, kMaxThreads, kMaxCounter); 316 StatsTable table(kTableName, kMaxThreads, kMaxCounter);
316 StatsTable::set_current(&table); 317 StatsTable::set_current(&table);
317 318
318 MockStatsCounterTimer bar("bar"); 319 MockStatsCounterTimer bar("bar");
319 320
320 // Test initial state. 321 // Test initial state.
321 EXPECT_FALSE(bar.Running()); 322 EXPECT_FALSE(bar.Running());
322 EXPECT_TRUE(bar.start_time().is_null()); 323 EXPECT_TRUE(bar.start_time().is_null());
323 EXPECT_TRUE(bar.stop_time().is_null()); 324 EXPECT_TRUE(bar.stop_time().is_null());
324 325
325 const TimeDelta kDuration = TimeDelta::FromMilliseconds(100); 326 const TimeDelta kDuration = TimeDelta::FromMilliseconds(100);
326 327
327 // Do some timing. 328 // Do some timing.
328 bar.Start(); 329 bar.Start();
329 PlatformThread::Sleep(kDuration); 330 PlatformThread::Sleep(kDuration);
330 bar.Stop(); 331 bar.Stop();
331 EXPECT_GT(table.GetCounterValue("t:bar"), 0); 332 EXPECT_GT(table.GetCounterValue("t:bar"), 0);
332 EXPECT_LE(kDuration.InMilliseconds(), table.GetCounterValue("t:bar")); 333 EXPECT_LE(kDuration.InMilliseconds(), table.GetCounterValue("t:bar"));
333 334
334 // Verify that timing again is additive. 335 // Verify that timing again is additive.
335 bar.Start(); 336 bar.Start();
336 PlatformThread::Sleep(kDuration); 337 PlatformThread::Sleep(kDuration);
337 bar.Stop(); 338 bar.Stop();
338 EXPECT_GT(table.GetCounterValue("t:bar"), 0); 339 EXPECT_GT(table.GetCounterValue("t:bar"), 0);
339 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); 340 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar"));
341 DeleteShmem(kTableName);
340 } 342 }
341 343
342 // Test some basic StatsRate operations 344 // Test some basic StatsRate operations
343 // Usually fails on all platforms when run alone. http://crbug.com/131024 345 TEST_F(StatsTableTest, StatsRate) {
344 TEST_F(StatsTableTest, DISABLED_StatsRate) {
345 // Create a stats table. 346 // Create a stats table.
346 const std::string kTableName = "StatTable"; 347 const std::string kTableName = "StatTable";
347 const int kMaxThreads = 20; 348 const int kMaxThreads = 20;
348 const int kMaxCounter = 5; 349 const int kMaxCounter = 5;
350 DeleteShmem(kTableName);
349 StatsTable table(kTableName, kMaxThreads, kMaxCounter); 351 StatsTable table(kTableName, kMaxThreads, kMaxCounter);
350 StatsTable::set_current(&table); 352 StatsTable::set_current(&table);
351 353
352 StatsRate baz("baz"); 354 StatsRate baz("baz");
353 355
354 // Test initial state. 356 // Test initial state.
355 EXPECT_FALSE(baz.Running()); 357 EXPECT_FALSE(baz.Running());
356 EXPECT_EQ(0, table.GetCounterValue("c:baz")); 358 EXPECT_EQ(0, table.GetCounterValue("c:baz"));
357 EXPECT_EQ(0, table.GetCounterValue("t:baz")); 359 EXPECT_EQ(0, table.GetCounterValue("t:baz"));
358 360
359 const TimeDelta kDuration = TimeDelta::FromMilliseconds(100); 361 const TimeDelta kDuration = TimeDelta::FromMilliseconds(100);
360 362
361 // Do some timing. 363 // Do some timing.
362 baz.Start(); 364 baz.Start();
363 PlatformThread::Sleep(kDuration); 365 PlatformThread::Sleep(kDuration);
364 baz.Stop(); 366 baz.Stop();
365 EXPECT_EQ(1, table.GetCounterValue("c:baz")); 367 EXPECT_EQ(1, table.GetCounterValue("c:baz"));
366 EXPECT_LE(kDuration.InMilliseconds(), table.GetCounterValue("t:baz")); 368 EXPECT_LE(kDuration.InMilliseconds(), table.GetCounterValue("t:baz"));
367 369
368 // Verify that timing again is additive. 370 // Verify that timing again is additive.
369 baz.Start(); 371 baz.Start();
370 PlatformThread::Sleep(kDuration); 372 PlatformThread::Sleep(kDuration);
371 baz.Stop(); 373 baz.Stop();
372 EXPECT_EQ(2, table.GetCounterValue("c:baz")); 374 EXPECT_EQ(2, table.GetCounterValue("c:baz"));
373 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:baz")); 375 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:baz"));
376 DeleteShmem(kTableName);
374 } 377 }
375 378
376 // Test some basic StatsScope operations 379 // Test some basic StatsScope operations
377 TEST_F(StatsTableTest, StatsScope) { 380 TEST_F(StatsTableTest, StatsScope) {
378 // Create a stats table. 381 // Create a stats table.
379 const std::string kTableName = "StatTable"; 382 const std::string kTableName = "StatTable";
380 const int kMaxThreads = 20; 383 const int kMaxThreads = 20;
381 const int kMaxCounter = 5; 384 const int kMaxCounter = 5;
382 DeleteShmem(kTableName); 385 DeleteShmem(kTableName);
383 StatsTable table(kTableName, kMaxThreads, kMaxCounter); 386 StatsTable table(kTableName, kMaxThreads, kMaxCounter);
(...skipping 26 matching lines...) Expand all
410 PlatformThread::Sleep(kDuration); 413 PlatformThread::Sleep(kDuration);
411 } 414 }
412 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); 415 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo"));
413 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); 416 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar"));
414 EXPECT_EQ(2, table.GetCounterValue("c:bar")); 417 EXPECT_EQ(2, table.GetCounterValue("c:bar"));
415 418
416 DeleteShmem(kTableName); 419 DeleteShmem(kTableName);
417 } 420 }
418 421
419 } // namespace base 422 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698