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

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: Rebase, self review 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.
(...skipping 10 matching lines...) Expand all
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 |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 NET_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 NET_LOG_IF_SLOW() \
satorux1 2014/12/16 03:29:43 Maybe SCOPED_NET_LOG_IF_SLOW() because it depends
stevenjb 2014/12/16 19:12:58 Hmm, I kind of like it short, but I guess a little
46 DEVICE_LOG_IF_SLOW(::chromeos::device_event_log::LOG_TYPE_NETWORK)
47
48 #define DEVICE_LOG_IF_SLOW(type) \
satorux1 2014/12/16 03:29:44 this looks like a generic tool. maybe define this
stevenjb 2014/12/16 19:12:58 I'll add a comment like I did above with DEVICE_LO
49 ::chromeos::device_event_log::internal::DeviceLogIfSlow _elapsed_( \
satorux1 2014/12/16 03:29:43 is _elapsed_ a variable name? names starting with
stevenjb 2014/12/16 19:12:58 Hmm. I intentionally wanted to use a variable that
satorux1 2014/12/18 05:18:51 Would something like work? elapsed_ ## __LINE__
stevenjb 2014/12/18 18:16:17 That would have been clever, but I think the long
50 type, __FILE__, __func__)
satorux1 2014/12/16 03:29:44 use __LINE__ as well? Also it might be nicer to r
stevenjb 2014/12/16 19:12:58 __LINE__ doesn't add any info since we are timing
satorux1 2014/12/18 05:18:51 SGTM. I originally thought this could be used mult
stevenjb 2014/12/18 18:16:17 In theory it could be used within a scope, but yea
51
42 namespace device_event_log { 52 namespace device_event_log {
43 53
44 // Used to specify the type of event. NOTE: Be sure to update LogTypeFromString 54 // Used to specify the type of event. NOTE: Be sure to update LogTypeFromString
45 // and GetLogTypeString when adding entries to this enum. Also consider 55 // and GetLogTypeString when adding entries to this enum. Also consider
46 // updating chrome://device-log (see device_log_ui.cc). 56 // updating chrome://device-log (see device_log_ui.cc).
47 enum LogType { 57 enum LogType {
48 // Shill / network configuration related events. 58 // Shill / network configuration related events.
49 LOG_TYPE_NETWORK, 59 LOG_TYPE_NETWORK,
50 // Power manager related events. 60 // Power manager related events.
51 LOG_TYPE_POWER, 61 LOG_TYPE_POWER,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 CHROMEOS_EXPORT std::string GetAsString(StringOrder order, 120 CHROMEOS_EXPORT std::string GetAsString(StringOrder order,
111 const std::string& format, 121 const std::string& format,
112 const std::string& types, 122 const std::string& types,
113 LogLevel max_level, 123 LogLevel max_level,
114 size_t max_events); 124 size_t max_events);
115 125
116 CHROMEOS_EXPORT extern const LogLevel kDefaultLogLevel; 126 CHROMEOS_EXPORT extern const LogLevel kDefaultLogLevel;
117 127
118 namespace internal { 128 namespace internal {
119 129
120 class CHROMEOS_EXPORT DeviceEventLogInstance { 130 class CHROMEOS_EXPORT DeviceEventLogInstance {
satorux1 2014/12/16 03:29:43 Add some class comment while you are at it?
stevenjb 2014/12/16 19:12:58 Done.
121 public: 131 public:
122 DeviceEventLogInstance(const char* file, 132 DeviceEventLogInstance(const char* file,
123 int line, 133 int line,
124 device_event_log::LogType type, 134 device_event_log::LogType type,
125 device_event_log::LogLevel level); 135 device_event_log::LogLevel level);
126 ~DeviceEventLogInstance(); 136 ~DeviceEventLogInstance();
127 137
128 std::ostream& stream() { return stream_; } 138 std::ostream& stream() { return stream_; }
129 139
130 private: 140 private:
131 const char* file_; 141 const char* file_;
132 const int line_; 142 const int line_;
133 device_event_log::LogType type_; 143 device_event_log::LogType type_;
134 device_event_log::LogLevel level_; 144 device_event_log::LogLevel level_;
135 std::ostringstream stream_; 145 std::ostringstream stream_;
136 146
137 DISALLOW_COPY_AND_ASSIGN(DeviceEventLogInstance); 147 DISALLOW_COPY_AND_ASSIGN(DeviceEventLogInstance);
138 }; 148 };
139 149
150 class CHROMEOS_EXPORT DeviceLogIfSlow {
satorux1 2014/12/16 03:29:44 Add some comment?
stevenjb 2014/12/16 19:12:58 Done.
151 public:
152 DeviceLogIfSlow(LogType type, const char* file, const std::string& name);
153 ~DeviceLogIfSlow();
154
155 private:
156 const char* file_;
157 LogType type_;
158 std::string name_;
159 base::ElapsedTimer timer_;
160 };
161
140 } // namespace internal 162 } // namespace internal
141 163
142 } // namespace device_event_log 164 } // namespace device_event_log
143 165
144 } // namespace chromeos 166 } // namespace chromeos
145 167
146 #endif // CHROMEOS_DEVICE_EVENT_LOG_H_ 168 #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