summaryrefslogtreecommitdiffstats
path: root/include/utils
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-08-10 20:44:39 -0700
committerJeff Brown <jeffbrown@google.com>2012-08-10 22:03:55 -0700
commit6f12d573251528086636707dde2fb01a8b7199b8 (patch)
tree460216732eecae5597ada876286a95a231e86a3c /include/utils
parente57f292595bec48f65c8088b00ff6beea01217e9 (diff)
downloadframeworks_native-6f12d573251528086636707dde2fb01a8b7199b8.zip
frameworks_native-6f12d573251528086636707dde2fb01a8b7199b8.tar.gz
frameworks_native-6f12d573251528086636707dde2fb01a8b7199b8.tar.bz2
Add a very simple helper function to log slow functions.
Change-Id: I2e2e072206d02b572a330dd25857c161b5b563bf
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