1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/**
29bf215546Sopenharmony_ci * @file
30bf215546Sopenharmony_ci * Trace data dumping primitives.
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#ifndef TR_DUMP_H
34bf215546Sopenharmony_ci#define TR_DUMP_H
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "pipe/p_compiler.h"
38bf215546Sopenharmony_ci#include "pipe/p_format.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistruct pipe_resource;
41bf215546Sopenharmony_cistruct pipe_surface;
42bf215546Sopenharmony_cistruct pipe_transfer;
43bf215546Sopenharmony_cistruct pipe_box;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci/*
46bf215546Sopenharmony_ci * Low level dumping controls.
47bf215546Sopenharmony_ci *
48bf215546Sopenharmony_ci * Opening the trace file and checking if that is opened.
49bf215546Sopenharmony_ci */
50bf215546Sopenharmony_cibool trace_dump_trace_begin(void);
51bf215546Sopenharmony_cibool trace_dump_trace_enabled(void);
52bf215546Sopenharmony_civoid trace_dump_trace_flush(void);
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci/*
55bf215546Sopenharmony_ci * Lock and unlock the call mutex.
56bf215546Sopenharmony_ci *
57bf215546Sopenharmony_ci * It used by the none locked version of dumping control
58bf215546Sopenharmony_ci * and begin/end call dump functions.
59bf215546Sopenharmony_ci *
60bf215546Sopenharmony_ci * Begin takes the lock while end unlocks it. Use the _locked
61bf215546Sopenharmony_ci * version to avoid locking/unlocking it.
62bf215546Sopenharmony_ci */
63bf215546Sopenharmony_civoid trace_dump_call_lock(void);
64bf215546Sopenharmony_civoid trace_dump_call_unlock(void);
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci/*
67bf215546Sopenharmony_ci * High level dumping control.
68bf215546Sopenharmony_ci */
69bf215546Sopenharmony_civoid trace_dumping_start_locked(void);
70bf215546Sopenharmony_civoid trace_dumping_stop_locked(void);
71bf215546Sopenharmony_cibool trace_dumping_enabled_locked(void);
72bf215546Sopenharmony_civoid trace_dumping_start(void);
73bf215546Sopenharmony_civoid trace_dumping_stop(void);
74bf215546Sopenharmony_cibool trace_dumping_enabled(void);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_civoid trace_dump_call_begin_locked(const char *klass, const char *method);
77bf215546Sopenharmony_civoid trace_dump_call_end_locked(void);
78bf215546Sopenharmony_civoid trace_dump_call_begin(const char *klass, const char *method);
79bf215546Sopenharmony_civoid trace_dump_call_end(void);
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_civoid trace_dump_arg_begin(const char *name);
82bf215546Sopenharmony_civoid trace_dump_arg_end(void);
83bf215546Sopenharmony_civoid trace_dump_ret_begin(void);
84bf215546Sopenharmony_civoid trace_dump_ret_end(void);
85bf215546Sopenharmony_civoid trace_dump_bool(int value);
86bf215546Sopenharmony_civoid trace_dump_int(long long int value);
87bf215546Sopenharmony_civoid trace_dump_uint(long long unsigned value);
88bf215546Sopenharmony_civoid trace_dump_float(double value);
89bf215546Sopenharmony_civoid trace_dump_bytes(const void *data, size_t size);
90bf215546Sopenharmony_civoid trace_dump_box_bytes(const void *data,
91bf215546Sopenharmony_ci                          struct pipe_resource *resource,
92bf215546Sopenharmony_ci			  const struct pipe_box *box,
93bf215546Sopenharmony_ci			  unsigned stride,
94bf215546Sopenharmony_ci			  unsigned slice_stride);
95bf215546Sopenharmony_civoid trace_dump_string(const char *str);
96bf215546Sopenharmony_civoid trace_dump_enum(const char *value);
97bf215546Sopenharmony_civoid trace_dump_array_begin(void);
98bf215546Sopenharmony_civoid trace_dump_array_end(void);
99bf215546Sopenharmony_civoid trace_dump_elem_begin(void);
100bf215546Sopenharmony_civoid trace_dump_elem_end(void);
101bf215546Sopenharmony_civoid trace_dump_struct_begin(const char *name);
102bf215546Sopenharmony_civoid trace_dump_struct_end(void);
103bf215546Sopenharmony_civoid trace_dump_member_begin(const char *name);
104bf215546Sopenharmony_civoid trace_dump_member_end(void);
105bf215546Sopenharmony_civoid trace_dump_null(void);
106bf215546Sopenharmony_civoid trace_dump_ptr(const void *value);
107bf215546Sopenharmony_ci/* will turn a wrapped object into the real one and dump ptr */
108bf215546Sopenharmony_civoid trace_dump_surface_ptr(struct pipe_surface *_surface);
109bf215546Sopenharmony_civoid trace_dump_transfer_ptr(struct pipe_transfer *_transfer);
110bf215546Sopenharmony_civoid trace_dump_nir(void *nir);
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_civoid trace_dump_trigger_active(bool active);
113bf215546Sopenharmony_civoid trace_dump_check_trigger(void);
114bf215546Sopenharmony_cibool trace_dump_is_triggered(void);
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci/*
117bf215546Sopenharmony_ci * Code saving macros.
118bf215546Sopenharmony_ci */
119bf215546Sopenharmony_ci
120bf215546Sopenharmony_ci#define trace_dump_arg(_type, _arg) \
121bf215546Sopenharmony_ci   do { \
122bf215546Sopenharmony_ci      trace_dump_arg_begin(#_arg); \
123bf215546Sopenharmony_ci      trace_dump_##_type(_arg); \
124bf215546Sopenharmony_ci      trace_dump_arg_end(); \
125bf215546Sopenharmony_ci   } while(0)
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci#define trace_dump_arg_enum(_arg, _value) \
128bf215546Sopenharmony_ci   do { \
129bf215546Sopenharmony_ci      trace_dump_arg_begin(#_arg); \
130bf215546Sopenharmony_ci      trace_dump_enum(_value); \
131bf215546Sopenharmony_ci      trace_dump_arg_end(); \
132bf215546Sopenharmony_ci   } while(0)
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_ci#define trace_dump_arg_struct(_type, _arg) \
135bf215546Sopenharmony_ci   do { \
136bf215546Sopenharmony_ci      trace_dump_arg_begin(#_arg); \
137bf215546Sopenharmony_ci      trace_dump_##_type(&_arg); \
138bf215546Sopenharmony_ci      trace_dump_arg_end(); \
139bf215546Sopenharmony_ci   } while(0)
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci#define trace_dump_ret(_type, _arg) \
142bf215546Sopenharmony_ci   do { \
143bf215546Sopenharmony_ci      trace_dump_ret_begin(); \
144bf215546Sopenharmony_ci      trace_dump_##_type(_arg); \
145bf215546Sopenharmony_ci      trace_dump_ret_end(); \
146bf215546Sopenharmony_ci   } while(0)
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci#define trace_dump_array(_type, _obj, _size) \
149bf215546Sopenharmony_ci   do { \
150bf215546Sopenharmony_ci      if (_obj) { \
151bf215546Sopenharmony_ci         size_t idx; \
152bf215546Sopenharmony_ci         trace_dump_array_begin(); \
153bf215546Sopenharmony_ci         for(idx = 0; idx < (_size); ++idx) { \
154bf215546Sopenharmony_ci            trace_dump_elem_begin(); \
155bf215546Sopenharmony_ci            trace_dump_##_type((_obj)[idx]); \
156bf215546Sopenharmony_ci            trace_dump_elem_end(); \
157bf215546Sopenharmony_ci         } \
158bf215546Sopenharmony_ci         trace_dump_array_end(); \
159bf215546Sopenharmony_ci      } else { \
160bf215546Sopenharmony_ci         trace_dump_null(); \
161bf215546Sopenharmony_ci      } \
162bf215546Sopenharmony_ci   } while(0)
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_ci#define trace_dump_struct_array(_type, _obj, _size) \
165bf215546Sopenharmony_ci   do { \
166bf215546Sopenharmony_ci      if (_obj) { \
167bf215546Sopenharmony_ci         size_t idx; \
168bf215546Sopenharmony_ci         trace_dump_array_begin(); \
169bf215546Sopenharmony_ci         for(idx = 0; idx < (_size); ++idx) { \
170bf215546Sopenharmony_ci            trace_dump_elem_begin(); \
171bf215546Sopenharmony_ci            trace_dump_##_type(&(_obj)[idx]); \
172bf215546Sopenharmony_ci            trace_dump_elem_end(); \
173bf215546Sopenharmony_ci         } \
174bf215546Sopenharmony_ci         trace_dump_array_end(); \
175bf215546Sopenharmony_ci      } else { \
176bf215546Sopenharmony_ci         trace_dump_null(); \
177bf215546Sopenharmony_ci      } \
178bf215546Sopenharmony_ci   } while(0)
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci#define trace_dump_member(_type, _obj, _member) \
181bf215546Sopenharmony_ci   do { \
182bf215546Sopenharmony_ci      trace_dump_member_begin(#_member); \
183bf215546Sopenharmony_ci      trace_dump_##_type((_obj)->_member); \
184bf215546Sopenharmony_ci      trace_dump_member_end(); \
185bf215546Sopenharmony_ci   } while(0)
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_ci#define trace_dump_arg_array(_type, _arg, _size) \
188bf215546Sopenharmony_ci   do { \
189bf215546Sopenharmony_ci      trace_dump_arg_begin(#_arg); \
190bf215546Sopenharmony_ci      trace_dump_array(_type, _arg, _size); \
191bf215546Sopenharmony_ci      trace_dump_arg_end(); \
192bf215546Sopenharmony_ci   } while(0)
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_ci#define trace_dump_member_array(_type, _obj, _member) \
195bf215546Sopenharmony_ci   do { \
196bf215546Sopenharmony_ci      trace_dump_member_begin(#_member); \
197bf215546Sopenharmony_ci      trace_dump_array(_type, (_obj)->_member, sizeof((_obj)->_member)/sizeof((_obj)->_member[0])); \
198bf215546Sopenharmony_ci      trace_dump_member_end(); \
199bf215546Sopenharmony_ci   } while(0)
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_ci#endif /* TR_DUMP_H */
203