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

Side by Side Diff: chromeos/device_event_log.h

Issue 811623002: Add logging for slow device events, limit network UI update rate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_441650
Patch Set: Feedback Created 6 years 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
« no previous file with comments | « ash/system/chromeos/network/tray_vpn.cc ('k') | chromeos/device_event_log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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::ScopedDeviceLogIfSlow \
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
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 ScopedDeviceLogIfSlow {
159 public:
160 ScopedDeviceLogIfSlow(LogType type,
161 const char* file,
162 const std::string& name);
163 ~ScopedDeviceLogIfSlow();
164
165 private:
166 const char* file_;
167 LogType type_;
168 std::string name_;
169 base::ElapsedTimer timer_;
170 };
171
140 } // namespace internal 172 } // namespace internal
141 173
142 } // namespace device_event_log 174 } // namespace device_event_log
143 175
144 } // namespace chromeos 176 } // namespace chromeos
145 177
146 #endif // CHROMEOS_DEVICE_EVENT_LOG_H_ 178 #endif // CHROMEOS_DEVICE_EVENT_LOG_H_
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_vpn.cc ('k') | chromeos/device_event_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698