Skip to content

Commit

Permalink
Capture and Replay: XBTRACER module inclusion (Xilinx#8466)
Browse files Browse the repository at this point in the history
* Added xbtracer launcher application

This application for now launches the executabled passed to it as
argument

ex.
  xbtracer -v "Debug/opt/xilinx/xrt/bin/xrt-smi --help"

Signed-off-by: Harsh Wardhan <[email protected]>

* Added logger module.

This module provide infra to trace the APIs and data.
Traces(.txt and .bin) are written into seperate directory based
on execution timestamp.

Signed-off-by: Harsh Wardhan <[email protected]>

* Added interception support for linux platform

few APIs from xrt::device has been instrumented in this commit
other required infrastructure for linux platform has been fully
commited.

Signed-off-by: Harsh Wardhan <[email protected]>

* Added interception support for windows platform

Signed-off-by: Harsh Wardhan <[email protected]>

* Added instrumentation wrapper for other APIs

extended instrumentation to other APIs planned for tracing

Signed-off-by: Harsh Wardhan <[email protected]>

---------

Signed-off-by: Harsh Wardhan <[email protected]>
Co-authored-by: rajiv448 <[email protected]>
  • Loading branch information
theharshwardhan and rajiv448 authored Oct 3, 2024
1 parent 4e009c4 commit 266b98d
Show file tree
Hide file tree
Showing 26 changed files with 3,638 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/runtime_src/core/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (${XRT_BOOST_VERSION} VERSION_LESS 1.64.0)
endif()

xrt_add_subdirectory(xbutil2)
xrt_add_subdirectory(xbtracer)
if (${XRT_NATIVE_BUILD} STREQUAL "yes")
xrt_add_subdirectory(xbmgmt2)
if(NOT WIN32)
Expand Down
44 changes: 44 additions & 0 deletions src/runtime_src/core/tools/xbtracer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved
# -----------------------------------------------------------------------------
# Include the generated header files (e.g., version.h)
include_directories(${XRT_BINARY_DIR}/gen)

set(XBTRACER_NAME "xbtracer")

if(WIN32)
set(XRT_HELPER_SCRIPTS "xbtracer" "xbtracer.bat")
else()
set(XRT_HELPER_SCRIPTS "xbtracer")
endif()

set(SRCS src/app/launcher.cpp)
if (WIN32)
list(APPEND SRCS src/app/getopt.c)
endif()

add_executable(${XBTRACER_NAME} ${SRCS})

# Static build is a Linux / Ubuntu option only
if (XRT_STATIC_BUILD)
add_executable(${XBTRACER_NAME}_static ${SRCS})
target_link_options(${XBTRACER_NAME}_static PRIVATE "-static" "-L${Boost_LIBRARY_DIRS}")
# Bypass FindBoost versions and just link explicitly with boost libraries
# The -static link option will pick the static libraries.
target_link_libraries(${XBTRACER_NAME}_static
PRIVATE
xrt_coreutil_static
boost_system
boost_program_options
-Wl,--whole-archive rt pthread -Wl,--no-whole-archive
uuid
dl
)
set_target_properties(${XBTRACER_NAME}_static PROPERTIES INSTALL_RPATH "")
install(TARGETS ${XBTRACER_NAME}_static RUNTIME DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR})
endif()

install (TARGETS ${XBTRACER_NAME} RUNTIME DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR})
install (PROGRAMS ${XRT_HELPER_SCRIPTS} DESTINATION ${XRT_INSTALL_BIN_DIR})

add_subdirectory(src/lib)
51 changes: 51 additions & 0 deletions src/runtime_src/core/tools/xbtracer/src/app/getopt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* *****************************************************************
*
* Copyright 2016 Microsoft
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************/

#include "getopt.h"
#include <windows.h>

char* optarg = NULL;
int optind = 1;

int getopt(int argc, char *const argv[], const char *optstring)
{
if ((optind >= argc) || (argv[optind][0] != '-') || (argv[optind][0] == 0))
{
return -1;
}

int opt = argv[optind++][1];
const char *p = strchr(optstring, opt);

if (p == NULL)
{
return '?';
}
if (p[1] == ':')
{
//optind++;
if (optind >= argc)
{
return '?';
}
optarg = argv[optind];
optind++;
}
return opt;
}
36 changes: 36 additions & 0 deletions src/runtime_src/core/tools/xbtracer/src/app/getopt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* *****************************************************************
*
* Copyright 2016 Microsoft
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************/

#ifndef GETOPT_H__
#define GETOPT_H__

#ifdef __cplusplus
extern "C" {
#endif

extern char *optarg;
extern int optind;

int getopt(int argc, char *const argv[], const char *optstring);

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 266b98d

Please sign in to comment.