summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn2012-05-08 20:54:22 -0500
committerAlex Ray2013-07-30 15:56:59 -0500
commitc1309d74e8929f73e1b9cdb5dbf70aa8a2b09af3 (patch)
treeae89c82296d03a9192621f82d10584614157f086 /libs/utils
parent6c1cf1c8f29263a1374991195ffa98b883f181ed (diff)
downloadplatform-system-core-c1309d74e8929f73e1b9cdb5dbf70aa8a2b09af3.tar.gz
platform-system-core-c1309d74e8929f73e1b9cdb5dbf70aa8a2b09af3.tar.xz
platform-system-core-c1309d74e8929f73e1b9cdb5dbf70aa8a2b09af3.zip
Add callback hack to find out when to reload system properties.
Every IBinder object can accept a new transaction to tell it that it might want to reload system properties, and in the process anyone can register a callback to be executed when this happens. Use this to reload the trace property. This is very much ONLY for debugging. Change-Id: I55c67c46f8f3fa9073bef0dfaab4577ed1d47eb4
Diffstat (limited to 'libs/utils')
-rw-r--r--libs/utils/Trace.cpp22
-rw-r--r--libs/utils/misc.cpp60
2 files changed, 77 insertions, 5 deletions
diff --git a/libs/utils/Trace.cpp b/libs/utils/Trace.cpp
index f3ec4851a..5cd5731d5 100644
--- a/libs/utils/Trace.cpp
+++ b/libs/utils/Trace.cpp
@@ -19,6 +19,7 @@
19#include <cutils/properties.h> 19#include <cutils/properties.h>
20#include <utils/Log.h> 20#include <utils/Log.h>
21#include <utils/Trace.h> 21#include <utils/Trace.h>
22#include <utils/misc.h>
22 23
23namespace android { 24namespace android {
24 25
@@ -27,10 +28,19 @@ int Tracer::sTraceFD = -1;
27uint64_t Tracer::sEnabledTags = 0; 28uint64_t Tracer::sEnabledTags = 0;
28Mutex Tracer::sMutex; 29Mutex Tracer::sMutex;
29 30
31void Tracer::changeCallback() {
32 Mutex::Autolock lock(sMutex);
33 if (sIsReady && sTraceFD >= 0) {
34 loadSystemProperty();
35 }
36}
37
30void Tracer::init() { 38void Tracer::init() {
31 Mutex::Autolock lock(sMutex); 39 Mutex::Autolock lock(sMutex);
32 40
33 if (!sIsReady) { 41 if (!sIsReady) {
42 add_sysprop_change_callback(changeCallback, 0);
43
34 const char* const traceFileName = 44 const char* const traceFileName =
35 "/sys/kernel/debug/tracing/trace_marker"; 45 "/sys/kernel/debug/tracing/trace_marker";
36 sTraceFD = open(traceFileName, O_WRONLY); 46 sTraceFD = open(traceFileName, O_WRONLY);
@@ -38,14 +48,18 @@ void Tracer::init() {
38 ALOGE("error opening trace file: %s (%d)", strerror(errno), errno); 48 ALOGE("error opening trace file: %s (%d)", strerror(errno), errno);
39 // sEnabledTags remains zero indicating that no tracing can occur 49 // sEnabledTags remains zero indicating that no tracing can occur
40 } else { 50 } else {
41 char value[PROPERTY_VALUE_MAX]; 51 loadSystemProperty();
42 property_get("debug.atrace.tags.enableflags", value, "0");
43 sEnabledTags = (strtoll(value, NULL, 0) & ATRACE_TAG_VALID_MASK)
44 | ATRACE_TAG_ALWAYS;
45 } 52 }
46 53
47 android_atomic_release_store(1, &sIsReady); 54 android_atomic_release_store(1, &sIsReady);
48 } 55 }
49} 56}
50 57
58void Tracer::loadSystemProperty() {
59 char value[PROPERTY_VALUE_MAX];
60 property_get("debug.atrace.tags.enableflags", value, "0");
61 sEnabledTags = (strtoll(value, NULL, 0) & ATRACE_TAG_VALID_MASK)
62 | ATRACE_TAG_ALWAYS;
63}
64
51} // namespace andoid 65} // namespace andoid
diff --git a/libs/utils/misc.cpp b/libs/utils/misc.cpp
index dc89d15b6..b3c99e6b4 100644
--- a/libs/utils/misc.cpp
+++ b/libs/utils/misc.cpp
@@ -14,10 +14,13 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#define LOG_TAG "misc"
18
17// 19//
18// Miscellaneous utility functions. 20// Miscellaneous utility functions.
19// 21//
20#include <utils/misc.h> 22#include <utils/misc.h>
23#include <utils/Log.h>
21 24
22#include <sys/stat.h> 25#include <sys/stat.h>
23#include <string.h> 26#include <string.h>
@@ -25,6 +28,12 @@
25#include <assert.h> 28#include <assert.h>
26#include <stdio.h> 29#include <stdio.h>
27 30
31#if defined(HAVE_PTHREADS)
32# include <pthread.h>
33#endif
34
35#include <utils/Vector.h>
36
28using namespace android; 37using namespace android;
29 38
30namespace android { 39namespace android {
@@ -181,5 +190,54 @@ unsigned int roundUpPower2(unsigned int val)
181 return val; 190 return val;
182} 191}
183 192
184}; // namespace android 193struct sysprop_change_callback_info {
194 sysprop_change_callback callback;
195 int priority;
196};
197
198#if defined(HAVE_PTHREADS)
199static pthread_mutex_t gSyspropMutex = PTHREAD_MUTEX_INITIALIZER;
200static Vector<sysprop_change_callback_info>* gSyspropList = NULL;
201#endif
202
203void add_sysprop_change_callback(sysprop_change_callback cb, int priority) {
204#if defined(HAVE_PTHREADS)
205 pthread_mutex_lock(&gSyspropMutex);
206 if (gSyspropList == NULL) {
207 gSyspropList = new Vector<sysprop_change_callback_info>();
208 }
209 sysprop_change_callback_info info;
210 info.callback = cb;
211 info.priority = priority;
212 bool added = false;
213 for (size_t i=0; i<gSyspropList->size(); i++) {
214 if (priority >= gSyspropList->itemAt(i).priority) {
215 gSyspropList->insertAt(info, i);
216 added = true;
217 break;
218 }
219 }
220 if (!added) {
221 gSyspropList->add(info);
222 }
223 pthread_mutex_unlock(&gSyspropMutex);
224#endif
225}
226
227void report_sysprop_change() {
228#if defined(HAVE_PTHREADS)
229 pthread_mutex_lock(&gSyspropMutex);
230 Vector<sysprop_change_callback_info> listeners;
231 if (gSyspropList != NULL) {
232 listeners = *gSyspropList;
233 }
234 pthread_mutex_unlock(&gSyspropMutex);
185 235
236 //ALOGI("Reporting sysprop change to %d listeners", listeners.size());
237 for (size_t i=0; i<listeners.size(); i++) {
238 listeners[i].callback();
239 }
240#endif
241}
242
243}; // namespace android