OLD | NEW |
1 // Copyright (c) 2011 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/logging.h" | 5 #include "base/logging.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <io.h> | 8 #include <io.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 typedef HANDLE FileHandle; | 10 typedef HANDLE FileHandle; |
11 typedef HANDLE MutexHandle; | 11 typedef HANDLE MutexHandle; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include <iomanip> | 44 #include <iomanip> |
45 #include <ostream> | 45 #include <ostream> |
46 | 46 |
47 #include "base/base_switches.h" | 47 #include "base/base_switches.h" |
48 #include "base/command_line.h" | 48 #include "base/command_line.h" |
49 #include "base/debug/debugger.h" | 49 #include "base/debug/debugger.h" |
50 #include "base/debug/stack_trace.h" | 50 #include "base/debug/stack_trace.h" |
51 #include "base/eintr_wrapper.h" | 51 #include "base/eintr_wrapper.h" |
52 #include "base/string_piece.h" | 52 #include "base/string_piece.h" |
53 #include "base/synchronization/lock_impl.h" | 53 #include "base/synchronization/lock_impl.h" |
| 54 #include "base/threading/platform_thread.h" |
54 #include "base/utf_string_conversions.h" | 55 #include "base/utf_string_conversions.h" |
55 #include "base/vlog.h" | 56 #include "base/vlog.h" |
56 #if defined(OS_POSIX) | 57 #if defined(OS_POSIX) |
57 #include "base/safe_strerror_posix.h" | 58 #include "base/safe_strerror_posix.h" |
58 #endif | 59 #endif |
59 | 60 |
60 #if defined(OS_ANDROID) | 61 #if defined(OS_ANDROID) |
61 #include <android/log.h> | 62 #include <android/log.h> |
62 #endif | 63 #endif |
63 | 64 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // Helper functions to wrap platform differences. | 123 // Helper functions to wrap platform differences. |
123 | 124 |
124 int32 CurrentProcessId() { | 125 int32 CurrentProcessId() { |
125 #if defined(OS_WIN) | 126 #if defined(OS_WIN) |
126 return GetCurrentProcessId(); | 127 return GetCurrentProcessId(); |
127 #elif defined(OS_POSIX) | 128 #elif defined(OS_POSIX) |
128 return getpid(); | 129 return getpid(); |
129 #endif | 130 #endif |
130 } | 131 } |
131 | 132 |
132 int32 CurrentThreadId() { | |
133 #if defined(OS_WIN) | |
134 return GetCurrentThreadId(); | |
135 #elif defined(OS_MACOSX) | |
136 return mach_thread_self(); | |
137 #elif defined(OS_LINUX) | |
138 return syscall(__NR_gettid); | |
139 #elif defined(OS_ANDROID) | |
140 return gettid(); | |
141 #elif defined(OS_NACL) | |
142 return pthread_self(); | |
143 #elif defined(OS_POSIX) | |
144 return reinterpret_cast<int64>(pthread_self()); | |
145 #endif | |
146 } | |
147 | |
148 uint64 TickCount() { | 133 uint64 TickCount() { |
149 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
150 return GetTickCount(); | 135 return GetTickCount(); |
151 #elif defined(OS_MACOSX) | 136 #elif defined(OS_MACOSX) |
152 return mach_absolute_time(); | 137 return mach_absolute_time(); |
153 #elif defined(OS_NACL) | 138 #elif defined(OS_NACL) |
154 // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h | 139 // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h |
155 // So we have to use clock() for now. | 140 // So we have to use clock() for now. |
156 return clock(); | 141 return clock(); |
157 #elif defined(OS_POSIX) | 142 #elif defined(OS_POSIX) |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 size_t last_slash_pos = filename.find_last_of("\\/"); | 668 size_t last_slash_pos = filename.find_last_of("\\/"); |
684 if (last_slash_pos != base::StringPiece::npos) | 669 if (last_slash_pos != base::StringPiece::npos) |
685 filename.remove_prefix(last_slash_pos + 1); | 670 filename.remove_prefix(last_slash_pos + 1); |
686 | 671 |
687 // TODO(darin): It might be nice if the columns were fixed width. | 672 // TODO(darin): It might be nice if the columns were fixed width. |
688 | 673 |
689 stream_ << '['; | 674 stream_ << '['; |
690 if (log_process_id) | 675 if (log_process_id) |
691 stream_ << CurrentProcessId() << ':'; | 676 stream_ << CurrentProcessId() << ':'; |
692 if (log_thread_id) | 677 if (log_thread_id) |
693 stream_ << CurrentThreadId() << ':'; | 678 stream_ << base::PlatformThread::CurrentId() << ':'; |
694 if (log_timestamp) { | 679 if (log_timestamp) { |
695 time_t t = time(NULL); | 680 time_t t = time(NULL); |
696 struct tm local_time = {0}; | 681 struct tm local_time = {0}; |
697 #if _MSC_VER >= 1400 | 682 #if _MSC_VER >= 1400 |
698 localtime_s(&local_time, &t); | 683 localtime_s(&local_time, &t); |
699 #else | 684 #else |
700 localtime_r(&t, &local_time); | 685 localtime_r(&t, &local_time); |
701 #endif | 686 #endif |
702 struct tm* tm_time = &local_time; | 687 struct tm* tm_time = &local_time; |
703 stream_ << std::setfill('0') | 688 stream_ << std::setfill('0') |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 845 |
861 // This was defined at the beginnig of this file. | 846 // This was defined at the beginnig of this file. |
862 #undef write | 847 #undef write |
863 | 848 |
864 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { | 849 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { |
865 o.write(piece.data(), static_cast<std::streamsize>(piece.size())); | 850 o.write(piece.data(), static_cast<std::streamsize>(piece.size())); |
866 return o; | 851 return o; |
867 } | 852 } |
868 | 853 |
869 } // namespace base | 854 } // namespace base |
OLD | NEW |