Mir

Merge lp:~vanvugt/mir/fastlog into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 1780
Proposed branch: lp:~vanvugt/mir/fastlog
Merge into: lp:mir
Diff against target: 113 lines (+48/-8)
5 files modified
3rd_party/android-deps/std/Log.h (+4/-0)
3rd_party/android-input/android/frameworks/base/services/input/MirLog.cpp (+11/-8)
CMakeLists.txt (+4/-0)
tests/acceptance-tests/CMakeLists.txt (+1/-0)
tests/acceptance-tests/test_macros.cpp (+28/-0)
To merge this branch: bzr merge lp:~vanvugt/mir/fastlog
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel d'Andrada (community) Approve
Kevin DuBois (community) Approve
Alan Griffiths Approve
Review via email: mp+227148@code.launchpad.net

Commit message

Stop Android logging from consuming significant CPU (on every input event).
(LP: #1343074)

Two things needed fixing:
  1. Verbose logging (ALOGV) is meant to be disabled (optimized out) unless
     debugging, but it wasn't ever being removed. This means expensive calls
     to ALOGV remained, for example in EventHub.cpp on every input event.
  2. Our own Mir version of __android_log_print was extremely inefficient,
     formatting log messages unconditionally even when they did not meet the
     reporting threshold and were never used.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

OK

review: Approve
Revision history for this message
Kevin DuBois (kdub) wrote :

lgtm

review: Approve
Revision history for this message
Daniel d'Andrada (dandrader) wrote :

lgtm

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '3rd_party/android-deps/std/Log.h'
2--- 3rd_party/android-deps/std/Log.h 2013-05-03 22:53:02 +0000
3+++ 3rd_party/android-deps/std/Log.h 2014-07-17 07:43:34 +0000
4@@ -61,8 +61,12 @@
5 * Simplified macro to send a verbose log message using the current LOG_TAG.
6 */
7 #ifndef ALOGV
8+#if LOG_NDEBUG // Per Android, optimize out verbose messages when LOG_NDEBUG=1
9+#define ALOGV(...) ((void)0)
10+#else
11 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
12 #endif
13+#endif
14
15 /*
16 * Simplified macro to send a debug log message using the current LOG_TAG.
17
18=== modified file '3rd_party/android-input/android/frameworks/base/services/input/MirLog.cpp'
19--- 3rd_party/android-input/android/frameworks/base/services/input/MirLog.cpp 2013-09-24 18:04:03 +0000
20+++ 3rd_party/android-input/android/frameworks/base/services/input/MirLog.cpp 2014-07-17 07:43:34 +0000
21@@ -154,11 +154,7 @@
22
23 extern "C" int __android_log_print(int prio, const char *tag, const char *fmt, ...)
24 {
25- char buffer[1024] = {'0'};
26- va_list ap;
27- va_start(ap, fmt);
28- int result = vsnprintf(buffer, sizeof buffer - 1, fmt, ap);
29- va_end(ap);
30+ int result = 0;
31
32 if (gLogState.globalMinPriority == ANDROID_LOG_UNKNOWN) {
33 configureInitialState(&gLogState);
34@@ -177,9 +173,16 @@
35 }
36
37 if (prio >= minPrio) {
38- char taggedBuffer[1024];
39- sprintf(taggedBuffer, "[%s]%s", tag, buffer);
40- mir::write_to_log(prio, taggedBuffer);
41+ char buffer[1024];
42+ int max = sizeof buffer - 1;
43+ int tagend = snprintf(buffer, max, "[%s]", tag);
44+
45+ va_list ap;
46+ va_start(ap, fmt);
47+ result = vsnprintf(buffer+tagend, max - tagend, fmt, ap);
48+ va_end(ap);
49+
50+ mir::write_to_log(prio, buffer);
51 } else {
52 // filter out log message
53 }
54
55=== modified file 'CMakeLists.txt'
56--- CMakeLists.txt 2014-07-09 10:48:47 +0000
57+++ CMakeLists.txt 2014-07-17 07:43:34 +0000
58@@ -88,6 +88,10 @@
59 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
60 endif()
61
62+# Define LOG_NDEBUG=1 to ensure Android ALOGV calls are not compiled in to
63+# consume CPU time...
64+add_definitions(-DLOG_NDEBUG=1)
65+
66 enable_testing()
67
68 include_directories(include/shared)
69
70=== modified file 'tests/acceptance-tests/CMakeLists.txt'
71--- tests/acceptance-tests/CMakeLists.txt 2014-07-11 14:04:15 +0000
72+++ tests/acceptance-tests/CMakeLists.txt 2014-07-17 07:43:34 +0000
73@@ -39,6 +39,7 @@
74 test_large_messages.cpp
75 test_client_surface_visibility.cpp
76 test_client_with_custom_display_config_deadlock.cpp
77+ test_macros.cpp
78 ${GENERATED_PROTOBUF_SRCS}
79 ${GENERATED_PROTOBUF_HDRS}
80 )
81
82=== added file 'tests/acceptance-tests/test_macros.cpp'
83--- tests/acceptance-tests/test_macros.cpp 1970-01-01 00:00:00 +0000
84+++ tests/acceptance-tests/test_macros.cpp 2014-07-17 07:43:34 +0000
85@@ -0,0 +1,28 @@
86+/*
87+ * Copyright © 2014 Canonical Ltd.
88+ *
89+ * This program is free software: you can redistribute it and/or modify
90+ * it under the terms of the GNU General Public License version 3 as
91+ * published by the Free Software Foundation.
92+ *
93+ * This program is distributed in the hope that it will be useful,
94+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
95+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96+ * GNU General Public License for more details.
97+ *
98+ * You should have received a copy of the GNU General Public License
99+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
100+ *
101+ * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
102+ */
103+
104+#include "cutils/log.h" // Get the final value of LOG_NDEBUG
105+#include <gtest/gtest.h>
106+
107+TEST(Macros, android_verbose_logging_is_disabled)
108+{
109+ // Ensure verbose logging (ALOGV) is removed. It requires significant
110+ // CPU time to constantly format some verbose messages...
111+ // This is a regression test for performance bug LP: #1343074.
112+ EXPECT_EQ(1, LOG_NDEBUG);
113+}

Subscribers

People subscribed via source and target branches