101e04c3fSmrg/*
201e04c3fSmrg * Copyright 2017 Advanced Micro Devices, Inc.
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
501e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
601e04c3fSmrg * to deal in the Software without restriction, including without limitation
701e04c3fSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub
801e04c3fSmrg * license, and/or sell copies of the Software, and to permit persons to whom
901e04c3fSmrg * the Software is furnished to do so, subject to the following conditions:
1001e04c3fSmrg *
1101e04c3fSmrg * The above copyright notice and this permission notice (including the next
1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1301e04c3fSmrg * Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
1801e04c3fSmrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
1901e04c3fSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2001e04c3fSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2101e04c3fSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
2201e04c3fSmrg */
2301e04c3fSmrg
2401e04c3fSmrg/**
2501e04c3fSmrg * @file u_log.h
2601e04c3fSmrg * @brief Context logging facilities
2701e04c3fSmrg *
2801e04c3fSmrg * Provides a means of logging context events (draw calls, command streams, ...)
2901e04c3fSmrg * into files.
3001e04c3fSmrg *
3101e04c3fSmrg * Log entries start their life cycle as "chunks". Chunks can be plain text
3201e04c3fSmrg * written by \ref u_log_printf or custom internal representations added by
3301e04c3fSmrg * \ref u_log_chunk that are only converted to text on-demand (e.g. for higher
3401e04c3fSmrg * performance pipelined hang-debugging).
3501e04c3fSmrg *
3601e04c3fSmrg * Chunks are accumulated into "pages". The manager of the log can periodically
3701e04c3fSmrg * take out the current page using \ref u_log_new_page and dump it to a file.
3801e04c3fSmrg *
3901e04c3fSmrg * Furthermore, "auto loggers" can be added to a context, which are callbacks
4001e04c3fSmrg * that are given the opportunity to add their own logging each time a chunk is
4101e04c3fSmrg * added. Drivers can use this to lazily log chunks of their command stream.
4201e04c3fSmrg * Lazy loggers don't need to be re-entrant.
4301e04c3fSmrg */
4401e04c3fSmrg
4501e04c3fSmrg#ifndef U_LOG_H
4601e04c3fSmrg#define U_LOG_H
4701e04c3fSmrg
4801e04c3fSmrg#include <stdio.h>
4901e04c3fSmrg
5001e04c3fSmrg#include "util/u_debug.h"
5101e04c3fSmrg
527ec681f3Smrg#ifdef __cplusplus
537ec681f3Smrgextern "C" {
547ec681f3Smrg#endif
557ec681f3Smrg
5601e04c3fSmrgstruct u_log_page;
5701e04c3fSmrgstruct u_log_auto_logger;
5801e04c3fSmrg
5901e04c3fSmrgstruct u_log_chunk_type {
6001e04c3fSmrg   void (*destroy)(void *data);
6101e04c3fSmrg   void (*print)(void *data, FILE *stream);
6201e04c3fSmrg};
6301e04c3fSmrg
6401e04c3fSmrgstruct u_log_context {
6501e04c3fSmrg   struct u_log_page *cur;
6601e04c3fSmrg   struct u_log_auto_logger *auto_loggers;
6701e04c3fSmrg   unsigned num_auto_loggers;
6801e04c3fSmrg};
6901e04c3fSmrg
7001e04c3fSmrgtypedef void (u_auto_log_fn)(void *data, struct u_log_context *ctx);
7101e04c3fSmrg
7201e04c3fSmrgvoid
7301e04c3fSmrgu_log_context_init(struct u_log_context *ctx);
7401e04c3fSmrg
7501e04c3fSmrgvoid
7601e04c3fSmrgu_log_context_destroy(struct u_log_context *ctx);
7701e04c3fSmrg
7801e04c3fSmrgvoid
7901e04c3fSmrgu_log_add_auto_logger(struct u_log_context *ctx, u_auto_log_fn *callback,
8001e04c3fSmrg                      void *data);
8101e04c3fSmrg
8201e04c3fSmrgvoid
8301e04c3fSmrgu_log_flush(struct u_log_context *ctx);
8401e04c3fSmrg
8501e04c3fSmrgvoid
8601e04c3fSmrgu_log_printf(struct u_log_context *ctx, const char *fmt, ...) _util_printf_format(2,3);
8701e04c3fSmrg
8801e04c3fSmrgvoid
8901e04c3fSmrgu_log_chunk(struct u_log_context *ctx, const struct u_log_chunk_type *type,
9001e04c3fSmrg            void *data);
9101e04c3fSmrg
9201e04c3fSmrgvoid
9301e04c3fSmrgu_log_new_page_print(struct u_log_context *ctx, FILE *stream);
9401e04c3fSmrg
9501e04c3fSmrgstruct u_log_page *
9601e04c3fSmrgu_log_new_page(struct u_log_context *ctx);
9701e04c3fSmrg
9801e04c3fSmrgvoid
9901e04c3fSmrgu_log_page_destroy(struct u_log_page *page);
10001e04c3fSmrg
10101e04c3fSmrgvoid
10201e04c3fSmrgu_log_page_print(struct u_log_page *page, FILE *stream);
10301e04c3fSmrg
1047ec681f3Smrg#ifdef __cplusplus
1057ec681f3Smrg}
1067ec681f3Smrg#endif
1077ec681f3Smrg
10801e04c3fSmrg#endif /* U_LOG_H */
109