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

Side by Side Diff: ui/events/ozone/evdev/libgestures_glue/gesture_feedback.cc

Issue 893753002: Dump touchpad event logs for touch log source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change functions to Chromium counterparts and cleanup stuff Created 5 years, 10 months 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_feedback.h"
6
7 #include <time.h>
8
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/logging.h"
13 #include "base/process/launch.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h"
17 #include "base/threading/worker_pool.h"
18 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h"
19
20 namespace ui {
21
22 namespace {
23
24 // Binary paths.
25 const char kGzipCommand[] = "/bin/gzip";
26 const char kDateCommand[] = "/bin/date";
27
28 const size_t kTouchLogTimestampMaxSize = 80;
29
30 // Return the values in an array in one string. Used for touch logging.
31 template <typename T>
32 std::string DumpArrayProperty(const std::vector<T>& value, const char* format) {
33 std::string ret;
34 for (size_t i = 0; i < value.size(); ++i) {
35 if (i > 0)
36 ret.append(", ");
37 ret.append(base::StringPrintf(format, value[i]));
38 }
39 return ret;
40 }
41
42 // Return the values in a gesture property in one string. Used for touch
43 // logging.
44 std::string DumpGesturePropertyValue(GesturesProp* property) {
45 switch (property->type()) {
46 case GesturePropertyProvider::PT_INT:
47 return DumpArrayProperty(property->GetIntValue(), "%d");
48 break;
49 case GesturePropertyProvider::PT_SHORT:
50 return DumpArrayProperty(property->GetShortValue(), "%d");
51 break;
52 case GesturePropertyProvider::PT_BOOL:
53 return DumpArrayProperty(property->GetBoolValue(), "%d");
54 break;
55 case GesturePropertyProvider::PT_STRING:
56 return "\"" + property->GetStringValue() + "\"";
57 break;
58 case GesturePropertyProvider::PT_REAL:
59 return DumpArrayProperty(property->GetDoubleValue(), "%lf");
60 break;
61 default:
62 NOTREACHED();
63 break;
64 }
65 return std::string();
66 }
67
68 // Compress dumped event logs in place.
69 void CompressDumpedLog(scoped_ptr<std::vector<std::string>> log_paths) {
70 for (size_t i = 0; i < log_paths->size(); ++i) {
71 // Zip the file.
72 base::CommandLine command = base::CommandLine(base::FilePath(kGzipCommand));
73 command.AppendArg("-f");
74 command.AppendArg((*log_paths)[i]);
75 std::string output;
76 base::GetAppOutput(command, &output);
77
78 // Replace the original file with the zipped one.
79 base::Move(base::FilePath((*log_paths)[i] + ".gz"),
80 base::FilePath((*log_paths)[i]));
81 }
82 }
83
84 // Get the current time in a string.
85 std::string GetCurrentTimeForLogging() {
86 time_t rawtime;
87 struct tm timeinfo;
88 char buffer[kTouchLogTimestampMaxSize];
89
90 time(&rawtime);
91 if (!localtime_r(&rawtime, &timeinfo)) {
92 PLOG(ERROR) << "localtime_r failed";
93 return "";
94 }
95 strftime(buffer, kTouchLogTimestampMaxSize, "%Y%m%d-%H%M%S", &timeinfo);
spang 2015/02/12 18:10:38 It looks like buffer may not be NULL terminated if
Shecky Lin 2015/02/13 05:12:22 Done.
96 return std::string(buffer);
97 }
98
99 // Canonize the device name for logging.
100 std::string GetCanonicalDeviceName(const std::string& name) {
101 std::string ret(name);
102 for (size_t i = 0; i < ret.size(); ++i)
103 if (!IsAsciiAlpha(ret[i]))
104 ret[i] = '_';
105 return ret;
106 }
107
108 // Name event logs in a way that is compatible with existing toolchain.
109 std::string GenerateEventLogName(GesturePropertyProvider* provider,
110 const base::FilePath& out_dir,
111 const std::string& prefix,
112 const std::string& now,
113 int id) {
114 return out_dir.value() + "/" + prefix + now + "." + base::IntToString(id) +
115 "." + GetCanonicalDeviceName(provider->GetDeviceNameById(id));
116 }
117
118 // Set the logging properties to dump event logs.
119 void StartToDumpEventLog(GesturePropertyProvider* provider,
120 const int device_id) {
121 // Dump gesture log.
122 GesturesProp* property = provider->GetProperty(device_id, "Log Path");
123 property->SetStringValue(kTouchpadGestureLogPath);
124 property = provider->GetProperty(device_id, "Logging Notify");
125 property->SetIntValue(std::vector<int>(1, 1));
126
127 // Dump evdev log.
128 property = provider->GetProperty(device_id, "Dump Debug Log");
129 property->SetBoolValue(std::vector<bool>(1, true));
130 }
131
132 } // namespace
133
134 // Dump touch device property values to a string.
135 void DumpTouchDeviceStatus(GesturePropertyProvider* provider,
136 std::string* status) {
137 // We use DT_ALL since we want gesture property values for all devices that
138 // run with the gesture library, not just mice or touchpads.
139 std::vector<int> ids;
140 provider->GetDeviceIdsByType(DT_ALL, &ids);
141
142 // Dump the property names and values for each device.
143 for (size_t i = 0; i < ids.size(); ++i) {
144 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]);
145 status->append("\n");
146 status->append(base::StringPrintf("ID %d:\n", ids[i]));
147 status->append(base::StringPrintf(
148 "Device \'%s\':\n", provider->GetDeviceNameById(ids[i]).c_str()));
149
150 // Note that, unlike X11, we don't maintain the "atom" concept here.
151 // Therefore, the property name indices we output here shouldn't be treated
152 // as unique identifiers of the properties.
153 std::sort(names.begin(), names.end());
154 for (size_t j = 0; j < names.size(); ++j) {
155 status->append(base::StringPrintf("\t%s (%zu):", names[j].c_str(), j));
156 GesturesProp* property = provider->GetProperty(ids[i], names[j]);
157 status->append("\t" + DumpGesturePropertyValue(property) + '\n');
158 }
159 }
160 }
161
162 // Dump touch event logs.
163 void DumpTouchEventLog(GesturePropertyProvider* provider,
164 const base::FilePath& out_dir,
165 scoped_ptr<std::vector<base::FilePath>> log_paths,
166 const GetTouchEventLogReply& reply) {
167 // Get device ids.
168 std::vector<int> ids;
169 provider->GetDeviceIdsByType(DT_ALL, &ids);
170
171 // Get current time stamp.
172 std::string now = GetCurrentTimeForLogging();
173
174 // Dump event logs for gesture devices.
175 scoped_ptr<std::vector<std::string>> log_paths_to_be_compressed(
176 new std::vector<std::string>);
177 for (size_t i = 0; i < ids.size(); ++i) {
178 // First, see if the device actually uses the gesture library by checking
179 // if it has any gesture property.
180 std::vector<std::string> names = provider->GetPropertyNamesById(ids[i]);
181 if (names.size() == 0)
182 continue;
183
184 // Set the logging properties to dump event logs. This needs to be done
185 // synchronously for now or we might have race conditions on the debug
186 // buffer. If the performance becomes a concern then, we can fork and
187 // synchronize it.
188 //
189 // TODO(sheckylin): Make sure this has no performance impact for user
190 // feedbacks.
191 StartToDumpEventLog(provider, ids[i]);
192
193 // Rename/move the file to another place since each device's log is
194 // always dumped using the same name.
195 std::string gesture_log_filename = GenerateEventLogName(
196 provider, out_dir, "touchpad_activity_", now, ids[i]);
197 base::Move(base::FilePath(kTouchpadGestureLogPath),
198 base::FilePath(gesture_log_filename));
199 std::string evdev_log_filename = GenerateEventLogName(
200 provider, out_dir, "cmt_input_events_", now, ids[i]);
201 base::Move(base::FilePath(kTouchpadEvdevLogPath),
202 base::FilePath(evdev_log_filename));
203
204 // Historically, we compress touchpad/mouse logs with gzip before tarring
205 // them up. We DONT compress touchscreen logs though.
206 log_paths_to_be_compressed->push_back(gesture_log_filename);
207 log_paths->push_back(base::FilePath(gesture_log_filename));
208 log_paths_to_be_compressed->push_back(evdev_log_filename);
209 log_paths->push_back(base::FilePath(evdev_log_filename));
210 }
211
212 // Compress touchpad/mouse logs on another thread and return.
213 base::WorkerPool::PostTaskAndReply(
214 FROM_HERE,
215 base::Bind(&CompressDumpedLog, base::Passed(&log_paths_to_be_compressed)),
216 base::Bind(reply, base::Passed(&log_paths)), true /* task_is_slow */);
217 }
218
219 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698