summaryrefslogtreecommitdiffstats
path: root/include/utils
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-08-13 23:35:07 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-08-13 23:35:08 -0700
commitf0083bf5288e0d430b0dc5cbc4b4852bce2ff1af (patch)
tree0050b3fcea9ee008bb05b4f95b67031f19860eb6 /include/utils
parent20128300e0cb7f459a60cfbcddb48190ce6545ed (diff)
parent6f12d573251528086636707dde2fb01a8b7199b8 (diff)
downloadframeworks_native-f0083bf5288e0d430b0dc5cbc4b4852bce2ff1af.zip
frameworks_native-f0083bf5288e0d430b0dc5cbc4b4852bce2ff1af.tar.gz
frameworks_native-f0083bf5288e0d430b0dc5cbc4b4852bce2ff1af.tar.bz2
Merge "Add a very simple helper function to log slow functions." into jb-mr1-dev
Diffstat (limited to 'include/utils')
-rw-r--r--include/utils/Log.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/utils/Log.h b/include/utils/Log.h
index 3c6cc8b..98c441c 100644
--- a/include/utils/Log.h
+++ b/include/utils/Log.h
@@ -29,5 +29,43 @@
#define _LIBS_UTILS_LOG_H
#include <cutils/log.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+
+namespace android {
+
+/*
+ * A very simple utility that yells in the log when an operation takes too long.
+ */
+class LogIfSlow {
+public:
+ LogIfSlow(const char* tag, android_LogPriority priority,
+ int timeoutMillis, const char* message);
+ ~LogIfSlow();
+
+private:
+ const char* const mTag;
+ const android_LogPriority mPriority;
+ const int mTimeoutMillis;
+ const char* const mMessage;
+ const int64_t mStart;
+};
+
+/*
+ * Writes the specified debug log message if this block takes longer than the
+ * specified number of milliseconds to run. Includes the time actually taken.
+ *
+ * {
+ * ALOGD_IF_SLOW(50, "Excessive delay doing something.");
+ * doSomething();
+ * }
+ */
+#define ALOGD_IF_SLOW(timeoutMillis, message) \
+ LogIfSlow _logIfSlow(LOG_TAG, ANDROID_LOG_DEBUG, timeoutMillis, message);
+
+} // namespace android
+
+#endif // __cplusplus
#endif // _LIBS_UTILS_LOG_H