| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "tools/cygprofile/cygprofile.h" | 5 #include "tools/cygprofile/cygprofile.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <sys/time.h> | 8 #include <sys/time.h> |
| 9 | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace cygprofile { | 18 namespace cygprofile { |
| 19 namespace { | 19 namespace { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 std::vector<LogEntry> entries; | 72 std::vector<LogEntry> entries; |
| 73 scoped_ptr<ThreadLog> thread_log( | 73 scoped_ptr<ThreadLog> thread_log( |
| 74 new ThreadLog(base::Bind(&FlushEntries, base::Unretained(&entries)))); | 74 new ThreadLog(base::Bind(&FlushEntries, base::Unretained(&entries)))); |
| 75 | 75 |
| 76 thread_log->AddEntry(reinterpret_cast<void*>(0x2)); | 76 thread_log->AddEntry(reinterpret_cast<void*>(0x2)); |
| 77 thread_log->AddEntry(reinterpret_cast<void*>(0x3)); | 77 thread_log->AddEntry(reinterpret_cast<void*>(0x3)); |
| 78 | 78 |
| 79 // This should make the manager spawn its internal flush thread which will | 79 // This should make the manager spawn its internal flush thread which will |
| 80 // wait for a notification before it starts doing some work. | 80 // wait for a notification before it starts doing some work. |
| 81 manager.AddLog(thread_log.Pass()); | 81 manager.AddLog(std::move(thread_log)); |
| 82 | 82 |
| 83 EXPECT_EQ(0U, entries.size()); | 83 EXPECT_EQ(0U, entries.size()); |
| 84 // This will wake up the internal thread. | 84 // This will wake up the internal thread. |
| 85 wait_event.Signal(); | 85 wait_event.Signal(); |
| 86 // Now it's our turn to wait until it performed the flush. | 86 // Now it's our turn to wait until it performed the flush. |
| 87 notify_event.Wait(); | 87 notify_event.Wait(); |
| 88 | 88 |
| 89 // The flush should have moved the data to the local vector of entries. | 89 // The flush should have moved the data to the local vector of entries. |
| 90 EXPECT_EQ(2U, entries.size()); | 90 EXPECT_EQ(2U, entries.size()); |
| 91 ASSERT_EQ(2U, reinterpret_cast<uintptr_t>(entries[0].address)); | 91 ASSERT_EQ(2U, reinterpret_cast<uintptr_t>(entries[0].address)); |
| 92 ASSERT_EQ(3U, reinterpret_cast<uintptr_t>(entries[1].address)); | 92 ASSERT_EQ(3U, reinterpret_cast<uintptr_t>(entries[1].address)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| 96 } // namespace cygprofile | 96 } // namespace cygprofile |
| 97 | 97 |
| 98 // Custom runner implementation since base's one requires JNI on Android. | 98 // Custom runner implementation since base's one requires JNI on Android. |
| 99 int main(int argc, char** argv) { | 99 int main(int argc, char** argv) { |
| 100 testing::InitGoogleTest(&argc, argv); | 100 testing::InitGoogleTest(&argc, argv); |
| 101 return RUN_ALL_TESTS(); | 101 return RUN_ALL_TESTS(); |
| 102 } | 102 } |
| OLD | NEW |