1 /* Copyright (c) 2016, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 #include "camscope_packet_type.h"
31 #include "QCameraTrace.h"
32
33 #if defined(__linux__) && !defined(__ANDROID__)
34 #include <unistd.h>
35 #include <sys/syscall.h>
36 #endif
37
38 const char * camscope_atrace_names[CAMSCOPE_EVENT_NAME_SIZE] = {
39 "Mct_Sof",
40 "Mct_super_params",
41 "Mct_special_event",
42 "Mct_process_bus_msg",
43 "Camera:AFD",
44 "Camera:ASD",
45 "Camera:AEC",
46 "Camera:AWB",
47 "Camera:AF",
48 "CPP",
49 "CPP_Capture",
50 "CPP_clock_request",
51 "CPP_Holding_Time",
52 "CPP_Hardware_On",
53 "Snapshot",
54 "ISP_Hardware_Update",
55 "JPEG",
56 "FaceProc",
57 "Sensor_process_event",
58 "FD_num_faces_detected",
59 "Camera:alloc",
60 "iface:streamon_fwd",
61 "iface:streamon_to_thread",
62 "iface:streamoff_fwd",
63 "iface:streamoff_to_thread",
64 "iface:config_ISP",
65 "iface:hw_config",
66 "iface:create_axi_hw",
67 "iface:config_axi_hw",
68 "iface:streamon",
69 "iface:streamoff",
70 "AF_START",
71 "AF_SET",
72 "Camera:IS",
73 "ISP:streamon",
74 "ISP:streamoff",
75 "ISP:set_Strm_config",
76 "VFE_HW_UPDATE",
77 "ISP:streamon_fwd",
78 "SENSOR_SD_OPEN",
79 "SENSOR_START_SESSION",
80 "SENSOR_SET_RESOLUTION",
81 "SENSOR_SET_STREAM_CONFIG",
82 "SENSOR_CONFIG_PDAF",
83 "SENSOR_LOAD_CHROMATIX",
84 "SENSOR_START_STREAM",
85 "SENSOR_SET_FPS",
86 "SENSOR_STREAMOFF",
87 "Camera:WNR",
88 "Camera:WNR:memcpy",
89 "PPROC_streamoff",
90 "CPP:Streamon",
91 "Camera:CAC",
92 "CPP_create_hw_frame",
93 "CPP_set_Strm_config",
94 "Mct_start_session",
95 "Mct_stop_session",
96 "IMG:streamon",
97 "MCT:create_buf",
98 "start_preview",
99 "stop_preview",
100 "take_picture",
101 "close_camera_device",
102 "openCamera",
103 "startPreview",
104 "stopPreview",
105 "capture_channel_cb_routine",
106 "preview_stream_cb_routine",
107 "SNAPSHOT",
108 "getStreamBufs",
109 "openCamera",
110 "closeCamera",
111 "flush",
112 "zsl_channel_cb",
113 "postproc_channel_cb_routine",
114 "synchronous_stream_cb_routine",
115 "nodisplay_preview_stream_cb_routine",
116 "rdi_mode_stream_cb_routine",
117 "postview_stream_cb_routine",
118 "video_stream_cb_routine",
119 "snapshot_channel_cb_routine",
120 "raw_stream_cb_routine",
121 "raw_channel_cb_routine",
122 "preview_raw_stream_cb_routine",
123 "snapshot_raw_stream_cb_routine",
124 "metadata_stream_cb_routine",
125 "reprocess_stream_cb_routine",
126 "callback_stream_cb_routine",
127 "set_preview_window",
128 "set_CallBacks",
129 "enable_msg_type",
130 "disable_msg_type",
131 "msg_type_enabled",
132 "prepare_preview",
133 "preview_enabled",
134 "restart_start_preview",
135 "restart_stop_preview",
136 "pre_start_recording",
137 "start_recording",
138 "stop_recording",
139 "recording_enabled",
140 "release_recording_frame",
141 "cancel_auto_focus",
142 "pre_take_picture",
143 "cancel_picture",
144 "set_parameters",
145 "stop_after_set_params",
146 "commit_params",
147 "restart_after_set_params",
148 "get_parameters",
149 "put_parameters",
150 "send_command",
151 "send_command_restart",
152 "release",
153 "register_face_image",
154 "prepare_snapshot",
155 "QCamera2HardwareInterface",
156 "initCapabilities",
157 "getCapabilities",
158 "preparePreview",
159 "prepareHardwareForSnapshot",
160 "initialize",
161 "configureStreams",
162 "configureStreamsPerfLocked",
163 "handleBatchMetadata",
164 "handleMetadataWithLock",
165 "handleInputBufferWithLock",
166 "handleBufferWithLock",
167 "processCaptureRequest",
168 "flushPerf",
169 "getCamInfo",
170 "dynamicUpdateMetaStreamInfo",
171 "start",
172 "stop",
173 "flush",
174 "streamCbRoutine",
175 "registerBuffer",
176 "reprocessCbRoutine",
177 "initialize",
178 "request",
179 "initialize",
180 "streamCbRoutine",
181 "initialize",
182 "streamCbRoutine",
183 "jpegEvtHandle",
184 "request",
185 "dataNotifyCB",
186 "streamCbRoutine",
187 "registerBuffer",
188 "start",
189 "stop",
190 "init",
191 "initJpeg",
192 "releaseJpegJobData",
193 "releasePPJobData",
194 "encodeData"
195 };
196
197 /*===========================================================================
198 * FUNCTION : get_thread_id
199 *
200 * DESCRIPTION : helper function to get the current thread ID
201 *
202 * PARAMETERS : N/A
203 *
204 * RETURN : the thread ID
205 *==========================================================================*/
get_thread_id()206 pid_t get_thread_id() {
207 #if defined(__linux__) && !defined(__ANDROID__)
208 return syscall(__NR_gettid);
209 #else
210 return gettid();
211 #endif
212 }
213
214 /*===========================================================================
215 * FUNCTION : fill_camscope_base
216 *
217 * DESCRIPTION : helper function to set the struct's data with the given
218 * parameters
219 *
220 * PARAMETERS :
221 * @scope_struct: struct to fill out
222 * @packet_type : packet_type data value to set
223 * @size : size data value to set
224 *
225 * RETURN : void
226 *==========================================================================*/
fill_camscope_base(camscope_base * scope_struct,uint32_t packet_type,uint32_t size)227 void fill_camscope_base(camscope_base *scope_struct, uint32_t packet_type,
228 uint32_t size) {
229 scope_struct->packet_type = packet_type;
230 scope_struct->size = size;
231 }
232
233 /*===========================================================================
234 * FUNCTION : fill_camscope_sw_base
235 *
236 * DESCRIPTION : helper function to set the struct's data with the given
237 * parameters
238 *
239 * PARAMETERS :
240 * @scope_struct: struct to fill out
241 * @packet_type : packet_type data value to set
242 * @size : size data value to set
243 * @timestamp : timestamp value to store
244 * @thread_id : identifier of where the packet originates from
245 * @event_name : name of the event to store
246 *
247 * RETURN : void
248 *==========================================================================*/
fill_camscope_sw_base(camscope_sw_base * scope_struct,uint32_t packet_type,uint32_t size,struct timeval timestamp,int32_t thread_id,uint32_t event_name)249 void fill_camscope_sw_base(camscope_sw_base *scope_struct,
250 uint32_t packet_type, uint32_t size,
251 struct timeval timestamp,
252 int32_t thread_id, uint32_t event_name) {
253 fill_camscope_base(&(scope_struct->base), packet_type, size);
254 scope_struct->timestamp = timestamp;
255 scope_struct->thread_id = thread_id;
256 scope_struct->event_name = event_name;
257 }
258
259 /*===========================================================================
260 * FUNCTION : fill_camscope_timing
261 *
262 * DESCRIPTION : helper function to set the struct's data with the given
263 * parameters
264 *
265 * PARAMETERS :
266 * @scope_struct: struct to fill out
267 * @packet_type : packet_type data value to set
268 * @size : size data value to set
269 * @timestamp : timestamp value to store
270 * @thread_id : identifier of where the packet originates from
271 * @event_name : name of the event to store
272 * @frame_id : frame identifier of which frame the packet originates from
273 *
274 * RETURN : void
275 *==========================================================================*/
fill_camscope_timing(camscope_timing * scope_struct,uint32_t packet_type,uint32_t size,struct timeval timestamp,int32_t thread_id,uint32_t event_name,uint32_t frame_id)276 void fill_camscope_timing(camscope_timing *scope_struct, uint32_t packet_type,
277 uint32_t size, struct timeval timestamp,
278 int32_t thread_id, uint32_t event_name,
279 uint32_t frame_id) {
280 fill_camscope_sw_base(&(scope_struct->sw_base), packet_type, size,
281 timestamp, thread_id, event_name);
282 scope_struct->frame_id = frame_id;
283 }
284
285 /*===========================================================================
286 * FUNCTION : fill_camscope_in_out_timing
287 *
288 * DESCRIPTION : helper function to set the struct's data with the given
289 * parameters
290 *
291 * PARAMETERS :
292 * @scope_struct : struct to fill out
293 * @packet_type : packet_type data value to set
294 * @size : size data value to set
295 * @timestamp : timestamp value to store
296 * @thread_id : identifier of where the packet originates from
297 * @event_name : name of the event to store
298 * @in_timestamp : timestamp of when start of event occurred
299 * @out_timestamp: timestamp of when end of event occurred
300 * @frame_id : frame identifier of which frame the packet
301 * originates from
302 *
303 * RETURN : void
304 *==========================================================================*/
fill_camscope_in_out_timing(camscope_in_out_timing * scope_struct,uint32_t packet_type,uint32_t size,struct timeval timestamp,int32_t thread_id,uint32_t event_name,struct timeval in_timestamp,struct timeval out_timestamp,uint32_t frame_id)305 void fill_camscope_in_out_timing(camscope_in_out_timing *scope_struct,
306 uint32_t packet_type, uint32_t size,
307 struct timeval timestamp,
308 int32_t thread_id, uint32_t event_name,
309 struct timeval in_timestamp,
310 struct timeval out_timestamp,
311 uint32_t frame_id) {
312 fill_camscope_sw_base(&(scope_struct->sw_base), packet_type, size,
313 timestamp, thread_id, event_name);
314 scope_struct->in_timestamp = in_timestamp;
315 scope_struct->out_timestamp = out_timestamp;
316 scope_struct->frame_id = frame_id;
317 }
318
319 /*===========================================================================
320 * FUNCTION : camscope_base_log
321 *
322 * DESCRIPTION : CameraScope Base logging function that stores
323 * the base amount of data for a camscope packet
324 *
325 * PARAMETERS :
326 * @camscope_section : section of code where this log is being called
327 * @camscope_enable_mask: Enable/Disable mask
328 * @packet_type : camscope packet_type
329 *
330 * RETURN : void
331 *==========================================================================*/
camscope_base_log(uint32_t camscope_section,uint32_t camscope_enable_mask,uint32_t packet_type)332 void camscope_base_log(uint32_t camscope_section,
333 uint32_t camscope_enable_mask, uint32_t packet_type) {
334 if (kpi_camscope_frame_count != 0) {
335 if (kpi_camscope_flags & camscope_enable_mask) {
336 struct timeval timestamp;
337 gettimeofday(×tamp, NULL);
338 camscope_mutex_lock((camscope_section_type)camscope_section);
339 camscope_base scope_struct;
340 uint32_t size = sizeof(scope_struct);
341 uint32_t total_size =
342 camscope_reserve((camscope_section_type)camscope_section, size);
343 if (size == total_size) {
344 fill_camscope_base(&scope_struct, packet_type, size);
345 camscope_store_data((camscope_section_type)camscope_section,
346 &scope_struct, size);
347 }
348 camscope_mutex_unlock((camscope_section_type)camscope_section);
349 }
350 }
351 }
352
353 /*===========================================================================
354 * FUNCTION : camscope_sw_base_log
355 *
356 * DESCRIPTION : CameraScope Software Base logging function that
357 * stores the minimum amount of data for tracing
358 *
359 * PARAMETERS :
360 * @camscope_section : section of code where this log is being called
361 * @camscope_enable_mask: enable/disable mask
362 * @packet_type : camscope packet_type
363 * @event_name : name of the event that the packet is storing
364 *
365 * RETURN : void
366 *==========================================================================*/
camscope_sw_base_log(uint32_t camscope_section,uint32_t camscope_enable_mask,uint32_t packet_type,uint32_t event_name)367 void camscope_sw_base_log(uint32_t camscope_section,
368 uint32_t camscope_enable_mask,
369 uint32_t packet_type, uint32_t event_name) {
370 if (kpi_camscope_frame_count != 0) {
371 if (kpi_camscope_flags & camscope_enable_mask) {
372 struct timeval timestamp;
373 gettimeofday(×tamp, NULL);
374 camscope_mutex_lock((camscope_section_type)camscope_section);
375 camscope_sw_base scope_struct;
376 uint32_t size = sizeof(scope_struct);
377 int32_t thread_id = (int32_t)get_thread_id();
378 uint32_t total_size =
379 camscope_reserve((camscope_section_type)camscope_section, size);
380 if (size == total_size) {
381 fill_camscope_sw_base(&scope_struct, packet_type, size,
382 timestamp, thread_id, event_name);
383 camscope_store_data((camscope_section_type)camscope_section,
384 &scope_struct, size);
385 }
386 camscope_mutex_unlock((camscope_section_type)camscope_section);
387 }
388 }
389 }
390
391 /*===========================================================================
392 * FUNCTION : camscope_timing_log
393 *
394 * DESCRIPTION : CameraScope Timing logging function that
395 * stores data used for the timing of events
396 * with respect to their frame id
397 *
398 * PARAMETERS :
399 * @camscope_section : section of code where this log is being called
400 * @camscope_enable_mask: enable/Disable mask
401 * @packet_type : camscope packet_type
402 * @event_name : name of the event that the packet is storing
403 * @frame_id : frame id that the packet is logging
404 *
405 * RETURN : void
406 *==========================================================================*/
camscope_timing_log(uint32_t camscope_section,uint32_t camscope_enable_mask,uint32_t packet_type,uint32_t event_name,uint32_t frame_id)407 void camscope_timing_log(uint32_t camscope_section,
408 uint32_t camscope_enable_mask, uint32_t packet_type,
409 uint32_t event_name, uint32_t frame_id) {
410 if (kpi_camscope_frame_count != 0) {
411 if (kpi_camscope_flags & camscope_enable_mask) {
412 struct timeval timestamp;
413 gettimeofday(×tamp, NULL);
414 camscope_mutex_lock((camscope_section_type)camscope_section);
415 camscope_timing scope_struct;
416 uint32_t size = sizeof(scope_struct);
417 int32_t thread_id = (int32_t)get_thread_id();
418 uint32_t total_size =
419 camscope_reserve((camscope_section_type)camscope_section, size);
420 if (size == total_size) {
421 fill_camscope_timing(&scope_struct, packet_type, size,
422 timestamp, thread_id, event_name,
423 frame_id);
424 camscope_store_data((camscope_section_type)camscope_section,
425 &scope_struct, size);
426 }
427 camscope_mutex_unlock((camscope_section_type)camscope_section);
428 }
429 }
430 }
431
432 /*===========================================================================
433 * FUNCTION : camscope_in_out_timing_log
434 *
435 * DESCRIPTION : CameraScope In-Out Timing logging function that
436 * stores given timestamps with the packet data
437 *
438 * PARAMETERS :
439 * @camscope_section : section of code where this log is being called
440 * @camscope_enable_mask: enable/Disable mask
441 * @packet_type : camscope packet_type
442 * @event_name : name of the event that the packet is storing
443 * @frame_id : frame id that the packet is logging
444 *
445 * RETURN : void
446 *==========================================================================*/
camscope_in_out_timing_log(uint32_t camscope_section,uint32_t camscope_enable_mask,uint32_t packet_type,uint32_t event_name,struct timeval in_timestamp,struct timeval out_timestamp,uint32_t frame_id)447 void camscope_in_out_timing_log(uint32_t camscope_section,
448 uint32_t camscope_enable_mask,
449 uint32_t packet_type, uint32_t event_name,
450 struct timeval in_timestamp,
451 struct timeval out_timestamp,
452 uint32_t frame_id) {
453 if (kpi_camscope_frame_count != 0) {
454 if (kpi_camscope_flags & camscope_enable_mask) {
455 struct timeval timestamp;
456 gettimeofday(×tamp, NULL);
457 camscope_mutex_lock((camscope_section_type)camscope_section);
458 camscope_in_out_timing scope_struct;
459 uint32_t size = sizeof(scope_struct);
460 int32_t thread_id = (int32_t)get_thread_id();
461 uint32_t total_size =
462 camscope_reserve((camscope_section_type)camscope_section, size);
463 if (size == total_size) {
464 fill_camscope_in_out_timing(&scope_struct, packet_type, size,
465 timestamp, thread_id, event_name,
466 in_timestamp, out_timestamp,
467 frame_id);
468 camscope_store_data((camscope_section_type)camscope_section,
469 &scope_struct, size);
470 }
471 camscope_mutex_unlock((camscope_section_type)camscope_section);
472 }
473 }
474 }
475