1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
|
// Copyright (c) 2010-2025 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef __MFX_TRACE_H__
#define __MFX_TRACE_H__
#include <stdint.h>
#ifdef __cplusplus
#include <functional>
#include <tuple>
#include <utility>
#include <memory>
#endif
#include <stdarg.h>
#include "mfx_config.h"
#include "mfx_trace_dump.h"
#include "mfx_error.h"
#define MAX_PATH 260
#define __INT64 long long
#define __UINT64 unsigned long long
typedef char mfxTraceChar;
#define MFX_TRACE_STRING(x) x
#define DISABLE_WARN_HIDE_PREV_LOCAL_DECLARATION \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wshadow\"")
#define ROLLBACK_WARN_HIDE_PREV_LOCAL_DECLARATION \
_Pragma("GCC diagnostic pop")
#define VPLLOG_BUFFER_SIZE 256
typedef unsigned int mfxTraceU32;
typedef __UINT64 mfxTraceU64;
/*------------------------------------------------------------------------------*/
extern mfxTraceU64 EventCfg;
extern mfxTraceU32 LogConfig;
extern int32_t FrameIndex;
extern char VplLogPath[VPLLOG_BUFFER_SIZE];
// C section
#ifdef __cplusplus
extern "C"
{
#endif
// this is for RT events
enum mfxTraceTaskType
{
MFX_TRACE_DEFAULT_TASK = 0,
MFX_TRACE_API_DECODE_QUERY_TASK,
MFX_TRACE_API_DECODE_QUERY_IOSURF_TASK,
MFX_TRACE_API_DECODE_HEADER_TASK,
MFX_TRACE_API_DECODE_INIT_TASK,
MFX_TRACE_API_DECODE_CLOSE_TASK,
MFX_TRACE_API_DECODE_FRAME_ASYNC_TASK,
MFX_TRACE_API_ENCODE_QUERY_TASK,
MFX_TRACE_API_ENCODE_QUERY_IOSURF_TASK,
MFX_TRACE_API_ENCODE_INIT_TASK,
MFX_TRACE_API_ENCODE_CLOSE_TASK,
MFX_TRACE_API_ENCODE_FRAME_ASYNC_TASK,
MFX_TRACE_API_VPP_QUERY_TASK,
MFX_TRACE_API_VPP_QUERY_IOSURF_TASK,
MFX_TRACE_API_VPP_INIT_TASK,
MFX_TRACE_API_VPP_CLOSE_TASK,
MFX_TRACE_API_VPP_LEGACY_ROUTINE_TASK,
MFX_TRACE_API_VPP_RUN_FRAME_VPP_ASYNC_TASK,
MFX_TRACE_API_VPP_RUN_FRAME_VPP_ASYNC_EX_TASK,
MFX_TRACE_API_MFX_INIT_EX_TASK,
MFX_TRACE_API_MFX_CLOSE_TASK,
MFX_TRACE_API_DO_WORK_TASK,
MFX_TRACE_API_SYNC_OPERATION_TASK,
MFX_TRACE_HOTSPOT_SCHED_WAIT_GLOBAL_EVENT_TASK,
MFX_TRACE_HOTSPOT_DDI_SUBMIT_TASK,
MFX_TRACE_HOTSPOT_DDI_EXECUTE_TASK,
MFX_TRACE_HOTSPOT_DDI_ENDFRAME_TASK,
MFX_TRACE_HOTSPOT_DDI_WAIT_TASK_SYNC,
MFX_TRACE_HOTSPOT_DDI_QUERY_TASK,
MFX_TRACE_HOTSPOT_CM_COPY,
MFX_TRACE_HOTSPOT_COPY_DX11_TO_DX9,
MFX_TRACE_HOTSPOT_COPY_DX9_TO_DX11,
MFX_TRACE_HOTSPOT_SCHED_ROUTINE,
MFX_TRACE_API_MFXINITIALIZE_TASK,
MFX_TRACE_API_MFXQUERYIMPLSDESCRIPTION_TASK,
MFX_TRACE_API_HEVC_OUTPUTINFO_TASK,
MFX_TRACE_API_AVC_OUTPUTINFO_TASK,
MFX_TRACE_API_AV1_OUTPUTINFO_TASK,
MFX_TRACE_API_VP9_OUTPUTINFO_TASK,
MFX_TRACE_API_HEVC_SYNCINFO_TASK,
MFX_TRACE_API_AVC_SYNCINFO_TASK,
MFX_TRACE_API_AV1_SYNCINFO_TASK,
MFX_TRACE_API_VP9_SYNCINFO_TASK,
MFX_TRACE_API_HEVC_DISPLAYINFO_TASK,
MFX_TRACE_API_AVC_DISPLAYINFO_TASK,
MFX_TRACE_API_AV1_DISPLAYINFO_TASK,
MFX_TRACE_API_VP9_DISPLAYINFO_TASK,
MFX_TRACE_API_HEVC_PICTUREPARAMETER_TASK,
MFX_TRACE_API_HEVC_SLICEPARAMETER_TASK,
MFX_TRACE_API_HEVC_QMATRIXARAMETER_TASK,
MFX_TRACE_API_AVC_PICTUREPARAMETER_TASK,
MFX_TRACE_API_AVC_SLICEPARAMETER_TASK,
MFX_TRACE_API_AVC_QMATRIXARAMETER_TASK,
MFX_TRACE_API_AV1_PICTUREPARAMETER_TASK,
MFX_TRACE_API_AV1_TILECONTROLPARAMETER_TASK,
MFX_TRACE_API_VP9_PICTUREPARAMETER_TASK,
MFX_TRACE_API_VP9_SEGMENTPARAMETER_TASK,
MFX_TRACE_API_BITSTREAM_TASK,
MFX_TRACE_API_HEVC_DPBPARAMETER_TASK,
MFX_TRACE_API_AVC_DPBPARAMETER_TASK,
MFX_TRACE_API_AV1_DPBPARAMETER_TASK,
MFX_TRACE_API_VP9_DPBPARAMETER_TASK,
VA_TRACE_API_AV1_PICTUREPARAMETER_TASK,
VA_TRACE_API_AV1_TILECONTROLPARAMETER_TASK,
VA_TRACE_API_AVC_PICTUREPARAMETER_TASK,
VA_TRACE_API_AVC_SLICEPARAMETER_TASK,
VA_TRACE_API_AVC_QMATRIXARAMETER_TASK,
VA_TRACE_API_HEVC_PICTUREPARAMETER_TASK,
VA_TRACE_API_HEVC_SLICEPARAMETER_TASK,
VA_TRACE_API_HEVC_QMATRIXARAMETER_TASK,
VA_TRACE_API_VP9_PICTUREPARAMETER_TASK,
VA_TRACE_API_VP9_SLICEPARAMETER_TASK,
VA_TRACE_API_HEVC_DPBPARAMETER_TASK,
MFX_TRACE_PIPELINE_STICKER_TASK,
VPLMessage_TASK,
MFX_TRACE_API_DECODE_RESET_TASK,
MFX_TRACE_API_DECODE_GETVIDEOPARAM_TASK,
MFX_TRACE_API_DECODE_GETSTAT_TASK,
MFX_TRACE_API_DECODE_SETSKIPMODE_TASK,
MFX_TRACE_API_DECODE_GETPAYLOAD_TASK,
MFX_TRACE_API_GETSURFACE_TASK,
MFX_TRACE_API_DECODE_VPP_INIT_TASK,
MFX_TRACE_API_DECODE_VPP_CLOSE_TASK,
MFX_TRACE_API_DECODE_VPP_RESET_TASK,
MFX_TRACE_API_DECODE_VPP_FRAMEASYNC_TASK,
MFX_TRACE_API_DOFASTCOPY_WRAPPER_TASK,
MFX_TRACE_API_ADD_TASK,
MFX_TRACE_API_GET_TASK,
MFX_TRACE_API_QUERY_TASK,
MFX_TRACE_API_MARK_TASK,
#if defined(ONEVPL_EXPERIMENTAL)
MFX_TRACE_API_MFXQUERYIMPLSPROPERTIES_TASK,
#endif
};
// list of output modes
enum
{
MFX_TRACE_OUTPUT_TRASH = 0x00,
MFX_TRACE_OUTPUT_TEXTLOG = 0x01,
MFX_TRACE_OUTPUT_STAT = 0x02,
MFX_TRACE_OUTPUT_ETW = 0x04,
MFX_TRACE_OUTPUT_TAL = 0x08,
MFX_TRACE_OUTPUT_ITT = 0x10,
MFX_TRACE_OUTPUT_FTRACE = 0x20,
// special keys
MFX_TRACE_OUTPUT_ALL = 0xFFFFFFFF,
MFX_TRACE_OUTPUT_REG = MFX_TRACE_OUTPUT_ALL // output mode should be read from registry
};
// enumeration of the trace levels inside any category
typedef enum
{
MFX_TRACE_LEVEL_0 = 0,
MFX_TRACE_LEVEL_1 = 1,
MFX_TRACE_LEVEL_2 = 2,
MFX_TRACE_LEVEL_3 = 3,
MFX_TRACE_LEVEL_4 = 4,
MFX_TRACE_LEVEL_5 = 5,
MFX_TRACE_LEVEL_6 = 6,
MFX_TRACE_LEVEL_7 = 7,
MFX_TRACE_LEVEL_8 = 8,
MFX_TRACE_LEVEL_9 = 9,
MFX_TRACE_LEVEL_10 = 10,
MFX_TRACE_LEVEL_11 = 11,
MFX_TRACE_LEVEL_12 = 12,
MFX_TRACE_LEVEL_13 = 13,
MFX_TRACE_LEVEL_14 = 14,
MFX_TRACE_LEVEL_15 = 15,
MFX_TRACE_LEVEL_16 = 16,
MFX_TRACE_LEVEL_MAX = 0xFF
} mfxTraceLevel;
// enumeration of the TXT log levels
typedef enum
{
MFX_TXTLOG_LEVEL_MAX = 1, //include API Func, API PARAMS and internal Func
MFX_TXTLOG_LEVEL_API_AND_INTERNAL = 2, //include API Func and internal Func
MFX_TXTLOG_LEVEL_API_AND_PARAMS = 3, //include API Func and API PARAMS
MFX_TXTLOG_LEVEL_API = 4, //include API Func
} mfxTxtLogLevel;
typedef enum _MEDIA_EVENT_TYPE
{
EVENT_TYPE_INFO = 0, //! function information event
EVENT_TYPE_START = 1, //! function entry event
EVENT_TYPE_END = 2, //! function exit event
EVENT_TYPE_INFO2 = 3, //! function extra information event
} MEDIA_EVENT_TYPE;
//!
//! \brief Keyword for ETW tracing, 1bit per keyworld, total 64bits
//!
typedef enum _MEDIA_EVENT_FILTER_KEYID
{
//Common key
TR_KEY_MFX_API = 0,
TR_KEY_DDI_API,
TR_KEY_INTERNAl,
//Decode key
TR_KEY_DECODE_PICPARAM,
TR_KEY_DECODE_SLICEPARAM,
TR_KEY_DECODE_TILEPARAM,
TR_KEY_DECODE_QMATRIX,
TR_KEY_DECODE_SEGMENT,
TR_KEY_DECODE_BITSTREAM_INFO,
TR_KEY_DECODE_DPB_INFO,
TR_KEY_DECODE_BASIC_INFO,
TR_KEY_PIPELINE_STICKER,
} MEDIA_EVENT_FILTER_KEYID;
#define MFX_ETWLOG_ENABLE 16
// delete the following levels completely
#define MFX_TRACE_LEVEL_SCHED MFX_TRACE_LEVEL_10
#define MFX_TRACE_LEVEL_PRIVATE MFX_TRACE_LEVEL_16
// the following levels should remain only
/** API level
* - Media SDK library entry points exposed in Media SDK official API
* - Media SDK library important internal entry points
*/
#define MFX_TRACE_LEVEL_API MFX_TRACE_LEVEL_1
/** HOTSPOTS level
* - Known Media SDK library internal hotspots (functions taking > ~50us on selected platforms/contents)
*/
#define MFX_TRACE_LEVEL_HOTSPOTS MFX_TRACE_LEVEL_2
/** EXTCALL level
* - Calls to external libaries (DXVA, LibVA, MDF/CM, etc.)
*/
#define MFX_TRACE_LEVEL_EXTCALL MFX_TRACE_LEVEL_2 // should be MFX_TRACE_LEVEL_3
/** SCHEDULER level
* - Media SDK internal scheduler functions calls
*/
#define MFX_TRACE_LEVEL_API_PARAMS MFX_TRACE_LEVEL_4
/** INTERNAL level
* - Media SDK components function calls. Use this level to get more deeper knowledge of
* calling stack.
*/
#define MFX_TRACE_LEVEL_INTERNAL MFX_TRACE_LEVEL_5
/** PARAMS level
* - Tracing of function parameters, variables, etc. Note that not all tracing modules support this.
*/
#define MFX_TRACE_LEVEL_PARAMS MFX_TRACE_LEVEL_6
/** WARNING level
* - Tracing of warning info
*/
#define MFX_TRACE_LEVEL_WARNING_INFO MFX_TRACE_LEVEL_7
/** CRITICAL level
* - Tracing of critical info
*/
#define MFX_TRACE_LEVEL_CRITICAL_INFO MFX_TRACE_LEVEL_8
// defines default trace category
#define MFX_TRACE_CATEGORY_DEFAULT NULL
// defines category for the current module
#ifndef MFX_TRACE_CATEGORY
#define MFX_TRACE_CATEGORY MFX_TRACE_CATEGORY_DEFAULT
#endif
// defines default trace level
#define MFX_TRACE_LEVEL_DEFAULT MFX_TRACE_LEVEL_MAX
// defines default trace level for the current module
#ifndef MFX_TRACE_LEVEL
#define MFX_TRACE_LEVEL MFX_TRACE_LEVEL_DEFAULT
#endif
// Perf traces
mfxTraceU32 MFXTrace_EventInit();
mfxTraceU32 MFXTrace_EventClose();
/*------------------------------------------------------------------------------*/
#ifdef MFX_TRACE_ENABLE
typedef union
{
unsigned int uint32;
__UINT64 uint64;
__INT64 tick;
char* str;
void* ptr;
mfxTraceChar* category;
mfxTraceLevel level;
} mfxTraceHandle;
typedef struct
{
uint64_t callCount;
double totalTime;
}TimeStampInfo;
typedef struct
{
mfxTraceChar* category;
mfxTraceLevel level;
// reserved for stat dump:
mfxTraceHandle sd1;
mfxTraceHandle sd2;
mfxTraceHandle sd3;
mfxTraceHandle sd4;
mfxTraceHandle sd5;
mfxTraceHandle sd6;
mfxTraceHandle sd7;
// reserved for itt
mfxTraceHandle itt1;
//timeStamp
TimeStampInfo tick;
} mfxTraceStaticHandle;
typedef struct
{
// reserved for file dump:
mfxTraceHandle fd1;
mfxTraceHandle fd2;
mfxTraceHandle fd3;
mfxTraceHandle fd4;
// reserved for stat dump:
mfxTraceHandle sd1;
// reserved for TAL:
mfxTraceHandle tal1;
// reserved for ETW:
mfxTraceHandle etw1;
mfxTraceHandle etw2;
mfxTraceHandle etw3;
// reserved for itt
mfxTraceHandle itt1;
} mfxTraceTaskHandle;
/*------------------------------------------------------------------------------*/
// basic trace functions (macroses are recommended to use instead)
mfxTraceU32 MFXTrace_Init();
mfxTraceU32 MFXTrace_Close(void);
mfxTraceU32 MFXTrace_SetLevel(mfxTraceChar* category,
mfxTraceLevel level);
mfxTraceU32 MFXTrace_DebugMessage(mfxTraceStaticHandle *static_handle,
const char *file_name, mfxTraceU32 line_num,
const char *function_name,
mfxTraceChar* category, mfxTraceLevel level,
const char *message,
const char *format, ...);
mfxTraceU32 MFXTrace_vDebugMessage(mfxTraceStaticHandle *static_handle,
const char *file_name, mfxTraceU32 line_num,
const char *function_name,
mfxTraceChar* category, mfxTraceLevel level,
const char *message,
const char *format, va_list args);
mfxTraceU32 MFXTrace_BeginTask(mfxTraceStaticHandle *static_handle,
const char *file_name, mfxTraceU32 line_num,
const char *function_name,
mfxTraceChar* category, mfxTraceLevel level,
const char *task_name, const mfxTraceTaskType task_type,
mfxTraceTaskHandle *task_handle,
const void *task_params);
mfxTraceU32 MFXTrace_EndTask(mfxTraceStaticHandle *static_handle,
mfxTraceTaskHandle *task_handle);
/*------------------------------------------------------------------------------*/
// Perf traces
mfxTraceU32 MFXTraceEvent(uint16_t task, uint8_t opcode, uint8_t level, uint64_t size, const void *ptr);
#ifdef __cplusplus
}
#endif
#pragma pack(push, 2)
// struct event_data contains arguments we need to trace in perf events
// It contains variadic amount of arguments
template <typename ...>
struct event_data;
template <>
struct event_data<>
{
event_data() = default;
};
template <typename T, typename ...Rest>
struct event_data<T, Rest...>
: event_data<Rest...>
{
typename std::decay<T>::type value;
template <typename A, typename ...Args>
event_data(A&& a, Args&&... args)
: event_data<Rest...>(std::forward<Args>(args)...)
, value(std::forward<A>(a))
{}
};
#pragma pack(pop)
// Utility function for maintaining correct arguments order in event_data<...>()
template <typename Tuple, std::size_t... I>
auto make_event_data(Tuple&& t, std::index_sequence<I...>)
{
return event_data<
typename std::tuple_element<sizeof...(I) - I - 1, Tuple>::type...
>(std::get<sizeof...(I) - I - 1>(std::forward<Tuple>(t))...);
}
// Helper function for creating event_data<...>() object
template <typename ...Args>
auto make_event_data(Args&&... args)
{
return make_event_data(
std::forward_as_tuple(std::forward<Args>(args)...),
std::make_index_sequence<sizeof...(args)>{}
);
}
// PerfScopedTrace objects are created using PERF_EVENT macro
class PerfScopedTrace
{
public:
template <typename ...Args>
PerfScopedTrace(uint16_t task, uint8_t ucType, uint8_t level, event_data<Args...> data)
{
// Send event data on PerfScopedTrace creation
write(task, ucType, level, data);
}
~PerfScopedTrace()
{
}
template <typename T>
static void write(uint16_t task, uint8_t opcode, uint8_t level, T&& data)
{
MFXTraceEvent(task, opcode, level, sizeof(data), &data);
}
static void write(uint16_t task, uint8_t opcode, uint8_t level, event_data<>& /*data*/)
{
MFXTraceEvent(task, opcode, level, 0, nullptr);
}
template <typename T>
static void thunk(void* f, uint16_t task, uint8_t level)
{
std::unique_ptr<T> p { static_cast<T*>(f) };
auto e = (*p)();
// Send event data at function exit
write(task, 2, level, e);
}
template <typename T>
static constexpr auto get_thunk() noexcept {
return &thunk<T>;
}
};
#define TRACE_CHECK(keyWord) \
(EventCfg & (1 << keyWord)) || keyWord == TR_KEY_MFX_API || keyWord == TR_KEY_DDI_API || keyWord == TR_KEY_INTERNAl
// This macro is recommended to use instead creating RT Info ScopedTrace object directly
#define TRACE_BUFFER_EVENT(task, level, keyWord, pData, funcName, structType) \
if (TRACE_CHECK(keyWord)) \
{ \
EVENTDATA_##structType eventData; \
Event##funcName(&eventData, pData); \
PerfScopedTrace _info_scoped_trace##__LINE__(task, level, 0, make_event_data(eventData)); \
}
#define TRACE_EVENT(task, level, keyWord, at_exit_func) \
if (TRACE_CHECK(keyWord)) \
{ \
PerfScopedTrace _info_scoped_trace##__LINE__(task, level, 0, at_exit_func); \
}
#ifdef __cplusplus
extern "C" {
#endif
/*------------------------------------------------------------------------------*/
// basic macroses
#define MFX_TRACE_PARAMS \
&_trace_static_handle, __FILE__, __LINE__, __FUNCTION__, MFX_TRACE_CATEGORY
#define MFX_TRACE_INIT() \
MFXTrace_Init();
#define MFX_TRACE_INIT_RES(_res) \
_res = MFXTrace_Init();
#define MFX_TRACE_CLOSE() \
MFXTrace_Close();
#define MFX_TRACE_CLOSE_RES(_res) \
_res = MFXTrace_Close();
#define MFX_LTRACE(_trace_all_params) \
{ \
DISABLE_WARN_HIDE_PREV_LOCAL_DECLARATION \
static mfxTraceStaticHandle _trace_static_handle = {}; \
MFXTrace_DebugMessage _trace_all_params; \
ROLLBACK_WARN_HIDE_PREV_LOCAL_DECLARATION \
}
#else
#define MFX_TRACE_INIT()
#define MFX_TRACE_INIT_RES(res)
#define MFX_TRACE_CLOSE()
#define MFX_TRACE_CLOSE_RES(res)
#define MFX_LTRACE(_trace_all_params)
#define PERF_EVENT(task, level, ...)
#define TRACE_EVENT(task, level, ...)
#endif
/*------------------------------------------------------------------------------*/
// standard formats
#define MFX_TRACE_FORMAT_S "%s"
#define MFX_TRACE_FORMAT_WS "%S"
#define MFX_TRACE_FORMAT_P "%p"
#define MFX_TRACE_FORMAT_I "%d"
#define MFX_TRACE_FORMAT_X "%x"
#define MFX_TRACE_FORMAT_D "%d (0x%x)"
#define MFX_TRACE_FORMAT_F "%g"
#define MFX_TRACE_FORMAT_GUID "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}"
/*------------------------------------------------------------------------------*/
// these macroses permit to set trace level
#define MFX_LTRACE_1(_level, _message, _format, _arg1) \
MFX_LTRACE((MFX_TRACE_PARAMS, _level, _message, _format, _arg1))
#define MFX_LTRACE_2(_level, _message, _format, _arg1, _arg2) \
MFX_LTRACE((MFX_TRACE_PARAMS, _level, _message, _format, _arg1, _arg2))
#define MFX_LTRACE_3(_level, _message, _format, _arg1, _arg2, _arg3) \
MFX_LTRACE((MFX_TRACE_PARAMS, _level, _message, _format, _arg1, _arg2, _arg3))
#define MFX_LTRACE_MSG(_level, _message) \
MFX_LTRACE_1(_level, _message, NULL, 0)
#define MFX_LTRACE_MSG_1(_level, ...) \
{\
char str[256]; \
sprintf(str, __VA_ARGS__); \
MFX_LTRACE_MSG(_level, str); \
}\
#define MFX_LTRACE_S(_level, _string) \
MFX_LTRACE_1(_level, #_string " = ", MFX_TRACE_FORMAT_S, _string)
#define MFX_LTRACE_WS(_level, _string) \
MFX_LTRACE_1(_level, #_string " = ", MFX_TRACE_FORMAT_WS, _string)
#define MFX_LTRACE_P(_level, _arg1) \
MFX_LTRACE_1(_level, #_arg1 " = ", MFX_TRACE_FORMAT_P, _arg1)
#define MFX_LTRACE_X(_level, _arg1) \
MFX_LTRACE_1(_level, #_arg1 " = ", MFX_TRACE_FORMAT_X, _arg1)
#define MFX_LTRACE_D(_level, _arg1) \
MFX_LTRACE_2(_level, #_arg1 " = ", MFX_TRACE_FORMAT_D, _arg1, _arg1)
#define MFX_LTRACE_F(_level, _arg1) \
MFX_LTRACE_1(_level, #_arg1 " = ", MFX_TRACE_FORMAT_F, _arg1)
#ifdef MFX_TRACE_ENABLE
#define MFX_LTRACE_BUFFER_S(_level, _name, _buffer, _size) \
if (_buffer) \
MFX_LTRACE_2(_level, _name, "%p[%lu]", _buffer, _size)
#else
#define MFX_LTRACE_BUFFER_S(_level, _name, _buffer, _size)
#endif
#ifdef MFX_TRACE_ENABLE
#define MFX_LTRACE_BUFFER(_level, _message, _buffer) \
{ \
if (0 != LogConfig && _buffer) \
{ \
DumpContext context; \
std::string _str; \
try \
{ \
_str = context.dump(#_buffer, *_buffer); \
} \
catch(...) \
{ \
return MFX_ERR_UNKNOWN; \
} \
MFX_LTRACE_1(_level, "\n" _message, "%s", _str.c_str()) \
} \
else { \
MFX_LTRACE_BUFFER_S(_level, #_buffer, _buffer, sizeof(*_buffer))\
} \
}
#else
#define MFX_LTRACE_BUFFER(_level, _buffer) \
MFX_LTRACE_BUFFER_S(_level, #_buffer, _buffer, sizeof(*_buffer))
#endif
#define MFX_LTRACE_GUID(_level, _guid) \
MFX_LTRACE((MFX_TRACE_PARAMS, _level, #_guid " = ", \
MFX_TRACE_FORMAT_GUID, \
(_guid).Data1, (_guid).Data2, (_guid).Data3, \
(_guid).Data4[0], (_guid).Data4[1], (_guid).Data4[2], (_guid).Data4[3], \
(_guid).Data4[4], (_guid).Data4[5], (_guid).Data4[6], (_guid).Data4[7]))
/*------------------------------------------------------------------------------*/
// these macroses uses default trace level
#define MFX_TRACE_1(_message, _format, _arg1) \
MFX_LTRACE_1(MFX_TRACE_LEVEL, _message, _format, _arg1)
#define MFX_TRACE_2(_message, _format, _arg1, _arg2) \
MFX_LTRACE_2(MFX_TRACE_LEVEL, _message, _format, _arg1, _arg2)
#define MFX_TRACE_3(_message, _format, _arg1, _arg2, _arg3) \
MFX_LTRACE_3(MFX_TRACE_LEVEL, _message, _format, _arg1, _arg2, _arg3)
#define MFX_TRACE_S(_arg1) \
MFX_LTRACE_S(MFX_TRACE_LEVEL, _arg1)
#define MFX_TRACE_WS(_message) \
MFX_LTRACE_WS(MFX_TRACE_LEVEL, _message)
#define MFX_TRACE_P(_arg1) \
MFX_LTRACE_P(MFX_TRACE_LEVEL, _arg1)
#define MFX_TRACE_I(_arg1) \
MFX_LTRACE_I(MFX_TRACE_LEVEL, _arg1)
#define MFX_TRACE_X(_arg1) \
MFX_LTRACE_X(MFX_TRACE_LEVEL, _arg1)
#define MFX_TRACE_D(_arg1) \
MFX_LTRACE_D(MFX_TRACE_LEVEL, _arg1)
#define MFX_TRACE_F(_arg1) \
MFX_LTRACE_F(MFX_TRACE_LEVEL, _arg1)
#define MFX_TRACE_GUID(_guid) \
MFX_LTRACE_GUID(MFX_TRACE_LEVEL, _guid)
#define MFX_TRACE_BUFFER(_name, _buffer, _size) \
MFX_LTRACE_BUFFER(MFX_TRACE_LEVEL, _name, _buffer, _size)
// New Macro for VPL Log
#define MFX_CRITICAL_MSG(...) \
{ \
MFX_LTRACE_MSG_1(MFX_TRACE_LEVEL_CRITICAL_INFO, __VA_ARGS__);\
} \
#define MFX_WARNING_MSG(...) \
{ \
MFX_LTRACE_MSG_1(MFX_TRACE_LEVEL_WARNING_INFO, __VA_ARGS__);\
} \
#define MFX_NORMAL_MSG(...) \
{ \
MFX_LTRACE_MSG_1(MFX_TRACE_LEVEL_PARAMS, __VA_ARGS__);\
} \
#define MFX_CHECK_STATUS_RETURN(sts)\
{\
if(sts!=0)\
{\
MFX_LTRACE_I(MFX_TRACE_LEVEL_PARAMS, sts);\
return sts;\
}\
}\
#define MFX_CHECK_STS_MSG_RETURN(sts, ...) \
{ \
MFXLTraceI mFXLTraceI; \
auto status_tmp = (sts); \
if (status_tmp != 0) \
{ \
int8_t sts_type = mFXLTraceI.check_sts_type(status_tmp); \
if (sts_type < 0) \
{ \
MFX_CRITICAL_MSG(__VA_ARGS__); \
} \
else if (sts_type > 0) \
{ \
MFX_WARNING_MSG(__VA_ARGS__); \
} \
mFXLTraceI.mfx_ltrace_i(MFX_TRACE_LEVEL_PARAMS, "Status", __FUNCTION__, __FILE__, __LINE__, status_tmp); \
return status_tmp; \
}\
} \
/*------------------------------------------------------------------------------*/
#ifdef __cplusplus
} // extern "C"
#endif
/*------------------------------------------------------------------------------*/
// C++ section
#ifdef __cplusplus
#include "mfx_reflect.h"
mfx_reflect::AccessibleTypesCollection GetReflection();
#ifdef MFX_TRACE_ENABLE
// C++ class for BeginTask/EndTask
class MFXTraceTask
{
public:
MFXTraceTask(mfxTraceStaticHandle *static_handle,
const char *file_name, mfxTraceU32 line_num,
const char *function_name,
mfxTraceChar* category, mfxTraceLevel level,
const char *task_name,
const mfxTraceTaskType task_type,
const bool bCreateID = false);
mfxTraceU32 GetID();
void Stop();
~MFXTraceTask();
private:
bool m_bStarted;
mfxTraceU32 m_TaskID;
mfxTraceStaticHandle *m_pStaticHandle;
mfxTraceTaskHandle m_TraceTaskHandle;
};
#endif // #ifdef MFX_TRACE_ENABLE
/*------------------------------------------------------------------------------*/
// auto tracing of the functions
#ifdef MFX_TRACE_ENABLE
#define _MFX_AUTO_LTRACE_(_level, _task_name, _task_type, _bCreateID) \
DISABLE_WARN_HIDE_PREV_LOCAL_DECLARATION \
static mfxTraceStaticHandle _trace_static_handle; \
MFXTraceTask _mfx_trace_task(MFX_TRACE_PARAMS, _level, _task_name, _task_type, _bCreateID); \
ROLLBACK_WARN_HIDE_PREV_LOCAL_DECLARATION
#define MFX_AUTO_TRACE_STOP() _mfx_trace_task.Stop()
#define MFX_AUTO_TRACE_GETID() _mfx_trace_task.GetID()
#else
#define _MFX_AUTO_LTRACE_(_level, _task_name, _task_type, _bCreateID)
#define MFX_AUTO_TRACE_STOP()
#define MFX_AUTO_TRACE_GETID() 0
#endif
#define MFX_AUTO_LTRACE(_level, _task_name) \
_MFX_AUTO_LTRACE_(_level, _task_name, MFX_TRACE_DEFAULT_TASK, false)
#define MFX_AUTO_TRACE(_task_name) \
_MFX_AUTO_LTRACE_(MFX_TRACE_LEVEL, _task_name, MFX_TRACE_DEFAULT_TASK, false)
#define MFX_AUTO_LTRACE_FUNC(_level) \
_MFX_AUTO_LTRACE_(_level, __FUNCTION__, MFX_TRACE_DEFAULT_TASK, false)
#define MFX_AUTO_LTRACE_WITHID(_level, _task_name) \
_MFX_AUTO_LTRACE_(_level, _task_name, MFX_TRACE_DEFAULT_TASK, true)
#define MFX_AUTO_TRACE_WITHID(_task_name) \
_MFX_AUTO_LTRACE_(MFX_TRACE_LEVEL, _task_name, MFX_TRACE_DEFAULT_TASK, true)
#ifdef MFX_TRACE_ENABLE
class MFXLTraceI
{
public:
template <typename T>
int8_t check_sts_type(T sts)
{
if (sts > 0)
return 1;
else if (sts < 0)
return -1;
else
return 0;
}
int8_t check_sts_type(mfxStatus sts)
{
if (sts > MFX_ERR_NONE || sts == MFX_ERR_MORE_DATA || sts == MFX_ERR_MORE_SURFACE || sts == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) //MFX_ERR_MORE_DATA, MFX_ERR_MORE_SURFACE and MFX_ERR_INCOMPATIBLE_VIDEO_PARAM are warning status
return 1;
else if (sts < MFX_ERR_NONE)
return -1;
else
return 0;
}
template <typename T>
void mfx_ltrace_i(mfxTraceLevel _level, const char* _mesg, const char* _function, const char* _filename, mfxTraceU32 _line, T _arg1)
{
std::stringstream ss;
if (_arg1 > 0)
{
ss << "[Warning] ";
}
else if (_arg1 < 0)
{
ss << "[Critical] ";
}
ss << _mesg << " = ";
MFX_LTRACE((&_trace_static_handle, _filename, _line, _function, MFX_TRACE_CATEGORY, _level, ss.str().c_str(), MFX_TRACE_FORMAT_I, _arg1))
}
void mfx_ltrace_i(mfxTraceLevel _level, const char* _mesg, const char* _function, const char* _filename, mfxTraceU32 _line, mfxStatus _arg1)
{
std::error_code code = mfx::make_error_code(_arg1);
std::stringstream ss;
if (_arg1 > MFX_ERR_NONE || _arg1 == MFX_ERR_MORE_DATA || _arg1 == MFX_ERR_MORE_SURFACE || _arg1 == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) //MFX_ERR_MORE_DATA, MFX_ERR_MORE_SURFACE and MFX_ERR_INCOMPATIBLE_VIDEO_PARAM are warning status
{
ss << "[Warning] ";
}
else if (_arg1 < MFX_ERR_NONE)
{
ss << "[Critical] ";
}
ss << _mesg << " = ";
MFX_LTRACE((&_trace_static_handle, _filename, _line, _function, MFX_TRACE_CATEGORY, _level, ss.str().c_str(), MFX_TRACE_FORMAT_S, code.message().c_str()))
}
};
#define MFX_LTRACE_I(_level, _arg1) \
{ \
MFXLTraceI mFXLTraceI; \
try \
{ \
mFXLTraceI.mfx_ltrace_i(_level, #_arg1, __FUNCTION__, __FILE__, __LINE__,_arg1); \
} \
catch(...) \
{ \
std::cerr << "Trace failed!" << '\n'; \
} \
}
#else
#define MFX_LTRACE_I(_level, _arg1) \
MFX_LTRACE_1(_level, #_arg1 " = ", MFX_TRACE_FORMAT_I, _arg1)
#endif
#endif // ifdef __cplusplus
template <int TYPE>
struct TraceTaskType2TraceLevel;
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_DEFAULT_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_DECODE_QUERY_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_DECODE_QUERY_IOSURF_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_DECODE_HEADER_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_DECODE_INIT_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_DECODE_CLOSE_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_DECODE_FRAME_ASYNC_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_ENCODE_QUERY_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_ENCODE_QUERY_IOSURF_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_ENCODE_INIT_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_ENCODE_CLOSE_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_ENCODE_FRAME_ASYNC_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_VPP_QUERY_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_VPP_QUERY_IOSURF_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_VPP_INIT_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_VPP_CLOSE_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_VPP_LEGACY_ROUTINE_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_VPP_RUN_FRAME_VPP_ASYNC_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_VPP_RUN_FRAME_VPP_ASYNC_EX_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_MFX_INIT_EX_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_MFX_CLOSE_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_DO_WORK_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_SYNC_OPERATION_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_SCHED_WAIT_GLOBAL_EVENT_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_DDI_SUBMIT_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_DDI_EXECUTE_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_DDI_ENDFRAME_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_DDI_WAIT_TASK_SYNC> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_DDI_QUERY_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_CM_COPY> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_COPY_DX11_TO_DX9> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_COPY_DX9_TO_DX11> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_HOTSPOT_SCHED_ROUTINE> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_HOTSPOTS> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_MFXINITIALIZE_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_MFXQUERYIMPLSDESCRIPTION_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
#if defined(ONEVPL_EXPERIMENTAL)
template <>
struct TraceTaskType2TraceLevel<MFX_TRACE_API_MFXQUERYIMPLSPROPERTIES_TASK> : std::integral_constant<mfxTraceLevel, MFX_TRACE_LEVEL_API> {};
#endif
#endif // #ifndef __MFX_TRACE_H__
|