Chromium Code Reviews| 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 #ifndef CHROMEOS_DEVICE_EVENT_LOG_H_ | 5 #ifndef CHROMEOS_DEVICE_EVENT_LOG_H_ |
| 6 #define CHROMEOS_DEVICE_EVENT_LOG_H_ | 6 #define CHROMEOS_DEVICE_EVENT_LOG_H_ |
| 7 | 7 |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/timer/elapsed_timer.h" | |
| 12 #include "chromeos/chromeos_export.h" | 13 #include "chromeos/chromeos_export.h" |
| 13 | 14 |
| 14 namespace chromeos { | 15 namespace chromeos { |
| 15 | 16 |
| 16 // These macros can be used to log chromeos device related events. | 17 // These macros can be used to log chromeos device related events. |
| 17 // The following values should be used for |level| in these macros: | 18 // The following values should be used for |level| in these macros: |
| 18 // ERROR Unexpected events, or device level failures. Use sparingly. | 19 // ERROR Unexpected events, or device level failures. Use sparingly. |
| 19 // USER Events initiated directly by a user (or Chrome) action. | 20 // USER Events initiated directly by a user (or Chrome) action. |
| 20 // EVENT Default event type. | 21 // EVENT Default event type. |
| 21 // DEBUG Debugging details that are usually not interesting. | 22 // DEBUG Debugging details that are usually not interesting. |
| 22 // Examples: | 23 // Examples: |
| 23 // NET_LOG(EVENT) << "NetworkState Changed " << name << ": " << state; | 24 // NET_LOG(EVENT) << "NetworkState Changed " << name << ": " << state; |
| 24 // POWER_LOG(USER) << "Suspend requested"; | 25 // POWER_LOG(USER) << "Suspend requested"; |
| 25 | 26 |
| 26 #define NET_LOG(level) \ | 27 #define NET_LOG(level) \ |
| 27 DEVICE_LOG(::chromeos::device_event_log::LOG_TYPE_NETWORK, \ | 28 DEVICE_LOG(::chromeos::device_event_log::LOG_TYPE_NETWORK, \ |
| 28 ::chromeos::device_event_log::LOG_LEVEL_##level) | 29 ::chromeos::device_event_log::LOG_LEVEL_##level) |
| 29 #define POWER_LOG(level) \ | 30 #define POWER_LOG(level) \ |
| 30 DEVICE_LOG(::chromeos::device_event_log::LOG_TYPE_POWER, \ | 31 DEVICE_LOG(::chromeos::device_event_log::LOG_TYPE_POWER, \ |
| 31 ::chromeos::device_event_log::LOG_LEVEL_##level) | 32 ::chromeos::device_event_log::LOG_LEVEL_##level) |
| 32 #define LOGIN_LOG(level) \ | 33 #define LOGIN_LOG(level) \ |
| 33 DEVICE_LOG(::chromeos::device_event_log::LOG_TYPE_LOGIN, \ | 34 DEVICE_LOG(::chromeos::device_event_log::LOG_TYPE_LOGIN, \ |
| 34 ::chromeos::device_event_log::LOG_LEVEL_##level) | 35 ::chromeos::device_event_log::LOG_LEVEL_##level) |
| 35 | 36 |
| 36 // Generally prefer the above macros unless |level| is not constant. | 37 // Generally prefer the above macros unless |type| or |level| is not constant. |
| 37 | 38 |
| 38 #define DEVICE_LOG(type, level) \ | 39 #define DEVICE_LOG(type, level) \ |
| 39 ::chromeos::device_event_log::internal::DeviceEventLogInstance( \ | 40 ::chromeos::device_event_log::internal::DeviceEventLogInstance( \ |
| 40 __FILE__, __LINE__, type, level).stream() | 41 __FILE__, __LINE__, type, level).stream() |
| 41 | 42 |
| 43 // Declare {Type_LOG_IF_SLOW() at the top of a method to log slow methods | |
| 44 // where "slow" is defined by kSlowMethodThresholdMs in the .cc file. | |
| 45 #define SCOPED_NET_LOG_IF_SLOW() \ | |
| 46 SCOPED_DEVICE_LOG_IF_SLOW(::chromeos::device_event_log::LOG_TYPE_NETWORK) | |
| 47 | |
| 48 // Generally prefer the above macros unless |type| is not constant. | |
| 49 | |
| 50 #define SCOPED_DEVICE_LOG_IF_SLOW(type) \ | |
| 51 ::chromeos::device_event_log::internal::DeviceLogIfSlow \ | |
| 52 scoped_device_log_if_slow(type, __FILE__, __func__) | |
| 53 | |
| 42 namespace device_event_log { | 54 namespace device_event_log { |
| 43 | 55 |
| 44 // Used to specify the type of event. NOTE: Be sure to update LogTypeFromString | 56 // Used to specify the type of event. NOTE: Be sure to update LogTypeFromString |
| 45 // and GetLogTypeString when adding entries to this enum. Also consider | 57 // and GetLogTypeString when adding entries to this enum. Also consider |
| 46 // updating chrome://device-log (see device_log_ui.cc). | 58 // updating chrome://device-log (see device_log_ui.cc). |
| 47 enum LogType { | 59 enum LogType { |
| 48 // Shill / network configuration related events. | 60 // Shill / network configuration related events. |
| 49 LOG_TYPE_NETWORK, | 61 LOG_TYPE_NETWORK, |
| 50 // Power manager related events. | 62 // Power manager related events. |
| 51 LOG_TYPE_POWER, | 63 LOG_TYPE_POWER, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 CHROMEOS_EXPORT std::string GetAsString(StringOrder order, | 122 CHROMEOS_EXPORT std::string GetAsString(StringOrder order, |
| 111 const std::string& format, | 123 const std::string& format, |
| 112 const std::string& types, | 124 const std::string& types, |
| 113 LogLevel max_level, | 125 LogLevel max_level, |
| 114 size_t max_events); | 126 size_t max_events); |
| 115 | 127 |
| 116 CHROMEOS_EXPORT extern const LogLevel kDefaultLogLevel; | 128 CHROMEOS_EXPORT extern const LogLevel kDefaultLogLevel; |
| 117 | 129 |
| 118 namespace internal { | 130 namespace internal { |
| 119 | 131 |
| 132 // Implementation class for DEVICE_LOG macros. Provides a stream for creating | |
| 133 // a log string and adds the event using device_event_log::AddEntry on | |
| 134 // destruction. | |
| 120 class CHROMEOS_EXPORT DeviceEventLogInstance { | 135 class CHROMEOS_EXPORT DeviceEventLogInstance { |
| 121 public: | 136 public: |
| 122 DeviceEventLogInstance(const char* file, | 137 DeviceEventLogInstance(const char* file, |
| 123 int line, | 138 int line, |
| 124 device_event_log::LogType type, | 139 device_event_log::LogType type, |
| 125 device_event_log::LogLevel level); | 140 device_event_log::LogLevel level); |
| 126 ~DeviceEventLogInstance(); | 141 ~DeviceEventLogInstance(); |
| 127 | 142 |
| 128 std::ostream& stream() { return stream_; } | 143 std::ostream& stream() { return stream_; } |
| 129 | 144 |
| 130 private: | 145 private: |
| 131 const char* file_; | 146 const char* file_; |
| 132 const int line_; | 147 const int line_; |
| 133 device_event_log::LogType type_; | 148 device_event_log::LogType type_; |
| 134 device_event_log::LogLevel level_; | 149 device_event_log::LogLevel level_; |
| 135 std::ostringstream stream_; | 150 std::ostringstream stream_; |
| 136 | 151 |
| 137 DISALLOW_COPY_AND_ASSIGN(DeviceEventLogInstance); | 152 DISALLOW_COPY_AND_ASSIGN(DeviceEventLogInstance); |
| 138 }; | 153 }; |
| 139 | 154 |
| 155 // Implementation class for SCOPED_LOG_IF_SLOW macros. Tests the elapsed time on | |
| 156 // destruction and adds a Debug or Error log entry if it exceeds the | |
| 157 // corresponding expected maximum elapsed time. | |
| 158 class CHROMEOS_EXPORT DeviceLogIfSlow { | |
|
satorux1
2014/12/18 05:18:52
Because macros are now prefixed SCOPED_, this clas
stevenjb
2014/12/18 18:16:17
Done.
| |
| 159 public: | |
| 160 DeviceLogIfSlow(LogType type, const char* file, const std::string& name); | |
| 161 ~DeviceLogIfSlow(); | |
| 162 | |
| 163 private: | |
| 164 const char* file_; | |
| 165 LogType type_; | |
| 166 std::string name_; | |
| 167 base::ElapsedTimer timer_; | |
| 168 }; | |
| 169 | |
| 140 } // namespace internal | 170 } // namespace internal |
| 141 | 171 |
| 142 } // namespace device_event_log | 172 } // namespace device_event_log |
| 143 | 173 |
| 144 } // namespace chromeos | 174 } // namespace chromeos |
| 145 | 175 |
| 146 #endif // CHROMEOS_DEVICE_EVENT_LOG_H_ | 176 #endif // CHROMEOS_DEVICE_EVENT_LOG_H_ |
| OLD | NEW |