<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">n Sat, Sep 2, 2017 at 1:17 AM, Chad Versace <span dir="ltr"><<a href="mailto:chadversary@chromium.org" target="_blank">chadversary@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm bringing up Vulkan in the Android container of Chrome OS (ARC++).<br>
<br>
On Android, stdio goes to /dev/null. On Android, remote gdb is even more<br>
painful than the usual remote gdb. On Android, nothing works like you<br>
expect and debugging is hell. I need logging.<br>
<br>
This patch introduces a small, simple logging API that can easily wrap<br>
Android's API. On non-Android platforms, this logger does nothing fancy.<br>
It follows the time-honored Unix tradition of spewing everything to<br>
stderr with minimal fuss.<br>
<br>
My goal here is not perfection. My goal is to make a minimal, clean API,<br>
that people hate merely a little instead of a lot, and that's good<br>
enough to let me bring up Android Vulkan. And it needs to be fast,<br>
which means it must be small. No one wants to their game to miss frames<br>
while aiming a flaming bow into the jaws of an angry robot t-rex, and<br>
thus become t-rex breakfast, because some fool had too much fun desiging<br>
a bloated, ideal logging API.<br></blockquote><div><br></div><div>I don't actually hate it at all. In fact, I rather like it. Sadtly, we probably need a bit more indirection in Vulkan thanks to VK_EXT_debug_report but it should be pretty easy to tie in here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If people like it, perhaps we should quickly promote it to src/util.<br></blockquote><div><br></div><div>I'd be a fan.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The API looks like this:<br>
<br>
#define INTEL_LOG_TAG "intel-vulkan"<br>
#define DEBUG<br>
<br>
intel_logd("try hard thing with foo=%d", foo);<br>
<br>
n = try_foo(...);<br>
if (n < 0) {<br>
intel_loge("%s:%d: foo failed bigtime", __FILE__, __LINE__);<br>
return VK_ERROR_DEVICE_LOST;<br>
}<br>
<br>
And produces this on non-Android:<br>
<br>
intel-vulkan: debug: try hard thing with foo=93<br>
intel-vulkan: error: anv_device.c:182: foo failed bigtime<br>
---<br>
src/intel/Makefile.sources | 4 +-<br>
src/intel/common/intel_log.c | 87 ++++++++++++++++++++++++++++++<wbr>++++++++++++++<br>
src/intel/common/intel_log.h | 82 ++++++++++++++++++++++++++++++<wbr>+++++++++++<br>
3 files changed, 172 insertions(+), 1 deletion(-)<br>
create mode 100644 src/intel/common/intel_log.c<br>
create mode 100644 src/intel/common/intel_log.h<br>
<br>
diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources<br>
index 4074ba9ee54..f6a69f65455 100644<br>
--- a/src/intel/Makefile.sources<br>
+++ b/src/intel/Makefile.sources<br>
@@ -18,7 +18,9 @@ COMMON_FILES = \<br>
common/gen_l3_config.c \<br>
common/gen_l3_config.h \<br>
common/gen_urb_config.c \<br>
- common/gen_sample_positions.h<br>
+ common/gen_sample_positions.h \<br>
+ common/intel_log.c \<br>
+ common/intel_log.h<br>
<br>
COMPILER_FILES = \<br>
compiler/brw_cfg.cpp \<br>
diff --git a/src/intel/common/intel_log.c b/src/intel/common/intel_log.c<br>
new file mode 100644<br>
index 00000000000..03d6dc72a8d<br>
--- /dev/null<br>
+++ b/src/intel/common/intel_log.c<br>
@@ -0,0 +1,87 @@<br>
+/*<br>
+ * Copyright 2017 Google<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include <stdarg.h><br>
+<br>
+#ifdef ANDROID<br>
+#include <android/log.h><br>
+#else<br>
+#include <stdio.h><br>
+#endif<br>
+<br>
+#include "intel_log.h"<br>
+<br>
+#ifdef ANDROID<br>
+static inline android_LogPriority<br>
+level_to_android(enum intel_log_level l)<br>
+{<br>
+ switch (l) {<br>
+ case INTEL_LOG_ERROR: return ANDROID_LOG_ERROR;<br>
+ case INTEL_LOG_WARN: return ANDROID_LOG_WARN;<br>
+ case INTEL_LOG_INFO: return ANDROID_LOG_INFO;<br>
+ case INTEL_LOG_DEBUG: return ANDROID_LOG_DEBUG;<br>
+ }<br>
+<br>
+ unreachable("bad intel_log_level");<br>
+}<br>
+#endif<br>
+<br>
+#ifndef ANDROID<br>
+static inline const char *<br>
+level_to_str(enum intel_log_level l)<br>
+{<br>
+ switch (l) {<br>
+ case INTEL_LOG_ERROR: return "error";<br>
+ case INTEL_LOG_WARN: return "warning";<br>
+ case INTEL_LOG_INFO: return "info";<br>
+ case INTEL_LOG_DEBUG: return "debug";<br>
+ }<br>
+<br>
+ unreachable("bad intel_log_level");<br>
+}<br>
+#endif<br>
+<br>
+void<br>
+intel_log(enum intel_log_level level, const char *tag, const char *format, ...)<br>
+{<br>
+ va_list va;<br>
+<br>
+ va_start(va, format);<br>
+ intel_log_v(level, tag, format, va);<br>
+ va_end(va);<br>
+}<br>
+<br>
+void<br>
+intel_log_v(enum intel_log_level level, const char *tag, const char *format,<br>
+ va_list va)<br>
+{<br>
+#ifdef ANDROID<br>
+ __android_log_vprint(level_to_<wbr>android(level), tag, format, va);<br>
+#else<br>
+ flockfile(stderr);<br>
+ fprintf(stderr, "%s: %s: ", tag, level_to_str(level));<br>
+ vfprintf(stderr, format, va);<br>
+ fprintf(stderr, "\n");<br>
+ funlockfile(stderr);<br>
+#endif<br>
+}<br>
diff --git a/src/intel/common/intel_log.h b/src/intel/common/intel_log.h<br>
new file mode 100644<br>
index 00000000000..0f28109a0a4<br>
--- /dev/null<br>
+++ b/src/intel/common/intel_log.h<br>
@@ -0,0 +1,82 @@<br>
+/*<br>
+ * Copyright 2017 Google<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#ifndef INTEL_LOG_H<br>
+#define INTEL_LOG_H<br>
+<br>
+#include <stdarg.h><br>
+<br>
+#include "util/macros.h"<br>
+<br>
+#ifdef __cplusplus<br>
+extern "C" {<br>
+#endif<br>
+<br>
+#ifndef INTEL_LOG_TAG<br>
+#define INTEL_LOG_TAG "INTEL-MESA"<br>
+#endif<br>
+<br>
+enum intel_log_level {<br>
+ INTEL_LOG_ERROR,<br>
+ INTEL_LOG_WARN,<br>
+ INTEL_LOG_INFO,<br>
+ INTEL_LOG_DEBUG,<br>
+};<br>
+<br>
+void PRINTFLIKE(3, 4)<br>
+intel_log(enum intel_log_level, const char *tag, const char *format, ...);<br>
+<br>
+void<br>
+intel_log_v(enum intel_log_level, const char *tag, const char *format,<br>
+ va_list va);<br>
+<br>
+#define intel_loge(fmt, ...) intel_log(INTEL_LOG_ERROR, (INTEL_LOG_TAG), (fmt), ##__VA_ARGS__)<br>
+#define intel_logw(fmt, ...) intel_log(INTEL_LOG_WARN, (INTEL_LOG_TAG), (fmt), ##__VA_ARGS__)<br>
+#define intel_logi(fmt, ...) intel_log(INTEL_LOG_INFO, (INTEL_LOG_TAG), (fmt), ##__VA_ARGS__)<br>
+#ifdef DEBUG<br>
+#define intel_logd(fmt, ...) intel_log(INTEL_LOG_DEBUG, (INTEL_LOG_TAG), (fmt), ##__VA_ARGS__)<br>
+#else<br>
+#define intel_logd(fmt, ...) __intel_log_use_args((fmt), ##__VA_ARGS__)<br>
+#endif<br></blockquote><div><br></div><div>I'm not sure if ignoring debug loigging is best done here or at some slightly higher level. I think here is probably fine.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+#define intel_loge_v(fmt, va) intel_log_v(INTEL_LOG_ERROR, (INTEL_LOG_TAG), (fmt), (va))<br>
+#define intel_logw_v(fmt, va) intel_log_v(INTEL_LOG_WARN, (INTEL_LOG_TAG), (fmt), (va))<br>
+#define intel_logi_v(fmt, va) intel_log_v(INTEL_LOG_INFO, (INTEL_LOG_TAG), (fmt), (va))<br>
+#ifdef DEBUG<br>
+#define intel_logd_v(fmt, va) intel_log_v(INTEL_LOG_DEBUG, (INTEL_LOG_TAG), (fmt), (va))<br>
+#else<br>
+#define intel_logd_v(fmt, va) __intel_log_use_args((fmt), (va))<br>
+#endif<br>
+<br>
+<br>
+#ifndef DEBUG<br>
+/* Suppres -Wunused */<br>
+static inline void PRINTFLIKE(1, 2)<br>
+__intel_log_use_args(const char *format, ...) { }<br>
+#endif<br>
+<br>
+#ifdef __cplusplus<br>
+}<br>
+#endif<br>
+<br>
+#endif /* INTEL_LOG_H */<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.13.5<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>