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