diff --git a/projects/rocprofiler/.cmake-format.yaml b/projects/rocprofiler/.cmake-format.yaml new file mode 100644 index 0000000000..1d1aba5305 --- /dev/null +++ b/projects/rocprofiler/.cmake-format.yaml @@ -0,0 +1,98 @@ +parse: + additional_commands: + find_package: + flags: + - EXACT + - QUIET + - MODULE + - REQUIRED + - CONFIG + - NO_MODULE + - GLOBAL + - NO_POLICY_SCOPE + - BYPASS_PROVIDER + - NO_DEFAULT_PATH + - NO_PACKAGE_ROOT_PATH + - NO_CMAKE_PATH + - NO_CMAKE_ENVIRONMENT_PATH + - NO_SYSTEM_ENVIRONMENT_PATH + - NO_CMAKE_PACKAGE_REGISTRY + - NO_CMAKE_BUILDS_PATH + - NO_CMAKE_SYSTEM_PATH + - NO_CMAKE_INSTALL_PREFIX + - NO_CMAKE_SYSTEM_PACKAGE_REGISTRY + - CMAKE_FIND_ROOT_PATH_BOTH + - ONLY_CMAKE_FIND_ROOT_PATH + - NO_CMAKE_FIND_ROOT_PATH + kwargs: + COMPONENTS: '*' + OPTIONAL_COMPONENTS: '*' + NAMES: '*' + CONFIGS: '*' + HINTS: '*' + PATHS: '*' + REGISTRY_VIEW: '*' + PATH_SUFFIXES: '*' + override_spec: {} + vartags: [] + proptags: [] +format: + disable: false + line_width: 90 + tab_size: 4 + use_tabchars: false + fractional_tab_policy: use-space + max_subgroups_hwrap: 2 + max_pargs_hwrap: 8 + max_rows_cmdline: 2 + separate_ctrl_name_with_space: false + separate_fn_name_with_space: false + dangle_parens: false + dangle_align: child + min_prefix_chars: 4 + max_prefix_chars: 10 + max_lines_hwrap: 2 + line_ending: unix + command_case: lower + keyword_case: upper + always_wrap: [] + enable_sort: true + autosort: false + require_valid_layout: false + layout_passes: {} +markup: + bullet_char: '*' + enum_char: . + first_comment_is_literal: true + literal_comment_pattern: ^# + fence_pattern: ^\s*([`~]{3}[`~]*)(.*)$ + ruler_pattern: ^\s*[^\w\s]{3}.*[^\w\s]{3}$ + explicit_trailing_pattern: '#<' + hashruler_min_length: 10 + canonicalize_hashrulers: true + enable_markup: true +lint: + disabled_codes: [] + function_pattern: '[0-9a-z_]+' + macro_pattern: '[0-9A-Z_]+' + global_var_pattern: '[A-Z][0-9A-Z_]+' + internal_var_pattern: _[A-Z][0-9A-Z_]+ + local_var_pattern: '[a-z][a-z0-9_]+' + private_var_pattern: _[0-9a-z_]+ + public_var_pattern: '[A-Z][0-9A-Z_]+' + argument_var_pattern: '[a-z][a-z0-9_]+' + keyword_pattern: '[A-Z][0-9A-Z_]+' + max_conditionals_custom_parser: 2 + min_statement_spacing: 1 + max_statement_spacing: 2 + max_returns: 6 + max_branches: 12 + max_arguments: 5 + max_localvars: 15 + max_statements: 50 +encode: + emit_byteorder_mark: false + input_encoding: utf-8 + output_encoding: utf-8 +misc: + per_command: {} diff --git a/projects/rocprofiler/.github/workflows/cmake.yml b/projects/rocprofiler/.github/workflows/cmake.yml index 55f991a628..a8c8581dbb 100644 --- a/projects/rocprofiler/.github/workflows/cmake.yml +++ b/projects/rocprofiler/.github/workflows/cmake.yml @@ -34,16 +34,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Restore cached Build - id: cache-build-restore - uses: actions/cache/restore@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_ubuntu_22_04 - - name: Configure CMake - if: steps.cache-build-restore.outputs.cache-hit != 'false' # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -56,14 +47,6 @@ jobs: - name: Build Tests, Samples, Documentation, Packages run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 16 tests samples doc package - - name: Save Build - id: cache-build-save - uses: actions/cache/save@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_ubuntu_22_04 - - name: Testing V1 run: | cd ${{github.workspace}}/build @@ -102,16 +85,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Restore cached Build - id: cache-build-restore - uses: actions/cache/restore@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_ubuntu_20_04 - - name: Configure CMake - if: steps.cache-build-restore.outputs.cache-hit != 'false' # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -153,16 +127,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Restore cached Build - id: cache-build-restore - uses: actions/cache/restore@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_sles - - name: Configure CMake - if: steps.cache-build-restore.outputs.cache-hit != 'false' # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -175,14 +140,6 @@ jobs: - name: Build Tests run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 16 tests - - name: Save Build - id: cache-build-save - uses: actions/cache/save@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_sles - - name: Testing V1 run: | cd ${{github.workspace}}/build @@ -212,16 +169,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Restore cached Build - id: cache-build-restore - uses: actions/cache/restore@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_rhel_8 - - name: Configure CMake - if: steps.cache-build-restore.outputs.cache-hit != 'false' # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -234,14 +182,6 @@ jobs: - name: Build Tests run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 16 tests - - name: Save Build - id: cache-build-save - uses: actions/cache/save@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_rhel_8 - - name: Testing V1 run: | cd ${{github.workspace}}/build @@ -271,16 +211,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Restore cached Build - id: cache-build-restore - uses: actions/cache/restore@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_rhel_9 - - name: Configure CMake - if: steps.cache-build-restore.outputs.cache-hit != 'false' # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -293,14 +224,6 @@ jobs: - name: Build Tests run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 16 tests - - name: Save Build - id: cache-build-save - uses: actions/cache/save@v3 - with: - path: | - ${{github.workspace}}/build - key: mi200_rhel_9 - - name: Testing V1 run: | cd ${{github.workspace}}/build @@ -326,16 +249,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Restore cached Build - id: cache-build-restore - uses: actions/cache/restore@v3 - with: - path: | - ${{github.workspace}}/build - key: vega20 - - name: Configure CMake - if: steps.cache-build-restore.outputs.cache-hit != 'false' # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -348,14 +262,6 @@ jobs: - name: Build Tests run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 16 tests - - name: Save Build - id: cache-build-save - uses: actions/cache/save@v3 - with: - path: | - ${{github.workspace}}/build - key: vega20 - - name: Testing V1 run: | cd ${{github.workspace}}/build @@ -381,16 +287,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Restore cached Build - id: cache-build-restore - uses: actions/cache/restore@v3 - with: - path: | - ${{github.workspace}}/build - key: navi32 - - name: Configure CMake - if: steps.cache-build-restore.outputs.cache-hit != 'false' # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -403,14 +300,6 @@ jobs: - name: Build Tests run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 16 tests - - name: Save Build - id: cache-build-save - uses: actions/cache/save@v3 - with: - path: | - ${{github.workspace}}/build - key: navi32 - - name: Testing V1 run: | cd ${{github.workspace}}/build @@ -436,16 +325,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Restore cached Build - id: cache-build-restore - uses: actions/cache/restore@v3 - with: - path: | - ${{github.workspace}}/build - key: mi100 - - name: Configure CMake - if: steps.cache-build-restore.outputs.cache-hit != 'false' # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -458,14 +338,6 @@ jobs: - name: Build Tests run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 16 tests - - name: Save Build - id: cache-build-save - uses: actions/cache/save@v3 - with: - path: | - ${{github.workspace}}/build - key: mi100 - - name: Testing V1 run: | cd ${{github.workspace}}/build @@ -492,16 +364,7 @@ jobs: # steps: # - uses: actions/checkout@v3 - # - name: Restore cached Build - # id: cache-build-restore - # uses: actions/cache/restore@v3 - # with: - # path: | - # ${{github.workspace}}/build - # key: navi21 - # - name: Configure CMake - # if: steps.cache-build-restore.outputs.cache-hit != 'false' # # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type # run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE -DCMAKE_MODULE_PATH="${{env.ROCM_PATH}}/hip/cmake;${{env.ROCM_PATH}}/lib/cmake" -DCMAKE_PREFIX_PATH="${{env.PREFIX_PATH}}" -DCMAKE_INSTALL_PREFIX="${{env.ROCM_PATH}}" -DCMAKE_SHARED_LINKER_FLAGS="${{env.LD_RUNPATH_FLAG}}" -DCMAKE_INSTALL_RPATH=${{env.ROCM_RPATH}} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DGPU_TARGETS="${{env.GPU_LIST}}" -DCPACK_PACKAGING_INSTALL_PREFIX=${{env.ROCM_PATH}} -DCPACK_GENERATOR='DEB;RPM;TGZ' -DCPACK_OBJCOPY_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objcopy" -DCPACK_READELF_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-readelf" -DCPACK_STRIP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-strip" -DCPACK_OBJDUMP_EXECUTABLE="${{env.ROCM_PATH}}/llvm/bin/llvm-objdump" @@ -514,26 +377,18 @@ jobs: # - name: Build Tests # run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 16 tests - # - name: Save Build - # id: cache-build-save - # uses: actions/cache/save@v3 - # with: - # path: | - # ${{github.workspace}}/build - # key: navi21 + # - name: Testing V1 + # run: | + # cd ${{github.workspace}}/build + # ./run.sh + # # TODO(aelwazir): Enable this once ctest is fixed + # # working-directory: ${{github.workspace}}/build/tests-v2 + # # Execute tests defined by the CMake configuration. + # # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + # # TODO(aelwazir): Enable this once ctest is fixed + # # run: ctest --parallel 16 -C ${{env.BUILD_TYPE}} - # - name: Testing V1 - # run: | - # cd ${{github.workspace}}/build - # ./run.sh - # # TODO(aelwazir): Enable this once ctest is fixed - # # working-directory: ${{github.workspace}}/build/tests-v2 - # # Execute tests defined by the CMake configuration. - # # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - # # TODO(aelwazir): Enable this once ctest is fixed - # # run: ctest --parallel 16 -C ${{env.BUILD_TYPE}} - - # - name: Testing V2 - # run: | - # cd ${{github.workspace}}/build - # make -j check + # - name: Testing V2 + # run: | + # cd ${{github.workspace}}/build + # make -j check diff --git a/projects/rocprofiler/.github/workflows/formatting.yml b/projects/rocprofiler/.github/workflows/formatting.yml new file mode 100644 index 0000000000..73d6b3c5f3 --- /dev/null +++ b/projects/rocprofiler/.github/workflows/formatting.yml @@ -0,0 +1,95 @@ + +name: Formatting +run-name: formatting + +on: + pull_request: + branches: [ amd-staging ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + cmake: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + + - name: Extract branch name + shell: bash + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_HEAD_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y python3-pip + python3 -m pip install -U cmake-format + + - name: Run cmake-format + run: | + set +e + cmake-format -i $(find . -type f | egrep 'CMakeLists.txt|\.cmake$') + if [ $(git diff | wc -l) -ne 0 ]; then + echo -e "\nError! CMake code not formatted. Run cmake-format...\n" + echo -e "\nFiles:\n" + git diff --name-only + echo -e "\nFull diff:\n" + git diff + exit 1 + fi + + - name: Create pull request + if: failure() + uses: peter-evans/create-pull-request@v5 + with: + commit-message: "run cmake formatting (cmake-format)" + branch: ${{ steps.extract_branch.outputs.branch }}-cmake-format + delete-branch: true + title: "Apply cmake-format to ${{ steps.extract_branch.outputs.branch }}" + base: ${{ steps.extract_branch.outputs.branch }} + + source: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + + - name: Install dependencies + run: | + DISTRIB_CODENAME=$(cat /etc/lsb-release | grep DISTRIB_CODENAME | awk -F '=' '{print $NF}') + sudo apt-get update + sudo apt-get install -y software-properties-common wget curl clang-format-11 + + - name: Extract branch name + shell: bash + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_HEAD_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Run clang-format + run: | + set +e + FILES=$(find include plugin samples src test tests-v2 -type f | egrep '\.(h|hpp|hh|c|cc|cpp)(|\.in)$') + FORMAT_OUT=$(clang-format-11 -i ${FILES}) + if [ $(git diff | wc -l) -ne 0 ]; then + echo -e "\nError! Code not formatted. Run clang-format (version 11)...\n" + echo -e "\nFiles:\n" + git diff --name-only + echo -e "\nFull diff:\n" + git diff + exit 1 + fi + + - name: Create pull request + if: failure() + uses: peter-evans/create-pull-request@v5 + with: + commit-message: "run formatting (clang-format v11)" + branch: ${{ steps.extract_branch.outputs.branch }}-clang-format + delete-branch: true + title: "Apply clang-format (v11) to ${{ steps.extract_branch.outputs.branch }}" + base: ${{ steps.extract_branch.outputs.branch }} diff --git a/projects/rocprofiler/CMakeLists.txt b/projects/rocprofiler/CMakeLists.txt index 9fcdeb1316..1f1ac60ccb 100644 --- a/projects/rocprofiler/CMakeLists.txt +++ b/projects/rocprofiler/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 3.18.0) # Build is not supported on Windows plaform if(WIN32) - message(FATAL_ERROR "Windows build is not supported.") + message(FATAL_ERROR "Windows build is not supported.") endif() # Set module name and project name. @@ -37,9 +37,9 @@ include(GNUInstallDirs) # set default ROCM_PATH if(NOT DEFINED ROCM_PATH) - set(ROCM_PATH - "/opt/rocm" - CACHE STRING "Default ROCM installation directory") + set(ROCM_PATH + "/opt/rocm" + CACHE STRING "Default ROCM installation directory") endif() set(CMAKE_CXX_STANDARD 17) @@ -62,8 +62,8 @@ set(BUILD_VERSION_MAJOR ${VERSION_MAJOR}) set(BUILD_VERSION_MINOR ${VERSION_MINOR}) set(BUILD_VERSION_PATCH ${VERSION_PATCH}) if(DEFINED VERSION_BUILD AND NOT ${VERSION_BUILD} STREQUAL "") - message("VERSION BUILD DEFINED ${VERSION_BUILD}") - set(BUILD_VERSION_PATCH "${BUILD_VERSION_PATCH}-${VERSION_BUILD}") + message("VERSION BUILD DEFINED ${VERSION_BUILD}") + set(BUILD_VERSION_PATCH "${BUILD_VERSION_PATCH}-${VERSION_BUILD}") endif() set(BUILD_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}") @@ -71,12 +71,11 @@ set(BUILD_VERSION_STRING set(LIB_VERSION_MAJOR ${VERSION_MAJOR}) set(LIB_VERSION_MINOR ${VERSION_MINOR}) if(${ROCM_PATCH_VERSION}) - set(LIB_VERSION_PATCH ${ROCM_PATCH_VERSION}) + set(LIB_VERSION_PATCH ${ROCM_PATCH_VERSION}) else() - set(LIB_VERSION_PATCH ${VERSION_PATCH}) + set(LIB_VERSION_PATCH ${VERSION_PATCH}) endif() -set(LIB_VERSION_STRING - "${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH}") +set(LIB_VERSION_STRING "${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH}") message("-- LIB-VERSION STRING: ${LIB_VERSION_STRING}") # Set target and root/lib/test directory @@ -86,97 +85,84 @@ set(LIB_DIR "${ROOT_DIR}/src") set(TEST_DIR "${ROOT_DIR}/test") find_package( - amd_comgr - REQUIRED - CONFIG - HINTS - ${CMAKE_INSTALL_PREFIX} - PATHS - ${ROCM_PATH} - PATH_SUFFIXES - lib/cmake/amd_comgr) + amd_comgr REQUIRED CONFIG + HINTS ${CMAKE_INSTALL_PREFIX} + PATHS ${ROCM_PATH} + PATH_SUFFIXES lib/cmake/amd_comgr) message(STATUS "Code Object Manager found at ${amd_comgr_DIR}.") link_libraries(amd_comgr) find_package(Threads REQUIRED) find_package( - hsa-runtime64 - REQUIRED - CONFIG - HINTS - ${CMAKE_INSTALL_PREFIX} - PATHS - ${ROCM_PATH}) + hsa-runtime64 REQUIRED CONFIG + HINTS ${CMAKE_INSTALL_PREFIX} + PATHS ${ROCM_PATH}) find_package( - HIP - REQUIRED - CONFIG - HINTS - ${CMAKE_INSTALL_PREFIX} - PATHS - ${ROCM_PATH}) + HIP REQUIRED CONFIG + HINTS ${CMAKE_INSTALL_PREFIX} + PATHS ${ROCM_PATH}) find_library(NUMA NAME numa REQUIRED) link_libraries(${NUMA}) -find_program(ROCMINFO_EXEC NAMES "rocminfo" -PATHS ${ROCM_PATH} -${CMAKE_INSTALL_PREFIX} "/usr/local" "/usr" -PATH_SUFFIXES bin) +find_program( + ROCMINFO_EXEC + NAMES "rocminfo" + PATHS ${ROCM_PATH} ${CMAKE_INSTALL_PREFIX} "/usr/local" "/usr" + PATH_SUFFIXES bin) set(ORIGINAL_SCRIPT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin/tblextr.py) set(OUTPUT_SCRIPT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin/tblextr.py) configure_file(${ORIGINAL_SCRIPT_PATH} ${OUTPUT_SCRIPT_PATH} @ONLY) get_property( - HSA_RUNTIME_INCLUDE_DIRECTORIES - TARGET hsa-runtime64::hsa-runtime64 - PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + HSA_RUNTIME_INCLUDE_DIRECTORIES + TARGET hsa-runtime64::hsa-runtime64 + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) find_file( - HSA_H hsa.h - PATHS ${HSA_RUNTIME_INCLUDE_DIRECTORIES} - PATH_SUFFIXES hsa - NO_DEFAULT_PATH REQUIRED) + HSA_H hsa.h + PATHS ${HSA_RUNTIME_INCLUDE_DIRECTORIES} + PATH_SUFFIXES hsa + NO_DEFAULT_PATH REQUIRED) get_filename_component(HSA_RUNTIME_INC_PATH ${HSA_H} DIRECTORY) include_directories(${HSA_RUNTIME_INC_PATH}) if(NOT DEFINED LIBRARY_TYPE) - set(LIBRARY_TYPE SHARED) + set(LIBRARY_TYPE SHARED) endif() # Enable tracing API if(NOT USE_PROF_API) - set(USE_PROF_API 1) + set(USE_PROF_API 1) endif() # Protocol header lookup set(PROF_API_HEADER_NAME prof_protocol.h) if(USE_PROF_API EQUAL 1) - find_path( - PROF_API_HEADER_DIR ${PROF_API_HEADER_NAME} - HINTS ${PROF_API_HEADER_PATH} - PATHS /opt/rocm/include - PATH_SUFFIXES roctracer/ext) - if(NOT PROF_API_HEADER_DIR) - message( - FATAL_ERROR - "Profiling API header not found. Tracer integration disabled. Use -DPROF_API_HEADER_PATH=" - ) - else() - include_directories(${PROF_API_HEADER_DIR}) - message( - STATUS "Profiling API: ${PROF_API_HEADER_DIR}/${PROF_API_HEADER_NAME}") - endif() + find_path( + PROF_API_HEADER_DIR ${PROF_API_HEADER_NAME} + HINTS ${PROF_API_HEADER_PATH} + PATHS /opt/rocm/include + PATH_SUFFIXES roctracer/ext) + if(NOT PROF_API_HEADER_DIR) + message( + FATAL_ERROR + "Profiling API header not found. Tracer integration disabled. Use -DPROF_API_HEADER_PATH=" + ) + else() + include_directories(${PROF_API_HEADER_DIR}) + message(STATUS "Profiling API: ${PROF_API_HEADER_DIR}/${PROF_API_HEADER_NAME}") + endif() endif() # Build libraries add_subdirectory(src) if(${LIBRARY_TYPE} STREQUAL SHARED) - # Build samples - add_subdirectory(samples) + # Build samples + add_subdirectory(samples) - # Build tests - add_subdirectory(tests-v2) + # Build tests + add_subdirectory(tests-v2) endif() # Build Plugins @@ -188,20 +174,20 @@ add_subdirectory(${TEST_DIR} ${PROJECT_BINARY_DIR}/test) # Installation and packaging set(DEST_NAME ${ROCPROFILER_NAME}) if(DEFINED CMAKE_INSTALL_PREFIX) - get_filename_component(prefix_name ${CMAKE_INSTALL_PREFIX} NAME) - get_filename_component(prefix_dir ${CMAKE_INSTALL_PREFIX} DIRECTORY) - if(prefix_name STREQUAL ${DEST_NAME}) - set(CMAKE_INSTALL_PREFIX ${prefix_dir}) - endif() + get_filename_component(prefix_name ${CMAKE_INSTALL_PREFIX} NAME) + get_filename_component(prefix_dir ${CMAKE_INSTALL_PREFIX} DIRECTORY) + if(prefix_name STREQUAL ${DEST_NAME}) + set(CMAKE_INSTALL_PREFIX ${prefix_dir}) + endif() endif() if(DEFINED CPACK_PACKAGING_INSTALL_PREFIX) - get_filename_component(prefix_name ${CPACK_PACKAGING_INSTALL_PREFIX} NAME) - get_filename_component(prefix_dir ${CPACK_PACKAGING_INSTALL_PREFIX} DIRECTORY) - if(prefix_name STREQUAL ${DEST_NAME}) - set(CPACK_PACKAGING_INSTALL_PREFIX ${prefix_dir}) - endif() + get_filename_component(prefix_name ${CPACK_PACKAGING_INSTALL_PREFIX} NAME) + get_filename_component(prefix_dir ${CPACK_PACKAGING_INSTALL_PREFIX} DIRECTORY) + if(prefix_name STREQUAL ${DEST_NAME}) + set(CPACK_PACKAGING_INSTALL_PREFIX ${prefix_dir}) + endif() else() - set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) + set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) endif() message("CMake-install-prefix: ${CMAKE_INSTALL_PREFIX}") message("CPack-install-prefix: ${CPACK_PACKAGING_INSTALL_PREFIX}") @@ -209,413 +195,395 @@ message("-----------Dest-name: ${DEST_NAME}") # Install headers install( - FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/core/activity.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ROCPROFILER_NAME} - COMPONENT dev) + FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/core/activity.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ROCPROFILER_NAME} + COMPONENT dev) # rpl_run.sh install( - FILES ${CMAKE_CURRENT_SOURCE_DIR}/bin/rpl_run.sh - DESTINATION ${CMAKE_INSTALL_BINDIR} - PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ - WORLD_EXECUTE - RENAME rocprof - COMPONENT runtime) + FILES ${CMAKE_CURRENT_SOURCE_DIR}/bin/rpl_run.sh + DESTINATION ${CMAKE_INSTALL_BINDIR} + PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + RENAME rocprof + COMPONENT runtime) configure_file(bin/rocprofv2 ${PROJECT_BINARY_DIR} COPYONLY) install( - FILES ${PROJECT_SOURCE_DIR}/bin/rocprofv2 - DESTINATION ${CMAKE_INSTALL_BINDIR} - PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ - WORLD_EXECUTE - COMPONENT runtime) + FILES ${PROJECT_SOURCE_DIR}/bin/rocprofv2 + DESTINATION ${CMAKE_INSTALL_BINDIR} + PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + COMPONENT runtime) install( - FILES ${CMAKE_CURRENT_SOURCE_DIR}/bin/txt2xml.sh - ${CMAKE_CURRENT_SOURCE_DIR}/bin/merge_traces.sh - ${CMAKE_CURRENT_SOURCE_DIR}/bin/txt2params.py - ${CMAKE_CURRENT_BINARY_DIR}/bin/tblextr.py - ${CMAKE_CURRENT_SOURCE_DIR}/bin/dform.py - ${CMAKE_CURRENT_SOURCE_DIR}/bin/mem_manager.py - ${CMAKE_CURRENT_SOURCE_DIR}/bin/sqlitedb.py - DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${ROCPROFILER_NAME} - PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ - WORLD_EXECUTE - COMPONENT runtime) + FILES ${CMAKE_CURRENT_SOURCE_DIR}/bin/txt2xml.sh + ${CMAKE_CURRENT_SOURCE_DIR}/bin/merge_traces.sh + ${CMAKE_CURRENT_SOURCE_DIR}/bin/txt2params.py + ${CMAKE_CURRENT_BINARY_DIR}/bin/tblextr.py + ${CMAKE_CURRENT_SOURCE_DIR}/bin/dform.py + ${CMAKE_CURRENT_SOURCE_DIR}/bin/mem_manager.py + ${CMAKE_CURRENT_SOURCE_DIR}/bin/sqlitedb.py + DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${ROCPROFILER_NAME} + PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + COMPONENT runtime) # gfx_metrics.xml metrics.xml install( - FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/tool/metrics.xml - ${CMAKE_CURRENT_SOURCE_DIR}/test/tool/gfx_metrics.xml - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME} - COMPONENT runtime) + FILES ${CMAKE_CURRENT_SOURCE_DIR}/test/tool/metrics.xml + ${CMAKE_CURRENT_SOURCE_DIR}/test/tool/gfx_metrics.xml + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME} + COMPONENT runtime) # librocprof-tool.so install( - FILES ${PROJECT_BINARY_DIR}/test/librocprof-tool.so - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME} - COMPONENT runtime) + FILES ${PROJECT_BINARY_DIR}/test/librocprof-tool.so + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME} + COMPONENT runtime) install( - FILES ${PROJECT_BINARY_DIR}/test/librocprof-tool.so - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME} - COMPONENT asan) + FILES ${PROJECT_BINARY_DIR}/test/librocprof-tool.so + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME} + COMPONENT asan) install( - FILES ${PROJECT_BINARY_DIR}/test/rocprof-ctrl - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME} - PERMISSIONS - OWNER_READ - OWNER_WRITE - OWNER_EXECUTE - GROUP_READ - GROUP_EXECUTE - WORLD_READ - WORLD_EXECUTE - COMPONENT runtime) + FILES ${PROJECT_BINARY_DIR}/test/rocprof-ctrl + DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ + WORLD_EXECUTE + COMPONENT runtime) # File reorg backward compatibility for non ASAN packaging -if ( NOT ENABLE_ASAN_PACKAGING ) - # File reorg Backward compatibility - option(FILE_REORG_BACKWARD_COMPATIBILITY - "Enable File Reorg with backward compatibility" ON) +if(NOT ENABLE_ASAN_PACKAGING) + # File reorg Backward compatibility + option(FILE_REORG_BACKWARD_COMPATIBILITY + "Enable File Reorg with backward compatibility" ON) endif() if(FILE_REORG_BACKWARD_COMPATIBILITY) - # To enabe/disable #error in wrapper header files - if(NOT DEFINED ROCM_HEADER_WRAPPER_WERROR) - if(DEFINED ENV{ROCM_HEADER_WRAPPER_WERROR}) - set(ROCM_HEADER_WRAPPER_WERROR "$ENV{ROCM_HEADER_WRAPPER_WERROR}" - CACHE STRING "Header wrapper warnings as errors.") - else() - set(ROCM_HEADER_WRAPPER_WERROR "OFF" CACHE STRING "Header wrapper warnings as errors.") + # To enabe/disable #error in wrapper header files + if(NOT DEFINED ROCM_HEADER_WRAPPER_WERROR) + if(DEFINED ENV{ROCM_HEADER_WRAPPER_WERROR}) + set(ROCM_HEADER_WRAPPER_WERROR + "$ENV{ROCM_HEADER_WRAPPER_WERROR}" + CACHE STRING "Header wrapper warnings as errors.") + else() + set(ROCM_HEADER_WRAPPER_WERROR + "OFF" + CACHE STRING "Header wrapper warnings as errors.") + endif() endif() - endif() - if(ROCM_HEADER_WRAPPER_WERROR) - set(deprecated_error 1) - else() - set(deprecated_error 0) - endif() - include(rocprofiler-backward-compat.cmake) -endif() #FILE_REORG_BACKWARD_COMPATIBILITY + if(ROCM_HEADER_WRAPPER_WERROR) + set(deprecated_error 1) + else() + set(deprecated_error 0) + endif() + include(rocprofiler-backward-compat.cmake) +endif() # FILE_REORG_BACKWARD_COMPATIBILITY if(${LIBRARY_TYPE} STREQUAL SHARED) - # Packaging directives - set(CPACK_GENERATOR "DEB" "RPM" "TGZ") - set(ENABLE_LDCONFIG - ON - CACHE BOOL "Set library links and caches using ldconfig.") - set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") - set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.") - set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) - set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) - set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) - set(CPACK_PACKAGE_VERSION - "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" - ) - set(CPACK_PACKAGE_CONTACT - "ROCm Profiler Support ") - set(CPACK_PACKAGE_DESCRIPTION_SUMMARY - "ROCPROFILER library for AMD HSA runtime API extension support") - set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") - - if(DEFINED ENV{ROCM_LIBPATCH_VERSION}) + # Packaging directives + set(CPACK_GENERATOR "DEB" "RPM" "TGZ") + set(ENABLE_LDCONFIG + ON + CACHE BOOL "Set library links and caches using ldconfig.") + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") + set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.") + set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) + set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) + set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) set(CPACK_PACKAGE_VERSION - "${CPACK_PACKAGE_VERSION}.$ENV{ROCM_LIBPATCH_VERSION}") - message("Using CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}") - endif() + "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" + ) + set(CPACK_PACKAGE_CONTACT "ROCm Profiler Support ") + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY + "ROCPROFILER library for AMD HSA runtime API extension support") + set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") + if(DEFINED ENV{ROCM_LIBPATCH_VERSION}) + set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}.$ENV{ROCM_LIBPATCH_VERSION}") + message("Using CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}") + endif() + # Debian package specific variable for ASAN + set(CPACK_DEBIAN_ASAN_PACKAGE_NAME "${ROCPROFILER_NAME}-asan") + set(CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS "hsa-rocr-asan, rocm-core-asan") - # Debian package specific variable for ASAN - set ( CPACK_DEBIAN_ASAN_PACKAGE_NAME "${ROCPROFILER_NAME}-asan" ) - set ( CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS "hsa-rocr-asan, rocm-core-asan" ) + # Install license file + install( + FILES ${CPACK_RESOURCE_FILE_LICENSE} + DESTINATION ${CMAKE_INSTALL_DOCDIR} + COMPONENT runtime) + install( + FILES ${CPACK_RESOURCE_FILE_LICENSE} + DESTINATION ${CMAKE_INSTALL_DOCDIR}-asan + COMPONENT asan) - # Install license file - install( - FILES ${CPACK_RESOURCE_FILE_LICENSE} - DESTINATION ${CMAKE_INSTALL_DOCDIR} - COMPONENT runtime) - install( - FILES ${CPACK_RESOURCE_FILE_LICENSE} - DESTINATION ${CMAKE_INSTALL_DOCDIR}-asan - COMPONENT asan) + # Debian package specific variables + if(DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE}) + set(CPACK_DEBIAN_PACKAGE_RELEASE $ENV{CPACK_DEBIAN_PACKAGE_RELEASE}) + else() + set(CPACK_DEBIAN_PACKAGE_RELEASE "local") + endif() - # Debian package specific variables - if(DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE}) - set(CPACK_DEBIAN_PACKAGE_RELEASE $ENV{CPACK_DEBIAN_PACKAGE_RELEASE}) - else() - set(CPACK_DEBIAN_PACKAGE_RELEASE "local") - endif() + message("Using CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_DEBIAN_PACKAGE_RELEASE}") + set(CPACK_DEB_COMPONENT_INSTALL ON) + set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") + set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "${PROJECT_NAME}") + set(CPACK_DEBIAN_RUNTIME_PACKAGE_DEPENDS + "hsa-rocr-dev, rocm-core, libsystemd-dev, libelf-dev, libnuma-dev, libpciaccess-dev, libxml2-dev" + ) + set(CPACK_DEBIAN_DEV_PACKAGE_NAME "${PROJECT_NAME}-dev") + set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS "${PROJECT_NAME}, hsa-rocr-dev, rocm-core") + set(CPACK_DEBIAN_TESTS_PACKAGE_NAME "${PROJECT_NAME}-tests") + set(CPACK_DEBIAN_TESTS_PACKAGE_DEPENDS "${PROJECT_NAME}-dev, hsa-rocr-dev, rocm-core") + set(CPACK_DEBIAN_SAMPLES_PACKAGE_NAME "${PROJECT_NAME}-samples") + set(CPACK_DEBIAN_SAMPLES_PACKAGE_DEPENDS + "${PROJECT_NAME}-dev, hsa-rocr-dev, rocm-core") + set(CPACK_DEBIAN_DOCS_PACKAGE_NAME "${PROJECT_NAME}-docs") + set(CPACK_DEBIAN_DOCS_PACKAGE_DEPENDS "${PROJECT_NAME}-dev, hsa-rocr-dev, rocm-core") + set(CPACK_DEBIAN_PLUGINS_PACKAGE_NAME "${PROJECT_NAME}-plugins") + set(CPACK_DEBIAN_PLUGINS_PACKAGE_DEPENDS "${PROJECT_NAME}, hsa-rocr-dev, rocm-core") - message("Using CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_DEBIAN_PACKAGE_RELEASE}") - set(CPACK_DEB_COMPONENT_INSTALL ON) - set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") - set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "${PROJECT_NAME}") - set(CPACK_DEBIAN_RUNTIME_PACKAGE_DEPENDS "hsa-rocr-dev, rocm-core, libsystemd-dev, libelf-dev, libnuma-dev, libpciaccess-dev, libxml2-dev") - set(CPACK_DEBIAN_DEV_PACKAGE_NAME "${PROJECT_NAME}-dev") - set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS - "${PROJECT_NAME}, hsa-rocr-dev, rocm-core") - set(CPACK_DEBIAN_TESTS_PACKAGE_NAME "${PROJECT_NAME}-tests") - set(CPACK_DEBIAN_TESTS_PACKAGE_DEPENDS - "${PROJECT_NAME}-dev, hsa-rocr-dev, rocm-core") - set(CPACK_DEBIAN_SAMPLES_PACKAGE_NAME "${PROJECT_NAME}-samples") - set(CPACK_DEBIAN_SAMPLES_PACKAGE_DEPENDS - "${PROJECT_NAME}-dev, hsa-rocr-dev, rocm-core") - set(CPACK_DEBIAN_DOCS_PACKAGE_NAME "${PROJECT_NAME}-docs") - set(CPACK_DEBIAN_DOCS_PACKAGE_DEPENDS - "${PROJECT_NAME}-dev, hsa-rocr-dev, rocm-core") - set(CPACK_DEBIAN_PLUGINS_PACKAGE_NAME "${PROJECT_NAME}-plugins") - set(CPACK_DEBIAN_PLUGINS_PACKAGE_DEPENDS - "${PROJECT_NAME}, hsa-rocr-dev, rocm-core") + set(CPACK_DEBIAN_CHANGELOG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md") - set ( CPACK_DEBIAN_CHANGELOG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md" ) + # RPM package specific variables + if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE}) + set(CPACK_RPM_PACKAGE_RELEASE $ENV{CPACK_RPM_PACKAGE_RELEASE}) + else() + set(CPACK_RPM_PACKAGE_RELEASE "local") + endif() - # RPM package specific variables - if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE}) - set(CPACK_RPM_PACKAGE_RELEASE $ENV{CPACK_RPM_PACKAGE_RELEASE}) - else() - set(CPACK_RPM_PACKAGE_RELEASE "local") - endif() + message("Using CPACK_RPM_PACKAGE_RELEASE ${CPACK_RPM_PACKAGE_RELEASE}") - message("Using CPACK_RPM_PACKAGE_RELEASE ${CPACK_RPM_PACKAGE_RELEASE}") + set(CPACK_RPM_PACKAGE_LICENSE "MIT") - set(CPACK_RPM_PACKAGE_LICENSE "MIT") + # 'dist' breaks manual builds on debian systems due to empty Provides + execute_process( + COMMAND rpm --eval %{?dist} + RESULT_VARIABLE PROC_RESULT + OUTPUT_VARIABLE EVAL_RESULT + OUTPUT_STRIP_TRAILING_WHITESPACE) + message("RESULT_VARIABLE ${PROC_RESULT} OUTPUT_VARIABLE: ${EVAL_RESULT}") - # 'dist' breaks manual builds on debian systems due to empty Provides - execute_process( - COMMAND rpm --eval %{?dist} - RESULT_VARIABLE PROC_RESULT - OUTPUT_VARIABLE EVAL_RESULT - OUTPUT_STRIP_TRAILING_WHITESPACE) - message("RESULT_VARIABLE ${PROC_RESULT} OUTPUT_VARIABLE: ${EVAL_RESULT}") + if(PROC_RESULT EQUAL "0" AND NOT EVAL_RESULT STREQUAL "") + string(APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}") + endif() - if(PROC_RESULT EQUAL "0" AND NOT EVAL_RESULT STREQUAL "") - string(APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}") - endif() + set(CPACK_RPM_COMPONENT_INSTALL ON) + set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") + set(CPACK_RPM_RUNTIME_PACKAGE_NAME "${PROJECT_NAME}") + set(CPACK_RPM_RUNTIME_PACKAGE_REQUIRES + "hsa-rocr-dev, rocm-core, systemd-devel, libpciaccess-devel, libxml2-devel") + set(CPACK_RPM_DEV_PACKAGE_NAME "${PROJECT_NAME}-devel") + set(CPACK_RPM_DEV_PACKAGE_REQUIRES "${PROJECT_NAME}, hsa-rocr-dev, rocm-core") + set(CPACK_RPM_DEV_PACKAGE_PROVIDES "${PROJECT_NAME}-dev") + set(CPACK_RPM_DEV_PACKAGE_OBSOLETES "${PROJECT_NAME}-dev") + set(CPACK_RPM_TESTS_PACKAGE_NAME "${PROJECT_NAME}-tests") + set(CPACK_RPM_TESTS_PACKAGE_REQUIRES "${PROJECT_NAME}-devel, hsa-rocr-dev, rocm-core") + set(CPACK_RPM_DOCS_PACKAGE_NAME "${PROJECT_NAME}-docs") + set(CPACK_RPM_DOCS_PACKAGE_REQUIRES "${PROJECT_NAME}-devel, hsa-rocr-dev, rocm-core") + set(CPACK_RPM_PLUGINS_PACKAGE_NAME "${PROJECT_NAME}-plugins") + set(CPACK_RPM_PLUGINS_PACKAGE_REQUIRES "${PROJECT_NAME}, hsa-rocr-dev, rocm-core") + set(CPACK_RPM_PACKAGE_AUTOREQ 0) + set(CPACK_RPM_SAMPLES_PACKAGE_NAME "${PROJECT_NAME}-samples") + set(CPACK_RPM_SAMPLES_PACKAGE_REQUIRES + "${PROJECT_NAME}-devel, hsa-rocr-dev, rocm-core, hip-runtime-amd") + message("CPACK_RPM_PACKAGE_RELEASE: ${CPACK_RPM_PACKAGE_RELEASE}") - set(CPACK_RPM_COMPONENT_INSTALL ON) - set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") - set(CPACK_RPM_RUNTIME_PACKAGE_NAME "${PROJECT_NAME}") - set(CPACK_RPM_RUNTIME_PACKAGE_REQUIRES "hsa-rocr-dev, rocm-core, systemd-devel, libpciaccess-devel, libxml2-devel") - set(CPACK_RPM_DEV_PACKAGE_NAME "${PROJECT_NAME}-devel") - set(CPACK_RPM_DEV_PACKAGE_REQUIRES "${PROJECT_NAME}, hsa-rocr-dev, rocm-core") - set(CPACK_RPM_DEV_PACKAGE_PROVIDES "${PROJECT_NAME}-dev") - set(CPACK_RPM_DEV_PACKAGE_OBSOLETES "${PROJECT_NAME}-dev") - set(CPACK_RPM_TESTS_PACKAGE_NAME "${PROJECT_NAME}-tests") - set(CPACK_RPM_TESTS_PACKAGE_REQUIRES - "${PROJECT_NAME}-devel, hsa-rocr-dev, rocm-core") - set(CPACK_RPM_DOCS_PACKAGE_NAME "${PROJECT_NAME}-docs") - set(CPACK_RPM_DOCS_PACKAGE_REQUIRES - "${PROJECT_NAME}-devel, hsa-rocr-dev, rocm-core") - set(CPACK_RPM_PLUGINS_PACKAGE_NAME "${PROJECT_NAME}-plugins") - set(CPACK_RPM_PLUGINS_PACKAGE_REQUIRES - "${PROJECT_NAME}, hsa-rocr-dev, rocm-core") - set(CPACK_RPM_PACKAGE_AUTOREQ 0) - set(CPACK_RPM_SAMPLES_PACKAGE_NAME "${PROJECT_NAME}-samples") - set(CPACK_RPM_SAMPLES_PACKAGE_REQUIRES - "${PROJECT_NAME}-devel, hsa-rocr-dev, rocm-core, hip-runtime-amd") - message("CPACK_RPM_PACKAGE_RELEASE: ${CPACK_RPM_PACKAGE_RELEASE}") - - #Disable build id for rocprofiler as its creating transaction error - set ( CPACK_RPM_SPEC_MORE_DEFINE "%define _build_id_links none + # Disable build id for rocprofiler as its creating transaction error + set(CPACK_RPM_SPEC_MORE_DEFINE + "%define _build_id_links none %global __strip ${CPACK_STRIP_EXECUTABLE} %global __objdump ${CPACK_OBJDUMP_EXECUTABLE} %global __objcopy ${CPACK_OBJCOPY_EXECUTABLE} %global __readelf ${CPACK_READELF_EXECUTABLE}") - - # RPM package specific variable for ASAN - set ( CPACK_RPM_ASAN_PACKAGE_NAME "${ROCPROFILER_NAME}-asan" ) - set ( CPACK_RPM_ASAN_PACKAGE_REQUIRES "hsa-rocr-asan, rocm-core-asan" ) - #set ( CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md" ) + # RPM package specific variable for ASAN + set(CPACK_RPM_ASAN_PACKAGE_NAME "${ROCPROFILER_NAME}-asan") + set(CPACK_RPM_ASAN_PACKAGE_REQUIRES "hsa-rocr-asan, rocm-core-asan") - # Remove dependency on rocm-core if -DROCM_DEP_ROCMCORE=ON not given to cmake - if(NOT ROCM_DEP_ROCMCORE) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_RUNTIME_PACKAGE_REQUIRES - ${CPACK_RPM_RUNTIME_PACKAGE_REQUIRES}) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_DEV_PACKAGE_REQUIRES - ${CPACK_RPM_DEV_PACKAGE_REQUIRES}) - string(REGEX REPLACE ",? ?rocm-core-asan" "" CPACK_RPM_ASAN_PACKAGE_REQUIRES - ${CPACK_RPM_ASAN_PACKAGE_REQUIRES}) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_TESTS_PACKAGE_REQUIRES - ${CPACK_RPM_TESTS_PACKAGE_REQUIRES}) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_SAMPLES_PACKAGE_REQUIRES - ${CPACK_RPM_SAMPLES_PACKAGE_REQUIRES}) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_DOCS_PACKAGE_REQUIRES - ${CPACK_RPM_DOCS_PACKAGE_REQUIRES}) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_PLUGINS_PACKAGE_REQUIRES - ${CPACK_RPM_PLUGINS_PACKAGE_REQUIRES}) - string(REGEX - REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_RUNTIME_PACKAGE_DEPENDS - ${CPACK_DEBIAN_RUNTIME_PACKAGE_DEPENDS}) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_DEV_PACKAGE_DEPENDS - ${CPACK_DEBIAN_DEV_PACKAGE_DEPENDS}) - string(REGEX REPLACE ",? ?rocm-core-asan" "" CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS - ${CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS}) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_TESTS_PACKAGE_DEPENDS - ${CPACK_DEBIAN_TESTS_PACKAGE_DEPENDS}) - string(REGEX - REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_SAMPLES_PACKAGE_DEPENDS - ${CPACK_DEBIAN_SAMPLES_PACKAGE_DEPENDS}) - string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_DOCS_PACKAGE_DEPENDS - ${CPACK_DEBIAN_DOCS_PACKAGE_DEPENDS}) - string(REGEX - REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_PLUGINS_PACKAGE_DEPENDS - ${CPACK_DEBIAN_PLUGINS_PACKAGE_DEPENDS}) - endif() + # set ( CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md" ) - ## set components - if(ENABLE_ASAN_PACKAGING) - # ASAN Package requires only asan component with libraries and license file - set(CPACK_COMPONENTS_ALL asan) - else() - set(CPACK_COMPONENTS_ALL runtime dev tests docs plugins samples) - endif() + # Remove dependency on rocm-core if -DROCM_DEP_ROCMCORE=ON not given to cmake + if(NOT ROCM_DEP_ROCMCORE) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_RUNTIME_PACKAGE_REQUIRES + ${CPACK_RPM_RUNTIME_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_DEV_PACKAGE_REQUIRES + ${CPACK_RPM_DEV_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core-asan" "" CPACK_RPM_ASAN_PACKAGE_REQUIRES + ${CPACK_RPM_ASAN_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_TESTS_PACKAGE_REQUIRES + ${CPACK_RPM_TESTS_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_SAMPLES_PACKAGE_REQUIRES + ${CPACK_RPM_SAMPLES_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_DOCS_PACKAGE_REQUIRES + ${CPACK_RPM_DOCS_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_RPM_PLUGINS_PACKAGE_REQUIRES + ${CPACK_RPM_PLUGINS_PACKAGE_REQUIRES}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_RUNTIME_PACKAGE_DEPENDS + ${CPACK_DEBIAN_RUNTIME_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_DEV_PACKAGE_DEPENDS + ${CPACK_DEBIAN_DEV_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core-asan" "" CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS + ${CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_TESTS_PACKAGE_DEPENDS + ${CPACK_DEBIAN_TESTS_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_SAMPLES_PACKAGE_DEPENDS + ${CPACK_DEBIAN_SAMPLES_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_DOCS_PACKAGE_DEPENDS + ${CPACK_DEBIAN_DOCS_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_PLUGINS_PACKAGE_DEPENDS + ${CPACK_DEBIAN_PLUGINS_PACKAGE_DEPENDS}) + endif() - include(CPack) + # set components + if(ENABLE_ASAN_PACKAGING) + # ASAN Package requires only asan component with libraries and license file + set(CPACK_COMPONENTS_ALL asan) + else() + set(CPACK_COMPONENTS_ALL runtime dev tests docs plugins samples) + endif() - cpack_add_component( - runtime - DISPLAY_NAME "Runtime" - DESCRIPTION "Dynamic libraries for the ROCProfiler") + include(CPack) - cpack_add_component( - dev - DISPLAY_NAME "Development" - DESCRIPTION "Development needed header files for ROCProfiler" - DEPENDS runtime) + cpack_add_component( + runtime + DISPLAY_NAME "Runtime" + DESCRIPTION "Dynamic libraries for the ROCProfiler") - cpack_add_component( - plugins - DISPLAY_NAME "ROCProfile Plugins" - DESCRIPTION "Plugins for handling ROCProfiler data output" - DEPENDS runtime) + cpack_add_component( + dev + DISPLAY_NAME "Development" + DESCRIPTION "Development needed header files for ROCProfiler" + DEPENDS runtime) - cpack_add_component( - tests - DISPLAY_NAME "Tests" - DESCRIPTION "Tests for the ROCProfiler" - DEPENDS dev) + cpack_add_component( + plugins + DISPLAY_NAME "ROCProfile Plugins" + DESCRIPTION "Plugins for handling ROCProfiler data output" + DEPENDS runtime) - cpack_add_component( - samples - DISPLAY_NAME "Samples" - DESCRIPTION "Samples for the ROCProfiler" - DEPENDS dev) + cpack_add_component( + tests + DISPLAY_NAME "Tests" + DESCRIPTION "Tests for the ROCProfiler" + DEPENDS dev) - cpack_add_component( - docs - DISPLAY_NAME "Documentation" - DESCRIPTION "Documentation for the ROCProfiler API" - DEPENDS dev) + cpack_add_component( + samples + DISPLAY_NAME "Samples" + DESCRIPTION "Samples for the ROCProfiler" + DEPENDS dev) - cpack_add_component( - asan - DISPLAY_NAME "ASAN" - DESCRIPTION "ASAN libraries for the ROCPROFILER" - DEPENDS asan) + cpack_add_component( + docs + DISPLAY_NAME "Documentation" + DESCRIPTION "Documentation for the ROCProfiler API" + DEPENDS dev) + + cpack_add_component( + asan + DISPLAY_NAME "ASAN" + DESCRIPTION "ASAN libraries for the ROCPROFILER" + DEPENDS asan) endif() find_package(Doxygen) if(DOXYGEN_FOUND) - # # Set input and output files for API Document - set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile_API.in) - set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_API) + # # Set input and output files for API Document + set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile_API.in) + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_API) - # # Request to configure the file - configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) + # # Request to configure the file + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html - ${CMAKE_CURRENT_BINARY_DIR}/doc/latex/refman.pdf - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/doc/latex pdf - MAIN_DEPENDENCY ${DOXYGEN_OUT} - ${DOXYGEN_IN} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/rocprofiler/v2/rocprofiler_plugin.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/rocprofiler/v2/rocprofiler.h - COMMENT "Generating API documentation") + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html + ${CMAKE_CURRENT_BINARY_DIR}/doc/latex/refman.pdf + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/doc/latex pdf + MAIN_DEPENDENCY ${DOXYGEN_OUT} + ${DOXYGEN_IN} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/rocprofiler/v2/rocprofiler_plugin.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/rocprofiler/v2/rocprofiler.h + COMMENT "Generating API documentation") - add_custom_target( - doc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html - ${CMAKE_CURRENT_BINARY_DIR}/doc/latex/refman.pdf) + add_custom_target(doc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/html/index.html + ${CMAKE_CURRENT_BINARY_DIR}/doc/latex/refman.pdf) - install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/doc/latex/refman.pdf" - DESTINATION ${CMAKE_INSTALL_DOCDIR} - RENAME "${PROJECT_NAME}v2_api_spec.pdf" - OPTIONAL - COMPONENT docs) + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/doc/latex/refman.pdf" + DESTINATION ${CMAKE_INSTALL_DOCDIR} + RENAME "${PROJECT_NAME}v2_api_spec.pdf" + OPTIONAL + COMPONENT docs) - install( - DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc/html/" - DESTINATION ${CMAKE_INSTALL_DOCDIR}/html - OPTIONAL - COMPONENT docs) + install( + DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc/html/" + DESTINATION ${CMAKE_INSTALL_DOCDIR}/html + OPTIONAL + COMPONENT docs) - # # Set input and output files for Tools Document - set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile_Tool.in) - set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/Doxyfile_Tool) + # # Set input and output files for Tools Document + set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile_Tool.in) + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/Doxyfile_Tool) - # # Request to configure the file - configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) + # # Request to configure the file + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/html/index.html - ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/latex/refman.pdf - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/latex pdf - MAIN_DEPENDENCY ${DOXYGEN_OUT} - ${DOXYGEN_IN} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/doc/rocprofv2_tool.md - COMMENT "Generating Tools documentation") + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/html/index.html + ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/latex/refman.pdf + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/latex pdf + MAIN_DEPENDENCY ${DOXYGEN_OUT} + ${DOXYGEN_IN} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/doc/rocprofv2_tool.md + COMMENT "Generating Tools documentation") - add_custom_target( - doc_tool DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/html/index.html - ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/latex/refman.pdf) + add_custom_target( + doc_tool DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/html/index.html + ${CMAKE_CURRENT_BINARY_DIR}/tooldoc/latex/refman.pdf) - install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/tooldoc/latex/refman.pdf" - DESTINATION ${CMAKE_INSTALL_DOCDIR} - RENAME "${PROJECT_NAME}v2_tool.pdf" - OPTIONAL - COMPONENT docs) + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/tooldoc/latex/refman.pdf" + DESTINATION ${CMAKE_INSTALL_DOCDIR} + RENAME "${PROJECT_NAME}v2_tool.pdf" + OPTIONAL + COMPONENT docs) - install( - DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tooldoc/html/" - DESTINATION ${CMAKE_INSTALL_DOCDIR}/html - OPTIONAL - COMPONENT docs) + install( + DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tooldoc/html/" + DESTINATION ${CMAKE_INSTALL_DOCDIR}/html + OPTIONAL + COMPONENT docs) - # # Set input and output files for changelog document - set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile_ChangeLog.in) - set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/Doxyfile_ChangeLog) + # # Set input and output files for changelog document + set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile_ChangeLog.in) + set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/Doxyfile_ChangeLog) - # # Request to configure the file - configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) + # # Request to configure the file + configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/latex/refman.pdf - COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/latex pdf - MAIN_DEPENDENCY ${DOXYGEN_OUT} - ${DOXYGEN_IN} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md - COMMENT "Generating changelog documentation") + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/latex/refman.pdf + COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} + COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/latex pdf + MAIN_DEPENDENCY ${DOXYGEN_OUT} + ${DOXYGEN_IN} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md + COMMENT "Generating changelog documentation") - add_custom_target( - doc_changelog DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/latex/refman.pdf) + add_custom_target(doc_changelog + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/latex/refman.pdf) - install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/latex/refman.pdf" - DESTINATION ${CMAKE_INSTALL_DOCDIR} - RENAME "${PROJECT_NAME}_ChangeLog.pdf" - OPTIONAL - COMPONENT docs) + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/doc/changelog/latex/refman.pdf" + DESTINATION ${CMAKE_INSTALL_DOCDIR} + RENAME "${PROJECT_NAME}_ChangeLog.pdf" + OPTIONAL + COMPONENT docs) - add_dependencies(doc doc_changelog) + add_dependencies(doc doc_changelog) endif() - diff --git a/projects/rocprofiler/cmake_modules/FindLibDw.cmake b/projects/rocprofiler/cmake_modules/FindLibDw.cmake index 23eefe0936..8793fb8196 100644 --- a/projects/rocprofiler/cmake_modules/FindLibDw.cmake +++ b/projects/rocprofiler/cmake_modules/FindLibDw.cmake @@ -5,23 +5,16 @@ # - LIBDW_INCLUDE_DIRS - the libelf include directory # - LIBDW_LIBRARIES - Link these to use libelf # - LIBDW_DEFINITIONS - Compiler switches required for using libelf -find_path(FIND_LIBDW_INCLUDES - NAMES - elfutils/libdw.h - PATHS - /usr/include - /usr/local/include) +find_path( + FIND_LIBDW_INCLUDES + NAMES elfutils/libdw.h + PATHS /usr/include /usr/local/include) -find_library(FIND_LIBDW_LIBRARIES - NAMES - dw - PATH - /usr/lib - /usr/local/lib) +find_library(FIND_LIBDW_LIBRARIES NAMES dw PATH /usr/lib /usr/local/lib) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LibDw DEFAULT_MSG - FIND_LIBDW_INCLUDES FIND_LIBDW_LIBRARIES) +find_package_handle_standard_args(LibDw DEFAULT_MSG FIND_LIBDW_INCLUDES + FIND_LIBDW_LIBRARIES) mark_as_advanced(FIND_LIBDW_INCLUDES FIND_LIBDW_LIBRARIES) set(LIBDW_INCLUDES ${FIND_LIBDW_INCLUDES}) diff --git a/projects/rocprofiler/cmake_modules/FindLibElf.cmake b/projects/rocprofiler/cmake_modules/FindLibElf.cmake index 30081404dc..6355b09ba2 100644 --- a/projects/rocprofiler/cmake_modules/FindLibElf.cmake +++ b/projects/rocprofiler/cmake_modules/FindLibElf.cmake @@ -5,25 +5,16 @@ # - LIBELF_INCLUDE_DIRS - the libelf include directory # - LIBELF_LIBRARIES - Link these to use libelf # - LIBELF_DEFINITIONS - Compiler switches required for using libelf -find_path(FIND_LIBELF_INCLUDES - NAMES - libelf.h - PATHS - /usr/include - /usr/include/libelf - /usr/local/include - /usr/local/include/libelf) +find_path( + FIND_LIBELF_INCLUDES + NAMES libelf.h + PATHS /usr/include /usr/include/libelf /usr/local/include /usr/local/include/libelf) -find_library(FIND_LIBELF_LIBRARIES - NAMES - elf - PATH - /usr/lib - /usr/local/lib) +find_library(FIND_LIBELF_LIBRARIES NAMES elf PATH /usr/lib /usr/local/lib) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LibElf DEFAULT_MSG - FIND_LIBELF_INCLUDES FIND_LIBELF_LIBRARIES) +find_package_handle_standard_args(LibElf DEFAULT_MSG FIND_LIBELF_INCLUDES + FIND_LIBELF_LIBRARIES) mark_as_advanced(FIND_LIBELF_INCLUDES FIND_LIBELF_LIBRARIES) set(LIBELF_INCLUDES ${FIND_LIBELF_INCLUDES}) diff --git a/projects/rocprofiler/cmake_modules/env.cmake b/projects/rocprofiler/cmake_modules/env.cmake index 805e125ccb..58412775b6 100644 --- a/projects/rocprofiler/cmake_modules/env.cmake +++ b/projects/rocprofiler/cmake_modules/env.cmake @@ -20,60 +20,75 @@ # THE SOFTWARE. ################################################################################ -## Linux Compiler options +# Linux Compiler options set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fms-extensions") -add_definitions ( -DNEW_TRACE_API=1 ) +add_definitions(-DNEW_TRACE_API=1) -## CLANG options +# CLANG options if("$ENV{CXX}" STREQUAL "/usr/bin/clang++") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ferror-limit=1000000") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ferror-limit=1000000") endif() -## Enable debug trace -if ( DEFINED ENV{CMAKE_DEBUG_TRACE} ) - add_definitions ( -DDEBUG_TRACE=1 ) +# Enable debug trace +if(DEFINED ENV{CMAKE_DEBUG_TRACE}) + add_definitions(-DDEBUG_TRACE=1) endif() -## Enable AQL-profile new API -if ( NOT DEFINED ENV{CMAKE_CURR_API} ) - add_definitions ( -DAQLPROF_NEW_API=1 ) +# Enable AQL-profile new API +if(NOT DEFINED ENV{CMAKE_CURR_API}) + add_definitions(-DAQLPROF_NEW_API=1) endif() -## Enable direct loading of AQL-profile HSA extension -if ( DEFINED ENV{CMAKE_LD_AQLPROFILE} ) - add_definitions ( -DROCP_LD_AQLPROFILE=1 ) +# Enable direct loading of AQL-profile HSA extension +if(DEFINED ENV{CMAKE_LD_AQLPROFILE}) + add_definitions(-DROCP_LD_AQLPROFILE=1) endif() -## Find hsa-runtime -find_package(hsa-runtime64 CONFIG REQUIRED HINTS ${CMAKE_PREFIX_PATH} PATHS /opt/rocm PATH_SUFFIXES lib/cmake/hsa-runtime64 ) +# Find hsa-runtime +find_package( + hsa-runtime64 CONFIG REQUIRED + HINTS ${CMAKE_PREFIX_PATH} + PATHS /opt/rocm + PATH_SUFFIXES lib/cmake/hsa-runtime64) # find KFD thunk -find_package(hsakmt CONFIG REQUIRED HINTS ${CMAKE_PREFIX_PATH} PATHS /opt/rocm PATH_SUFFIXES lib/cmake/hsakmt ) +find_package( + hsakmt CONFIG REQUIRED + HINTS ${CMAKE_PREFIX_PATH} + PATHS /opt/rocm + PATH_SUFFIXES lib/cmake/hsakmt) -## Find ROCm -## TODO: Need a better method to find the ROCm path -find_path ( HSA_KMT_INC_PATH "hsakmt/hsakmt.h" HINTS ${CMAKE_PREFIX_PATH} PATHS /opt/rocm PATH_SUFFIXES include ) -if ( "${HSA_KMT_INC_PATH}" STREQUAL "" ) - get_target_property(HSA_KMT_INC_PATH hsakmt::hsakmt INTERFACE_INCLUDE_DIRECTORIES) +# Find ROCm TODO: Need a better method to find the ROCm path +find_path( + HSA_KMT_INC_PATH "hsakmt/hsakmt.h" + HINTS ${CMAKE_PREFIX_PATH} + PATHS /opt/rocm + PATH_SUFFIXES include) +if("${HSA_KMT_INC_PATH}" STREQUAL "") + get_target_property(HSA_KMT_INC_PATH hsakmt::hsakmt INTERFACE_INCLUDE_DIRECTORIES) endif() -## Include path: /opt/rocm-ver/include. Go up one level to get ROCm path -get_filename_component ( ROCM_ROOT_DIR "${HSA_KMT_INC_PATH}" DIRECTORY ) +# Include path: /opt/rocm-ver/include. Go up one level to get ROCm path +get_filename_component(ROCM_ROOT_DIR "${HSA_KMT_INC_PATH}" DIRECTORY) -## Basic Tool Chain Information -message ( "----------Build-Type: ${CMAKE_BUILD_TYPE}" ) -message ( "------------Compiler: ${CMAKE_CXX_COMPILER}" ) -message ( "----Compiler-Version: ${CMAKE_CXX_COMPILER_VERSION}" ) -message ( "-------ROCM_ROOT_DIR: ${ROCM_ROOT_DIR}" ) -message ( "-----CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}" ) -message ( "---CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}" ) -message ( "---------GPU_TARGETS: ${GPU_TARGETS}" ) +# Basic Tool Chain Information +message("----------Build-Type: ${CMAKE_BUILD_TYPE}") +message("------------Compiler: ${CMAKE_CXX_COMPILER}") +message("----Compiler-Version: ${CMAKE_CXX_COMPILER_VERSION}") +message("-------ROCM_ROOT_DIR: ${ROCM_ROOT_DIR}") +message("-----CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") +message("---CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") +message("---------GPU_TARGETS: ${GPU_TARGETS}") -if ( "${ROCM_ROOT_DIR}" STREQUAL "" ) - message ( FATAL_ERROR "ROCM_ROOT_DIR is not found." ) -endif () +if("${ROCM_ROOT_DIR}" STREQUAL "") + message(FATAL_ERROR "ROCM_ROOT_DIR is not found.") +endif() -find_library(FIND_AQL_PROFILE_LIB "libhsa-amd-aqlprofile64.so" HINTS ${CMAKE_PREFIX_PATH} PATHS ${ROCM_ROOT_DIR} PATH_SUFFIXES lib REQUIRED) +find_library( + FIND_AQL_PROFILE_LIB "libhsa-amd-aqlprofile64.so" + HINTS ${CMAKE_PREFIX_PATH} + PATHS ${ROCM_ROOT_DIR} + PATH_SUFFIXES lib REQUIRED) if(NOT FIND_AQL_PROFILE_LIB) - message("AQL_PROFILE not installed. Please install AQL_PROFILE") + message("AQL_PROFILE not installed. Please install AQL_PROFILE") endif() diff --git a/projects/rocprofiler/cmake_modules/utils.cmake b/projects/rocprofiler/cmake_modules/utils.cmake index f95a78335f..f1f856564a 100644 --- a/projects/rocprofiler/cmake_modules/utils.cmake +++ b/projects/rocprofiler/cmake_modules/utils.cmake @@ -20,77 +20,95 @@ # THE SOFTWARE. ################################################################################ -## Parses the VERSION_STRING variable and places -## the first, second and third number values in -## the major, minor and patch variables. -function( parse_version VERSION_STRING ) +# Parses the VERSION_STRING variable and places the first, second and third number values +# in the major, minor and patch variables. +function(parse_version VERSION_STRING) - string ( FIND ${VERSION_STRING} "-" STRING_INDEX ) + string(FIND ${VERSION_STRING} "-" STRING_INDEX) - if ( ${STRING_INDEX} GREATER -1 ) - math ( EXPR STRING_INDEX "${STRING_INDEX} + 1" ) - string ( SUBSTRING ${VERSION_STRING} ${STRING_INDEX} -1 VERSION_BUILD ) - endif () + if(${STRING_INDEX} GREATER -1) + math(EXPR STRING_INDEX "${STRING_INDEX} + 1") + string(SUBSTRING ${VERSION_STRING} ${STRING_INDEX} -1 VERSION_BUILD) + endif() - string ( REGEX MATCHALL "[0123456789]+" VERSIONS ${VERSION_STRING} ) - list ( LENGTH VERSIONS VERSION_COUNT ) + string(REGEX MATCHALL "[0123456789]+" VERSIONS ${VERSION_STRING}) + list(LENGTH VERSIONS VERSION_COUNT) - if ( ${VERSION_COUNT} GREATER 0) - list ( GET VERSIONS 0 MAJOR ) - set ( VERSION_MAJOR ${MAJOR} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${MAJOR}" ) - endif () + if(${VERSION_COUNT} GREATER 0) + list(GET VERSIONS 0 MAJOR) + set(VERSION_MAJOR + ${MAJOR} + PARENT_SCOPE) + set(TEMP_VERSION_STRING "${MAJOR}") + endif() - if ( ${VERSION_COUNT} GREATER 1 ) - list ( GET VERSIONS 1 MINOR ) - set ( VERSION_MINOR ${MINOR} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${MINOR}" ) - endif () + if(${VERSION_COUNT} GREATER 1) + list(GET VERSIONS 1 MINOR) + set(VERSION_MINOR + ${MINOR} + PARENT_SCOPE) + set(TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${MINOR}") + endif() - if ( ${VERSION_COUNT} GREATER 2 ) - list ( GET VERSIONS 2 PATCH ) - set ( VERSION_PATCH ${PATCH} PARENT_SCOPE ) - set ( TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${PATCH}" ) - endif () + if(${VERSION_COUNT} GREATER 2) + list(GET VERSIONS 2 PATCH) + set(VERSION_PATCH + ${PATCH} + PARENT_SCOPE) + set(TEMP_VERSION_STRING "${TEMP_VERSION_STRING}.${PATCH}") + endif() - if ( DEFINED VERSION_BUILD ) - set ( VERSION_BUILD "${VERSION_BUILD}" PARENT_SCOPE ) - endif () + if(DEFINED VERSION_BUILD) + set(VERSION_BUILD + "${VERSION_BUILD}" + PARENT_SCOPE) + endif() - set ( VERSION_STRING "${TEMP_VERSION_STRING}" PARENT_SCOPE ) - -endfunction () - -## Gets the current version of the repository -## using versioning tags and git describe. -## Passes back a packaging version string -## and a library version string. -function ( get_version DEFAULT_VERSION_STRING ) - - parse_version ( ${DEFAULT_VERSION_STRING} ) - - find_program ( GIT NAMES git ) - - if ( GIT ) - - execute_process ( COMMAND "git describe --dirty --long --match [0-9]* 2>/dev/null" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_TAG_STRING - OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE RESULT ) - - if ( ${RESULT} EQUAL 0 ) - - parse_version ( ${GIT_TAG_STRING} ) - - endif () - - endif () - - set( VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE ) - set( VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE ) - set( VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE ) - set( VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE ) - set( VERSION_BUILD "${VERSION_BUILD}" PARENT_SCOPE ) + set(VERSION_STRING + "${TEMP_VERSION_STRING}" + PARENT_SCOPE) + +endfunction() + +# Gets the current version of the repository using versioning tags and git describe. +# Passes back a packaging version string and a library version string. +function(get_version DEFAULT_VERSION_STRING) + + parse_version(${DEFAULT_VERSION_STRING}) + + find_program(GIT NAMES git) + + if(GIT) + + execute_process( + COMMAND "git describe --dirty --long --match [0-9]* 2>/dev/null" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_TAG_STRING + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT) + + if(${RESULT} EQUAL 0) + + parse_version(${GIT_TAG_STRING}) + + endif() + + endif() + + set(VERSION_STRING + "${VERSION_STRING}" + PARENT_SCOPE) + set(VERSION_MAJOR + "${VERSION_MAJOR}" + PARENT_SCOPE) + set(VERSION_MINOR + "${VERSION_MINOR}" + PARENT_SCOPE) + set(VERSION_PATCH + "${VERSION_PATCH}" + PARENT_SCOPE) + set(VERSION_BUILD + "${VERSION_BUILD}" + PARENT_SCOPE) endfunction() diff --git a/projects/rocprofiler/include/rocprofiler/rocprofiler.h b/projects/rocprofiler/include/rocprofiler/rocprofiler.h index 7d9a02ef40..84f7ec3013 100644 --- a/projects/rocprofiler/include/rocprofiler/rocprofiler.h +++ b/projects/rocprofiler/include/rocprofiler/rocprofiler.h @@ -164,12 +164,12 @@ typedef struct { // Profiling feature type typedef struct { - rocprofiler_feature_kind_t kind; // feature kind + rocprofiler_feature_kind_t kind; // feature kind union { - const char* name; // feature name + const char* name; // feature name struct { - const char* block; // counter block name - uint32_t event; // counter event id + const char* block; // counter block name + uint32_t event; // counter event id } counter; }; const rocprofiler_parameter_t* parameters; // feature parameters array @@ -216,23 +216,25 @@ typedef struct { } rocprofiler_properties_t; // Create new profiling context -hsa_status_t rocprofiler_open(hsa_agent_t agent, // GPU handle - rocprofiler_feature_t* features, // [in] profiling features array - uint32_t feature_count, // profiling info count - rocprofiler_t** context, // [out] context object - uint32_t mode, // profiling mode mask +hsa_status_t rocprofiler_open(hsa_agent_t agent, // GPU handle + rocprofiler_feature_t* features, // [in] profiling features array + uint32_t feature_count, // profiling info count + rocprofiler_t** context, // [out] context object + uint32_t mode, // profiling mode mask rocprofiler_properties_t* properties); // profiling properties // Add feature to a features set -hsa_status_t rocprofiler_add_feature(const rocprofiler_feature_t* feature, // [in] - rocprofiler_feature_set_t* features_set); // [in/out] profiling features set +hsa_status_t rocprofiler_add_feature( + const rocprofiler_feature_t* feature, // [in] + rocprofiler_feature_set_t* features_set); // [in/out] profiling features set // Create new profiling context -hsa_status_t rocprofiler_features_set_open(hsa_agent_t agent, // GPU handle - rocprofiler_feature_set_t* features_set, // [in] profiling features set - rocprofiler_t** context, // [out] context object - uint32_t mode, // profiling mode mask - rocprofiler_properties_t* properties); // profiling properties +hsa_status_t rocprofiler_features_set_open( + hsa_agent_t agent, // GPU handle + rocprofiler_feature_set_t* features_set, // [in] profiling features set + rocprofiler_t** context, // [out] context object + uint32_t mode, // profiling mode mask + rocprofiler_properties_t* properties); // profiling properties // Delete profiling info hsa_status_t rocprofiler_close(rocprofiler_t* context); // [in] profiling context @@ -242,24 +244,24 @@ hsa_status_t rocprofiler_reset(rocprofiler_t* context, // [in] profiling contex uint32_t group_index); // group index // Return context agent -hsa_status_t rocprofiler_get_agent(rocprofiler_t* context, // [in] profiling context - hsa_agent_t* agent); // [out] GPU handle +hsa_status_t rocprofiler_get_agent(rocprofiler_t* context, // [in] profiling context + hsa_agent_t* agent); // [out] GPU handle // Supported time value ID typedef enum { - ROCPROFILER_TIME_ID_CLOCK_REALTIME = 0, // Linux realtime clock time - ROCPROFILER_TIME_ID_CLOCK_REALTIME_COARSE = 1, // Linux realtime-coarse clock time - ROCPROFILER_TIME_ID_CLOCK_MONOTONIC = 2, // Linux monotonic clock time - ROCPROFILER_TIME_ID_CLOCK_MONOTONIC_COARSE = 3, // Linux monotonic-coarse clock time - ROCPROFILER_TIME_ID_CLOCK_MONOTONIC_RAW = 4, // Linux monotonic-raw clock time + ROCPROFILER_TIME_ID_CLOCK_REALTIME = 0, // Linux realtime clock time + ROCPROFILER_TIME_ID_CLOCK_REALTIME_COARSE = 1, // Linux realtime-coarse clock time + ROCPROFILER_TIME_ID_CLOCK_MONOTONIC = 2, // Linux monotonic clock time + ROCPROFILER_TIME_ID_CLOCK_MONOTONIC_COARSE = 3, // Linux monotonic-coarse clock time + ROCPROFILER_TIME_ID_CLOCK_MONOTONIC_RAW = 4, // Linux monotonic-raw clock time } rocprofiler_time_id_t; // Return time value for a given time ID and profiling timestamp hsa_status_t rocprofiler_get_time( - rocprofiler_time_id_t time_id, // identifier of the particular time to convert the timesatmp - uint64_t timestamp, // profiling timestamp - uint64_t* value_ns, // [out] returned time 'ns' value, ignored if NULL - uint64_t* error_ns); // [out] returned time error 'ns' value, ignored if NULL + rocprofiler_time_id_t time_id, // identifier of the particular time to convert the timesatmp + uint64_t timestamp, // profiling timestamp + uint64_t* value_ns, // [out] returned time 'ns' value, ignored if NULL + uint64_t* error_ns); // [out] returned time error 'ns' value, ignored if NULL //////////////////////////////////////////////////////////////////////////////// // Queue callbacks @@ -269,26 +271,26 @@ hsa_status_t rocprofiler_get_time( // Dispatch record typedef struct { - uint64_t dispatch; // dispatch timestamp, ns - uint64_t begin; // kernel begin timestamp, ns - uint64_t end; // kernel end timestamp, ns - uint64_t complete; // completion signal timestamp, ns + uint64_t dispatch; // dispatch timestamp, ns + uint64_t begin; // kernel begin timestamp, ns + uint64_t end; // kernel end timestamp, ns + uint64_t complete; // completion signal timestamp, ns } rocprofiler_dispatch_record_t; // Profiling callback data typedef struct { - hsa_agent_t agent; // GPU agent handle - uint32_t agent_index; // GPU index (GPU Driver Node ID as reported in the sysfs topology) - const hsa_queue_t* queue; // HSA queue - uint64_t queue_index; // Index in the queue - uint32_t queue_id; // Queue id - hsa_signal_t completion_signal; // Completion signal - const hsa_kernel_dispatch_packet_t* packet; // HSA dispatch packet - const char* kernel_name; // Kernel name - uint64_t kernel_object; // Kernel object address - const amd_kernel_code_t* kernel_code; // Kernel code pointer - uint32_t thread_id; // Thread id - const rocprofiler_dispatch_record_t* record; // Dispatch record + hsa_agent_t agent; // GPU agent handle + uint32_t agent_index; // GPU index (GPU Driver Node ID as reported in the sysfs topology) + const hsa_queue_t* queue; // HSA queue + uint64_t queue_index; // Index in the queue + uint32_t queue_id; // Queue id + hsa_signal_t completion_signal; // Completion signal + const hsa_kernel_dispatch_packet_t* packet; // HSA dispatch packet + const char* kernel_name; // Kernel name + uint64_t kernel_object; // Kernel object address + const amd_kernel_code_t* kernel_code; // Kernel code pointer + uint32_t thread_id; // Thread id + const rocprofiler_dispatch_record_t* record; // Dispatch record } rocprofiler_callback_data_t; // Profiling callback type @@ -299,15 +301,14 @@ typedef hsa_status_t (*rocprofiler_callback_t)( // Queue callbacks typedef struct { - rocprofiler_callback_t dispatch; // dispatch callback - hsa_status_t (*create)(hsa_queue_t* queue, void* data); // create callback - hsa_status_t (*destroy)(hsa_queue_t* queue, void* data); // destroy callback + rocprofiler_callback_t dispatch; // dispatch callback + hsa_status_t (*create)(hsa_queue_t* queue, void* data); // create callback + hsa_status_t (*destroy)(hsa_queue_t* queue, void* data); // destroy callback } rocprofiler_queue_callbacks_t; // Set queue callbacks -hsa_status_t rocprofiler_set_queue_callbacks( - rocprofiler_queue_callbacks_t callbacks, // callbacks - void* data); // [in/out] passed callbacks data +hsa_status_t rocprofiler_set_queue_callbacks(rocprofiler_queue_callbacks_t callbacks, // callbacks + void* data); // [in/out] passed callbacks data // Remove queue callbacks hsa_status_t rocprofiler_remove_queue_callbacks(); @@ -323,20 +324,20 @@ hsa_status_t rocprofiler_stop_queue_callbacks(); // contect.invocations' to collect all profiling data // Start profiling -hsa_status_t rocprofiler_start(rocprofiler_t* context, // [in/out] profiling context - uint32_t group_index); // group index +hsa_status_t rocprofiler_start(rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index); // group index // Stop profiling -hsa_status_t rocprofiler_stop(rocprofiler_t* context, // [in/out] profiling context - uint32_t group_index); // group index +hsa_status_t rocprofiler_stop(rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index); // group index // Read profiling -hsa_status_t rocprofiler_read(rocprofiler_t* context, // [in/out] profiling context - uint32_t group_index); // group index +hsa_status_t rocprofiler_read(rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index); // group index // Read profiling data -hsa_status_t rocprofiler_get_data(rocprofiler_t* context, // [in/out] profiling context - uint32_t group_index); // group index +hsa_status_t rocprofiler_get_data(rocprofiler_t* context, // [in/out] profiling context + uint32_t group_index); // group index // Get profiling groups count hsa_status_t rocprofiler_group_count(const rocprofiler_t* context, // [in] profiling context @@ -379,75 +380,76 @@ hsa_status_t rocprofiler_iterate_trace_data( // Profiling info kind typedef enum { - ROCPROFILER_INFO_KIND_METRIC = 0, // metric info - ROCPROFILER_INFO_KIND_METRIC_COUNT = 1, // metric features count, int32 - ROCPROFILER_INFO_KIND_TRACE = 2, // trace info - ROCPROFILER_INFO_KIND_TRACE_COUNT = 3, // trace features count, int32 - ROCPROFILER_INFO_KIND_TRACE_PARAMETER = 4, // trace parameter info - ROCPROFILER_INFO_KIND_TRACE_PARAMETER_COUNT = 5 // trace parameter count, int32 + ROCPROFILER_INFO_KIND_METRIC = 0, // metric info + ROCPROFILER_INFO_KIND_METRIC_COUNT = 1, // metric features count, int32 + ROCPROFILER_INFO_KIND_TRACE = 2, // trace info + ROCPROFILER_INFO_KIND_TRACE_COUNT = 3, // trace features count, int32 + ROCPROFILER_INFO_KIND_TRACE_PARAMETER = 4, // trace parameter info + ROCPROFILER_INFO_KIND_TRACE_PARAMETER_COUNT = 5 // trace parameter count, int32 } rocprofiler_info_kind_t; // Profiling info query typedef union { - rocprofiler_info_kind_t info_kind; // queried profiling info kind + rocprofiler_info_kind_t info_kind; // queried profiling info kind struct { - const char* trace_name; // queried info trace name + const char* trace_name; // queried info trace name } trace_parameter; } rocprofiler_info_query_t; // Profiling info data typedef struct { - uint32_t agent_index; // GPU HSA agent index (GPU Driver Node ID as reported in the sysfs topology) - rocprofiler_info_kind_t kind; // info data kind + uint32_t + agent_index; // GPU HSA agent index (GPU Driver Node ID as reported in the sysfs topology) + rocprofiler_info_kind_t kind; // info data kind union { struct { - const char* name; // metric name - uint32_t instances; // instances number - const char* expr; // metric expression, NULL for basic counters - const char* description; // metric description - const char* block_name; // block name - uint32_t block_counters; // number of block counters + const char* name; // metric name + uint32_t instances; // instances number + const char* expr; // metric expression, NULL for basic counters + const char* description; // metric description + const char* block_name; // block name + uint32_t block_counters; // number of block counters } metric; struct { - const char* name; // trace name - const char* description; // trace description - uint32_t parameter_count; // supported by the trace number parameters + const char* name; // trace name + const char* description; // trace description + uint32_t parameter_count; // supported by the trace number parameters } trace; struct { - uint32_t code; // parameter code - const char* trace_name; // trace name - const char* parameter_name; // parameter name - const char* description; // trace parameter description + uint32_t code; // parameter code + const char* trace_name; // trace name + const char* parameter_name; // parameter name + const char* description; // trace parameter description } trace_parameter; }; } rocprofiler_info_data_t; // Return the info for a given info kind -hsa_status_t rocprofiler_get_info( - const hsa_agent_t* agent, // [in] GFXIP handle - rocprofiler_info_kind_t kind, // kind of iterated info - void *data); // [in/out] returned data +hsa_status_t rocprofiler_get_info(const hsa_agent_t* agent, // [in] GFXIP handle + rocprofiler_info_kind_t kind, // kind of iterated info + void* data); // [in/out] returned data -// Iterate over the info for a given info kind, and invoke an application-defined callback on every iteration -hsa_status_t rocprofiler_iterate_info( - const hsa_agent_t* agent, // [in] GFXIP handle - rocprofiler_info_kind_t kind, // kind of iterated info - hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback - void *data); // [in/out] data passed to callback +// Iterate over the info for a given info kind, and invoke an application-defined callback on every +// iteration +hsa_status_t rocprofiler_iterate_info(const hsa_agent_t* agent, // [in] GFXIP handle + rocprofiler_info_kind_t kind, // kind of iterated info + hsa_status_t (*callback)(const rocprofiler_info_data_t info, + void* data), // callback + void* data); // [in/out] data passed to callback -// Iterate over the info for a given info query, and invoke an application-defined callback on every iteration -hsa_status_t rocprofiler_query_info( - const hsa_agent_t *agent, // [in] GFXIP handle - rocprofiler_info_query_t query, // iterated info query - hsa_status_t (*callback)(const rocprofiler_info_data_t info, void *data), // callback - void *data); // [in/out] data passed to callback +// Iterate over the info for a given info query, and invoke an application-defined callback on every +// iteration +hsa_status_t rocprofiler_query_info(const hsa_agent_t* agent, // [in] GFXIP handle + rocprofiler_info_query_t query, // iterated info query + hsa_status_t (*callback)(const rocprofiler_info_data_t info, + void* data), // callback + void* data); // [in/out] data passed to callback // Create a profiled queue. All dispatches on this queue will be profiled hsa_status_t rocprofiler_queue_create_profiled( - hsa_agent_t agent_handle,uint32_t size, hsa_queue_type32_t type, - void (*callback)(hsa_status_t status, hsa_queue_t* source, void* data), - void* data, uint32_t private_segment_size, uint32_t group_segment_size, - hsa_queue_t** queue); + hsa_agent_t agent_handle, uint32_t size, hsa_queue_type32_t type, + void (*callback)(hsa_status_t status, hsa_queue_t* source, void* data), void* data, + uint32_t private_segment_size, uint32_t group_segment_size, hsa_queue_t** queue); //////////////////////////////////////////////////////////////////////////////// // Profiling pool @@ -461,8 +463,8 @@ typedef void rocprofiler_pool_t; // Profiling pool entry typedef struct { - rocprofiler_t* context; // context object - void* payload; // payload data object + rocprofiler_t* context; // context object + void* payload; // payload data object } rocprofiler_pool_entry_t; // Profiling handler, calling on profiling completion @@ -478,120 +480,118 @@ typedef struct { // Open profiling pool hsa_status_t rocprofiler_pool_open( - hsa_agent_t agent, // GPU handle - rocprofiler_feature_t* features, // [in] profiling features array - uint32_t feature_count, // profiling info count - rocprofiler_pool_t** pool, // [out] context object - uint32_t mode, // profiling mode mask - rocprofiler_pool_properties_t*); // pool properties + hsa_agent_t agent, // GPU handle + rocprofiler_feature_t* features, // [in] profiling features array + uint32_t feature_count, // profiling info count + rocprofiler_pool_t** pool, // [out] context object + uint32_t mode, // profiling mode mask + rocprofiler_pool_properties_t*); // pool properties // Close profiling pool -hsa_status_t rocprofiler_pool_close( - rocprofiler_pool_t* pool); // profiling pool handle +hsa_status_t rocprofiler_pool_close(rocprofiler_pool_t* pool); // profiling pool handle // Fetch profiling pool entry hsa_status_t rocprofiler_pool_fetch( - rocprofiler_pool_t* pool, // profiling pool handle - rocprofiler_pool_entry_t* entry); // [out] empty profiling pool entry + rocprofiler_pool_t* pool, // profiling pool handle + rocprofiler_pool_entry_t* entry); // [out] empty profiling pool entry // Release profiling pool entry hsa_status_t rocprofiler_pool_release( - rocprofiler_pool_entry_t* entry); // released profiling pool entry + rocprofiler_pool_entry_t* entry); // released profiling pool entry // Iterate fetched profiling pool entries -hsa_status_t rocprofiler_pool_iterate( - rocprofiler_pool_t* pool, // profiling pool handle - hsa_status_t (*callback)(rocprofiler_pool_entry_t* entry, void* data), // callback - void *data); // [in/out] data passed to callback +hsa_status_t rocprofiler_pool_iterate(rocprofiler_pool_t* pool, // profiling pool handle + hsa_status_t (*callback)(rocprofiler_pool_entry_t* entry, + void* data), // callback + void* data); // [in/out] data passed to callback // Flush completed entries in profiling pool -hsa_status_t rocprofiler_pool_flush( - rocprofiler_pool_t* pool); // profiling pool handle +hsa_status_t rocprofiler_pool_flush(rocprofiler_pool_t* pool); // profiling pool handle //////////////////////////////////////////////////////////////////////////////// // HSA intercepting API // HSA callbacks ID enumeration typedef enum { - ROCPROFILER_HSA_CB_ID_ALLOCATE = 0, // Memory allocate callback - ROCPROFILER_HSA_CB_ID_DEVICE = 1, // Device assign callback - ROCPROFILER_HSA_CB_ID_MEMCOPY = 2, // Memcopy callback - ROCPROFILER_HSA_CB_ID_SUBMIT = 3, // Packet submit callback - ROCPROFILER_HSA_CB_ID_KSYMBOL = 4, // Loading/unloading of kernel symbol - ROCPROFILER_HSA_CB_ID_CODEOBJ = 5 // Loading/unloading of kernel symbol + ROCPROFILER_HSA_CB_ID_ALLOCATE = 0, // Memory allocate callback + ROCPROFILER_HSA_CB_ID_DEVICE = 1, // Device assign callback + ROCPROFILER_HSA_CB_ID_MEMCOPY = 2, // Memcopy callback + ROCPROFILER_HSA_CB_ID_SUBMIT = 3, // Packet submit callback + ROCPROFILER_HSA_CB_ID_KSYMBOL = 4, // Loading/unloading of kernel symbol + ROCPROFILER_HSA_CB_ID_CODEOBJ = 5 // Loading/unloading of kernel symbol } rocprofiler_hsa_cb_id_t; // HSA callback data type typedef struct { union { struct { - const void* ptr; // allocated area ptr - size_t size; // allocated area size, zero size means 'free' callback - hsa_amd_segment_t segment; // allocated area's memory segment type + const void* ptr; // allocated area ptr + size_t size; // allocated area size, zero size means 'free' callback + hsa_amd_segment_t segment; // allocated area's memory segment type hsa_amd_memory_pool_global_flag_t global_flag; // allocated area's memory global flag int is_code; // equal to 1 if code is allocated } allocate; struct { - hsa_device_type_t type; // type of assigned device - uint32_t id; // id of assigned device - hsa_agent_t agent; // device HSA agent handle - const void* ptr; // ptr the device is assigned to + hsa_device_type_t type; // type of assigned device + uint32_t id; // id of assigned device + hsa_agent_t agent; // device HSA agent handle + const void* ptr; // ptr the device is assigned to } device; struct { - const void* dst; // memcopy dst ptr - const void* src; // memcopy src ptr - size_t size; // memcopy size bytes + const void* dst; // memcopy dst ptr + const void* src; // memcopy src ptr + size_t size; // memcopy size bytes } memcopy; struct { - const void* packet; // submitted to GPU packet - const char* kernel_name; // kernel name, not NULL if dispatch - hsa_queue_t* queue; // HSA queue the kernel was submitted to - uint32_t device_type; // type of device the packed is submitted to - uint32_t device_id; // id of device the packed is submitted to + const void* packet; // submitted to GPU packet + const char* kernel_name; // kernel name, not NULL if dispatch + hsa_queue_t* queue; // HSA queue the kernel was submitted to + uint32_t device_type; // type of device the packed is submitted to + uint32_t device_id; // id of device the packed is submitted to } submit; struct { - uint64_t object; // kernel symbol object - const char* name; // kernel symbol name - uint32_t name_length; // kernel symbol name length - int unload; // symbol executable destroy + uint64_t object; // kernel symbol object + const char* name; // kernel symbol name + uint32_t name_length; // kernel symbol name length + int unload; // symbol executable destroy } ksymbol; struct { - uint32_t storage_type; // code object storage type - int storage_file; // origin file descriptor - uint64_t memory_base; // origin memory base - uint64_t memory_size; // origin memory size - uint64_t load_base; // codeobj load base - uint64_t load_size; // codeobj load size - uint64_t load_delta; // codeobj load size - uint32_t uri_length; // URI string length - char* uri; // URI string - int unload; // unload flag + uint32_t storage_type; // code object storage type + int storage_file; // origin file descriptor + uint64_t memory_base; // origin memory base + uint64_t memory_size; // origin memory size + uint64_t load_base; // codeobj load base + uint64_t load_size; // codeobj load size + uint64_t load_delta; // codeobj load size + uint32_t uri_length; // URI string length + char* uri; // URI string + int unload; // unload flag } codeobj; }; } rocprofiler_hsa_callback_data_t; // HSA callback function type typedef hsa_status_t (*rocprofiler_hsa_callback_fun_t)( - rocprofiler_hsa_cb_id_t id, // callback id - const rocprofiler_hsa_callback_data_t* data, // [in] callback data - void* arg); // [in/out] user passed data + rocprofiler_hsa_cb_id_t id, // callback id + const rocprofiler_hsa_callback_data_t* data, // [in] callback data + void* arg); // [in/out] user passed data // HSA callbacks structure typedef struct { - rocprofiler_hsa_callback_fun_t allocate; // memory allocate callback - rocprofiler_hsa_callback_fun_t device; // agent assign callback - rocprofiler_hsa_callback_fun_t memcopy; // memory copy callback - rocprofiler_hsa_callback_fun_t submit; // packet submit callback - rocprofiler_hsa_callback_fun_t ksymbol; // kernel symbol callback - rocprofiler_hsa_callback_fun_t codeobj; // codeobject load/unload callback + rocprofiler_hsa_callback_fun_t allocate; // memory allocate callback + rocprofiler_hsa_callback_fun_t device; // agent assign callback + rocprofiler_hsa_callback_fun_t memcopy; // memory copy callback + rocprofiler_hsa_callback_fun_t submit; // packet submit callback + rocprofiler_hsa_callback_fun_t ksymbol; // kernel symbol callback + rocprofiler_hsa_callback_fun_t codeobj; // codeobject load/unload callback } rocprofiler_hsa_callbacks_t; // Set callbacks. If the callback is NULL then it is disabled. // If callback returns a value that is not HSA_STATUS_SUCCESS the callback // will be unregistered. hsa_status_t rocprofiler_set_hsa_callbacks( - const rocprofiler_hsa_callbacks_t callbacks, // HSA callback function - void* arg); // callback user data + const rocprofiler_hsa_callbacks_t callbacks, // HSA callback function + void* arg); // callback user data #ifdef __cplusplus } // extern "C" block diff --git a/projects/rocprofiler/include/rocprofiler/v2/rocprofiler.h b/projects/rocprofiler/include/rocprofiler/v2/rocprofiler.h index e58bae5b04..bddabf2772 100644 --- a/projects/rocprofiler/include/rocprofiler/v2/rocprofiler.h +++ b/projects/rocprofiler/include/rocprofiler/v2/rocprofiler.h @@ -1714,7 +1714,7 @@ typedef enum { ROCPROFILER_ATT_TOKEN_MASK2 = 4, ROCPROFILER_ATT_SE_MASK = 5, ROCPROFILER_ATT_SAMPLE_RATE = 6, - ROCPROFILER_ATT_BUFFER_SIZE = 7, //! ATT collection max data size. + ROCPROFILER_ATT_BUFFER_SIZE = 7, //! ATT collection max data size. ROCPROFILER_ATT_PERF_MASK = 240, ROCPROFILER_ATT_PERF_CTRL = 241, ROCPROFILER_ATT_PERFCOUNTER = 242, diff --git a/projects/rocprofiler/plugin/CMakeLists.txt b/projects/rocprofiler/plugin/CMakeLists.txt index 922a8b1862..03201d40da 100644 --- a/projects/rocprofiler/plugin/CMakeLists.txt +++ b/projects/rocprofiler/plugin/CMakeLists.txt @@ -1,23 +1,23 @@ ################################################################################ -## Copyright (c) 2022 Advanced Micro Devices, Inc. -## -## 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. +# Copyright (c) 2022 Advanced Micro Devices, Inc. +# +# 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. ################################################################################ add_subdirectory(file) diff --git a/projects/rocprofiler/plugin/att/CMakeLists.txt b/projects/rocprofiler/plugin/att/CMakeLists.txt index 05c0ce8774..4384bb93eb 100644 --- a/projects/rocprofiler/plugin/att/CMakeLists.txt +++ b/projects/rocprofiler/plugin/att/CMakeLists.txt @@ -17,10 +17,10 @@ # ############################################################################## find_library( - ROCPROFV2_ATT rocprofv2_att - HINTS ${CMAKE_INSTALL_PREFIX} - PATHS ${ROCM_PATH} - PATH_SUFFIXES hsa-amd-aqlprofile) + ROCPROFV2_ATT rocprofv2_att + HINTS ${CMAKE_INSTALL_PREFIX} + PATHS ${ROCM_PATH} + PATH_SUFFIXES hsa-amd-aqlprofile) set(ENV{ROCPROFV2_ATT_LIB_PATH} $ROCPROFV2_ATT) @@ -30,30 +30,26 @@ file(GLOB FILE_SOURCES att.cpp) add_library(att_plugin SHARED ${FILE_SOURCES} ${ROCPROFILER_UTIL_SRC_FILES}) set_target_properties( - att_plugin - PROPERTIES CXX_VISIBILITY_PRESET hidden - LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../exportmap - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rocprofiler) + att_plugin + PROPERTIES CXX_VISIBILITY_PRESET hidden + LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../exportmap + LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rocprofiler) target_compile_definitions(att_plugin PRIVATE HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_HCC__=1) -target_include_directories( - att_plugin PRIVATE ${PROJECT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(att_plugin PRIVATE ${PROJECT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}) target_link_options( - att_plugin PRIVATE - -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap - -Wl,--no-undefined) -target_link_libraries(att_plugin PRIVATE rocprofiler-v2 - hsa-runtime64::hsa-runtime64 stdc++fs) + att_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap + -Wl,--no-undefined) +target_link_libraries(att_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 + stdc++fs) -install(TARGETS att_plugin - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} - COMPONENT asan) -install(TARGETS att_plugin - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} - COMPONENT runtime) +install(TARGETS att_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} + COMPONENT asan) +install(TARGETS att_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} + COMPONENT runtime) configure_file(att.py att/att.py COPYONLY) configure_file(trace_view.py att/trace_view.py COPYONLY) @@ -64,7 +60,7 @@ configure_file(ui/logo.svg att/ui/logo.svg COPYONLY) configure_file(ui/styles.css att/ui/styles.css COPYONLY) configure_file(ui/httpserver.py att/ui/httpserver.py COPYONLY) install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/att - DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/rocprofiler - USE_SOURCE_PERMISSIONS - COMPONENT runtime) + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/att + DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/rocprofiler + USE_SOURCE_PERMISSIONS + COMPONENT runtime) diff --git a/projects/rocprofiler/plugin/att/att.cpp b/projects/rocprofiler/plugin/att/att.cpp index 67eb4a5e56..f5aadba747 100644 --- a/projects/rocprofiler/plugin/att/att.cpp +++ b/projects/rocprofiler/plugin/att/att.cpp @@ -54,11 +54,12 @@ class att_plugin_t { att_plugin_t() { std::vector mpivars = {"MPI_RANK", "OMPI_COMM_WORLD_RANK", "MV2_COMM_WORLD_RANK"}; - for (const char* envvar : mpivars) if (const char* env = getenv(envvar)) { - MPI_RANK = atoi(env); - MPI_ENABLE = true; - break; - } + for (const char* envvar : mpivars) + if (const char* env = getenv(envvar)) { + MPI_RANK = atoi(env); + MPI_ENABLE = true; + break; + } } bool MPI_ENABLE = false; @@ -92,16 +93,15 @@ class att_plugin_t { std::string name_demangled = rocprofiler::truncate_name(rocprofiler::cxx_demangle(kernel_name_c)); - if (name_demangled.size() > ATT_FILENAME_MAXBYTES) // Limit filename size + if (name_demangled.size() > ATT_FILENAME_MAXBYTES) // Limit filename size name_demangled = name_demangled.substr(0, ATT_FILENAME_MAXBYTES); std::string outfilepath = "."; - if (const char* env = getenv("OUTPUT_PATH")) - outfilepath = std::string(env); + if (const char* env = getenv("OUTPUT_PATH")) outfilepath = std::string(env); - outfilepath.reserve(outfilepath.size()+128); // Max filename size - outfilepath += '/'+name_demangled; - if (MPI_ENABLE) outfilepath += "_rank"+std::to_string(MPI_RANK); + outfilepath.reserve(outfilepath.size() + 128); // Max filename size + outfilepath += '/' + name_demangled; + if (MPI_ENABLE) outfilepath += "_rank" + std::to_string(MPI_RANK); outfilepath += "_v"; // Find if this filename already exists. If so, increment vname. @@ -113,9 +113,9 @@ class att_plugin_t { auto dispatch_id = att_tracer_record->header.id.handle; std::string fname = outfilepath + "_kernel.txt"; - std::ofstream(fname.c_str()) << name_demangled << " dispatch[" << dispatch_id - << "] GPU[" << att_tracer_record->gpu_id.handle - << "]: " << kernel_name_c << '\n'; + std::ofstream(fname.c_str()) << name_demangled << " dispatch[" << dispatch_id << "] GPU[" + << att_tracer_record->gpu_id.handle << "]: " << kernel_name_c + << '\n'; // iterate over each shader engine att trace int se_num = att_tracer_record->shader_engine_data_count; diff --git a/projects/rocprofiler/plugin/cli/CMakeLists.txt b/projects/rocprofiler/plugin/cli/CMakeLists.txt index 8ea8e9a920..2090c8a952 100644 --- a/projects/rocprofiler/plugin/cli/CMakeLists.txt +++ b/projects/rocprofiler/plugin/cli/CMakeLists.txt @@ -25,23 +25,25 @@ file(GLOB ROCPROFILER_UTIL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/utils/helper.cpp) file(GLOB CLI_SOURCES "*.cpp") add_library(cli_plugin SHARED ${CLI_SOURCES} ${ROCPROFILER_UTIL_SRC_FILES}) -set_target_properties(cli_plugin PROPERTIES - CXX_VISIBILITY_PRESET hidden - LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../exportmap - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rocprofiler) +set_target_properties( + cli_plugin + PROPERTIES CXX_VISIBILITY_PRESET hidden + LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../exportmap + LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rocprofiler) -target_compile_definitions(cli_plugin - PRIVATE HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_HCC__=1) +target_compile_definitions(cli_plugin PRIVATE HIP_PROF_HIP_API_STRING=1 + __HIP_PLATFORM_HCC__=1) target_include_directories(cli_plugin PRIVATE ${PROJECT_SOURCE_DIR}) -target_link_options(cli_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap -Wl,--no-undefined) +target_link_options( + cli_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap + -Wl,--no-undefined) -target_link_libraries(cli_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 stdc++fs atomic amd_comgr dl) +target_link_libraries(cli_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 + stdc++fs atomic amd_comgr dl) -install(TARGETS cli_plugin LIBRARY - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} - COMPONENT asan) -install(TARGETS cli_plugin LIBRARY - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} - COMPONENT runtime) +install(TARGETS cli_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} + COMPONENT asan) +install(TARGETS cli_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} + COMPONENT runtime) diff --git a/projects/rocprofiler/plugin/ctf/CMakeLists.txt b/projects/rocprofiler/plugin/ctf/CMakeLists.txt index a84df0753b..9cab0cb143 100644 --- a/projects/rocprofiler/plugin/ctf/CMakeLists.txt +++ b/projects/rocprofiler/plugin/ctf/CMakeLists.txt @@ -1,76 +1,84 @@ ################################################################################ -## Copyright (c) 2022 Advanced Micro Devices, Inc. -## -## 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. +# Copyright (c) 2022 Advanced Micro Devices, Inc. +# +# 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. ################################################################################ # Plugin shared object. -add_library(ctf_plugin SHARED - ctf.cpp - plugin.cpp - barectf.c "${CMAKE_CURRENT_BINARY_DIR}/barectf.h" - ${PROJECT_SOURCE_DIR}/src/utils/helper.cpp - hsa_begin.cpp.i hsa_end.cpp.i - hip_begin.cpp.i hip_end.cpp.i) -set_target_properties(ctf_plugin PROPERTIES - CXX_VISIBILITY_PRESET hidden - LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../exportmap" - LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/rocprofiler") +add_library( + ctf_plugin SHARED + ctf.cpp + plugin.cpp + barectf.c + "${CMAKE_CURRENT_BINARY_DIR}/barectf.h" + ${PROJECT_SOURCE_DIR}/src/utils/helper.cpp + hsa_begin.cpp.i + hsa_end.cpp.i + hip_begin.cpp.i + hip_end.cpp.i) +set_target_properties( + ctf_plugin + PROPERTIES CXX_VISIBILITY_PRESET hidden + LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../exportmap" + LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/rocprofiler") set(METADATA_STREAM_FILE_DIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/plugin/ctf") -target_compile_definitions(ctf_plugin PUBLIC AMD_INTERNAL_BUILD PRIVATE - HIP_PROF_HIP_API_STRING=1 - __HIP_PLATFORM_HCC__=1 - CTF_PLUGIN_METADATA_FILE_PATH="${CMAKE_INSTALL_PREFIX}/${METADATA_STREAM_FILE_DIR}/metadata") -target_include_directories(ctf_plugin PRIVATE - "${PROJECT_SOURCE_DIR}" - "${CMAKE_BINARY_DIR}/src/api" - "${CMAKE_CURRENT_BINARY_DIR}") -target_link_options(ctf_plugin PRIVATE - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap" - -Wl,--no-undefined) -target_link_libraries(ctf_plugin PRIVATE - rocprofiler-v2 - hsa-runtime64::hsa-runtime64 - stdc++fs - dl) -install(TARGETS ctf_plugin LIBRARY - DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}" - COMPONENT plugins) +target_compile_definitions( + ctf_plugin + PUBLIC AMD_INTERNAL_BUILD + PRIVATE + HIP_PROF_HIP_API_STRING=1 + __HIP_PLATFORM_HCC__=1 + CTF_PLUGIN_METADATA_FILE_PATH="${CMAKE_INSTALL_PREFIX}/${METADATA_STREAM_FILE_DIR}/metadata" + ) +target_include_directories( + ctf_plugin PRIVATE "${PROJECT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/src/api" + "${CMAKE_CURRENT_BINARY_DIR}") +target_link_options( + ctf_plugin PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap" + -Wl,--no-undefined) +target_link_libraries(ctf_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 + stdc++fs dl) +install(TARGETS ctf_plugin LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}" + COMPONENT plugins) -# `gen_api_files.py` and `gen_env_yaml.py` require Python 3, -# CppHeaderParser, PyYAML, and barectf. -find_package(Python3 COMPONENTS Interpreter REQUIRED) +# `gen_api_files.py` and `gen_env_yaml.py` require Python 3, CppHeaderParser, PyYAML, and +# barectf. +find_package( + Python3 + COMPONENTS Interpreter + REQUIRED) message("Python: ${Python3_EXECUTABLE})") execute_process(COMMAND Python3::Interpreter -c "print('hello')") function(check_py3_pkg pkg_name) - execute_process(COMMAND "${Python3_EXECUTABLE}" -c "import ${pkg_name}" - RESULT_VARIABLE PY3_IMPORT_RES - OUTPUT_QUIET) + execute_process( + COMMAND "${Python3_EXECUTABLE}" -c "import ${pkg_name}" + RESULT_VARIABLE PY3_IMPORT_RES + OUTPUT_QUIET) - if(NOT (${PY3_IMPORT_RES} EQUAL 0)) - message(FATAL_ERROR "Cannot find Python 3 package `${pkg_name}`") - endif() + if(NOT (${PY3_IMPORT_RES} EQUAL 0)) + message(FATAL_ERROR "Cannot find Python 3 package `${pkg_name}`") + endif() - message(STATUS "Found Python 3 package `${pkg_name}`") + message(STATUS "Found Python 3 package `${pkg_name}`") endfunction() check_py3_pkg(CppHeaderParser) @@ -78,82 +86,76 @@ check_py3_pkg(yaml) find_program(BARECTF_RES barectf REQUIRED HINTS "$ENV{HOME}/.local/bin") # Generate barectf YAML and C++ files for HSA API. -get_property(HSA_RUNTIME_INCLUDE_DIRS - TARGET hsa-runtime64::hsa-runtime64 - PROPERTY INTERFACE_INCLUDE_DIRECTORIES) -find_file(HSA_H hsa.h - PATHS ${HSA_RUNTIME_INCLUDE_DIRS} - PATH_SUFFIXES hsa - NO_DEFAULT_PATH - REQUIRED) +get_property( + HSA_RUNTIME_INCLUDE_DIRS + TARGET hsa-runtime64::hsa-runtime64 + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +find_file( + HSA_H hsa.h + PATHS ${HSA_RUNTIME_INCLUDE_DIRS} + PATH_SUFFIXES hsa + NO_DEFAULT_PATH REQUIRED) get_filename_component(HSA_RUNTIME_INC_PATH "${HSA_H}" DIRECTORY) add_custom_command( - OUTPUT hsa_erts.yaml hsa_begin.cpp.i hsa_end.cpp.i - COMMAND ${CMAKE_C_COMPILER} -E "${HSA_RUNTIME_INC_PATH}/hsa.h" -o hsa.h.i - COMMAND ${CMAKE_C_COMPILER} -E "${HSA_RUNTIME_INC_PATH}/hsa_ext_amd.h" - -o hsa_ext_amd.h.i - COMMAND ${CMAKE_COMMAND} -E cat hsa.h.i - hsa_ext_amd.h.i - "${CMAKE_BINARY_DIR}/src/api/hsa_prof_str.h" - > hsa_input.h - COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_api_files.py" - hsa hsa_input.h - BYPRODUCTS hsa.h.i hsa_ext_amd.h.i hsa_input.h - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_api_files.py" - "${HSA_RUNTIME_INC_PATH}/hsa.h" - "${HSA_RUNTIME_INC_PATH}/hsa_ext_amd.h" - "${CMAKE_BINARY_DIR}/src/api/hsa_prof_str.h" - COMMENT "Generating HSA API files for the `ctf` plugin...") + OUTPUT hsa_erts.yaml hsa_begin.cpp.i hsa_end.cpp.i + COMMAND ${CMAKE_C_COMPILER} -E "${HSA_RUNTIME_INC_PATH}/hsa.h" -o hsa.h.i + COMMAND ${CMAKE_C_COMPILER} -E "${HSA_RUNTIME_INC_PATH}/hsa_ext_amd.h" -o + hsa_ext_amd.h.i + COMMAND ${CMAKE_COMMAND} -E cat hsa.h.i hsa_ext_amd.h.i + "${CMAKE_BINARY_DIR}/src/api/hsa_prof_str.h" > hsa_input.h + COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_api_files.py" hsa + hsa_input.h + BYPRODUCTS hsa.h.i hsa_ext_amd.h.i hsa_input.h + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_api_files.py" "${HSA_RUNTIME_INC_PATH}/hsa.h" + "${HSA_RUNTIME_INC_PATH}/hsa_ext_amd.h" + "${CMAKE_BINARY_DIR}/src/api/hsa_prof_str.h" + COMMENT "Generating HSA API files for the `ctf` plugin...") # Generate barectf YAML and C++ files for HIP API. -get_property(HIP_INCLUDE_DIRS TARGET hip::amdhip64 - PROPERTY INTERFACE_INCLUDE_DIRECTORIES) -find_file(HIP_RUNTIME_API_H hip_runtime_api.h - PATHS ${HIP_INCLUDE_DIRS} - PATH_SUFFIXES hip - NO_DEFAULT_PATH - REQUIRED) -find_file(HIP_PROF_STR_H hip_prof_str.h - PATHS ${HIP_INCLUDE_DIRS} - PATH_SUFFIXES hip hip/amd_detail - NO_DEFAULT_PATH - REQUIRED) +get_property( + HIP_INCLUDE_DIRS + TARGET hip::amdhip64 + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +find_file( + HIP_RUNTIME_API_H hip_runtime_api.h + PATHS ${HIP_INCLUDE_DIRS} + PATH_SUFFIXES hip + NO_DEFAULT_PATH REQUIRED) +find_file( + HIP_PROF_STR_H hip_prof_str.h + PATHS ${HIP_INCLUDE_DIRS} + PATH_SUFFIXES hip hip/amd_detail + NO_DEFAULT_PATH REQUIRED) list(TRANSFORM HIP_INCLUDE_DIRS PREPEND -I) add_custom_command( - OUTPUT hip_erts.yaml hip_begin.cpp.i hip_end.cpp.i - COMMAND ${CMAKE_C_COMPILER} ${HIP_INCLUDE_DIRS} - -E "${HIP_RUNTIME_API_H}" - -D__HIP_PLATFORM_HCC__=1 - -D__HIP_ROCclr__=1 - -o hip_runtime_api.h.i - COMMAND cat hip_runtime_api.h.i "${HIP_PROF_STR_H}" > hip_input.h - BYPRODUCTS hip_runtime_api.h.i hip_input.h - COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_api_files.py" - hip hip_input.h - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_api_files.py" - "${HIP_RUNTIME_API_H}" - "${HIP_PROF_STR_H}" - COMMENT "Generating HIP API files for the `ctf` plugin...") + OUTPUT hip_erts.yaml hip_begin.cpp.i hip_end.cpp.i + COMMAND ${CMAKE_C_COMPILER} ${HIP_INCLUDE_DIRS} -E "${HIP_RUNTIME_API_H}" + -D__HIP_PLATFORM_HCC__=1 -D__HIP_ROCclr__=1 -o hip_runtime_api.h.i + COMMAND cat hip_runtime_api.h.i "${HIP_PROF_STR_H}" > hip_input.h + BYPRODUCTS hip_runtime_api.h.i hip_input.h + COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_api_files.py" hip + hip_input.h + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_api_files.py" "${HIP_RUNTIME_API_H}" + "${HIP_PROF_STR_H}" + COMMENT "Generating HIP API files for the `ctf` plugin...") # Generate `env.yaml` (trace environment for barectf). add_custom_command( - OUTPUT env.yaml - COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_env_yaml.py" - ${PROJECT_VERSION} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_env_yaml.py" - COMMENT "Generating `env.yaml`...") + OUTPUT env.yaml + COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_env_yaml.py" + ${PROJECT_VERSION} + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gen_env_yaml.py" + COMMENT "Generating `env.yaml`...") # Generate raw CTF tracer with barectf. add_custom_command( - OUTPUT barectf.c barectf.h barectf-bitfield.h metadata - COMMAND "${BARECTF_RES}" gen "-I${CMAKE_CURRENT_BINARY_DIR}" - "-I${CMAKE_CURRENT_SOURCE_DIR}" - "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml" - DEPENDS hsa_erts.yaml - hip_erts.yaml - env.yaml - "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml" - "${CMAKE_CURRENT_SOURCE_DIR}/dst_base.yaml" - COMMENT "Generating raw CTF tracer with barectf...") -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/metadata" - DESTINATION "${METADATA_STREAM_FILE_DIR}" COMPONENT plugins) + OUTPUT barectf.c barectf.h barectf-bitfield.h metadata + COMMAND "${BARECTF_RES}" gen "-I${CMAKE_CURRENT_BINARY_DIR}" + "-I${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml" + DEPENDS hsa_erts.yaml hip_erts.yaml env.yaml "${CMAKE_CURRENT_SOURCE_DIR}/config.yaml" + "${CMAKE_CURRENT_SOURCE_DIR}/dst_base.yaml" + COMMENT "Generating raw CTF tracer with barectf...") +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/metadata" + DESTINATION "${METADATA_STREAM_FILE_DIR}" + COMPONENT plugins) diff --git a/projects/rocprofiler/plugin/ctf/plugin.cpp b/projects/rocprofiler/plugin/ctf/plugin.cpp index ba919154e3..df7923fa7b 100644 --- a/projects/rocprofiler/plugin/ctf/plugin.cpp +++ b/projects/rocprofiler/plugin/ctf/plugin.cpp @@ -156,9 +156,8 @@ class HsaApiEventRecord : public TracerEventRecord { const rocprofiler_session_id_t session_id, const std::uint64_t clock_val) : TracerEventRecord{record, clock_val} { - if(record.api_data.hsa) - api_data_ = *(record.api_data.hsa); - } + if (record.api_data.hsa) api_data_ = *(record.api_data.hsa); + } explicit HsaApiEventRecord(const rocprofiler_record_tracer_t& record, const std::uint64_t clock_val, hsa_api_data_t& api_data) : TracerEventRecord{record, clock_val}, api_data_(api_data) {} @@ -206,7 +205,7 @@ class HipApiEventRecord : public TracerEventRecord { const rocprofiler_session_id_t session_id, const std::uint64_t clock_val) : TracerEventRecord{record, clock_val}, - api_data_{record.api_data.hip? *(record.api_data.hip) : hip_api_data_t{}}, + api_data_{record.api_data.hip ? *(record.api_data.hip) : hip_api_data_t{}}, kernel_name_{record.name ? record.name : std::string{}} {} explicit HipApiEventRecord(const rocprofiler_record_tracer_t& record, const std::uint64_t clock_val, hip_api_data_t& api_data, @@ -760,16 +759,11 @@ std::uint64_t GetMetadataClkClsOffset() { static const char* LOOP_MPI_RANK(const std::vector& mpivars) { for (const char* env : mpivars) - if (const char* envvar = getenv(env)) - return envvar; + if (const char* envvar = getenv(env)) return envvar; return nullptr; } -static void insert_meta_to_stream( - std::stringstream& stream, - const char* field, - const char* value -) { +static void insert_meta_to_stream(std::stringstream& stream, const char* field, const char* value) { if (!field || !value) return; stream << "\n\t" << std::string(field) << " = " << std::string(value) << ';'; } @@ -802,7 +796,7 @@ void Plugin::CopyAdjustedMetadataStreamFile(const fs::path& metadata_stream_path std::string data_ins = data_stream.str(); size_t env_pos = metadata.find("env {"); if (env_pos != std::string::npos) - metadata.insert(metadata.begin()+env_pos+5, data_ins.begin(), data_ins.end()); + metadata.insert(metadata.begin() + env_pos + 5, data_ins.begin(), data_ins.end()); else std::cerr << "Failed to insert MPI metadata!" << std::endl; } diff --git a/projects/rocprofiler/plugin/file/CMakeLists.txt b/projects/rocprofiler/plugin/file/CMakeLists.txt index 62243d1644..2eb52c6fa4 100644 --- a/projects/rocprofiler/plugin/file/CMakeLists.txt +++ b/projects/rocprofiler/plugin/file/CMakeLists.txt @@ -25,23 +25,25 @@ file(GLOB ROCPROFILER_UTIL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/utils/helper.cpp) file(GLOB FILE_SOURCES "*.cpp") add_library(file_plugin SHARED ${FILE_SOURCES} ${ROCPROFILER_UTIL_SRC_FILES}) -set_target_properties(file_plugin PROPERTIES - CXX_VISIBILITY_PRESET hidden - LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../exportmap - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rocprofiler) +set_target_properties( + file_plugin + PROPERTIES CXX_VISIBILITY_PRESET hidden + LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../exportmap + LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rocprofiler) -target_compile_definitions(file_plugin - PRIVATE HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_HCC__=1) +target_compile_definitions(file_plugin PRIVATE HIP_PROF_HIP_API_STRING=1 + __HIP_PLATFORM_HCC__=1) target_include_directories(file_plugin PRIVATE ${PROJECT_SOURCE_DIR}) -target_link_options(file_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap -Wl,--no-undefined) +target_link_options( + file_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap + -Wl,--no-undefined) -target_link_libraries(file_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 stdc++fs amd_comgr dl) +target_link_libraries(file_plugin PRIVATE rocprofiler-v2 hsa-runtime64::hsa-runtime64 + stdc++fs amd_comgr dl) -install(TARGETS file_plugin LIBRARY - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} - COMPONENT asan) -install(TARGETS file_plugin LIBRARY - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} - COMPONENT runtime) +install(TARGETS file_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} + COMPONENT asan) +install(TARGETS file_plugin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} + COMPONENT runtime) diff --git a/projects/rocprofiler/plugin/file/file.cpp b/projects/rocprofiler/plugin/file/file.cpp index 4efda06bd2..145c471445 100644 --- a/projects/rocprofiler/plugin/file/file.cpp +++ b/projects/rocprofiler/plugin/file/file.cpp @@ -216,8 +216,7 @@ class file_plugin_t { case ACTIVITY_DOMAIN_HIP_API: { if (hip_api_header_written_.load(std::memory_order_relaxed)) return; output_file = get_output_file(output_type_t::TRACER, ACTIVITY_DOMAIN_HIP_API); - *output_file << "Domain,Function,Start_Timestamp,End_Timestamp,Correlation_ID" - << std::endl; + *output_file << "Domain,Function,Start_Timestamp,End_Timestamp,Correlation_ID" << std::endl; *output_file << std::endl; hip_api_header_written_.exchange(true, std::memory_order_release); return; diff --git a/projects/rocprofiler/plugin/perfetto/CMakeLists.txt b/projects/rocprofiler/plugin/perfetto/CMakeLists.txt index 5d97cdd8dc..55f95f5549 100644 --- a/projects/rocprofiler/plugin/perfetto/CMakeLists.txt +++ b/projects/rocprofiler/plugin/perfetto/CMakeLists.txt @@ -1,27 +1,27 @@ file(GLOB ROCPROFILER_UTIL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/utils/helper.cpp) -add_library(perfetto_plugin - ${LIBRARY_TYPE} ${ROCPROFILER_UTIL_SRC_FILES} - perfetto.cpp perfetto_sdk/sdk/perfetto.cc) +add_library(perfetto_plugin ${LIBRARY_TYPE} ${ROCPROFILER_UTIL_SRC_FILES} perfetto.cpp + perfetto_sdk/sdk/perfetto.cc) -set_target_properties(perfetto_plugin PROPERTIES - CXX_VISIBILITY_PRESET hidden - LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../exportmap - LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rocprofiler) +set_target_properties( + perfetto_plugin + PROPERTIES CXX_VISIBILITY_PRESET hidden + LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../exportmap + LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rocprofiler) -target_compile_definitions(perfetto_plugin - PRIVATE HIP_PROF_HIP_API_STRING=1 - __HIP_PLATFORM_HCC__=1) +target_compile_definitions(perfetto_plugin PRIVATE HIP_PROF_HIP_API_STRING=1 + __HIP_PLATFORM_HCC__=1) -target_include_directories(perfetto_plugin - PRIVATE ${PROJECT_SOURCE_DIR} - ${PROJECT_SOURCE_DIR}/plugin/perfetto/perfetto_sdk/sdk) +target_include_directories( + perfetto_plugin PRIVATE ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/plugin/perfetto/perfetto_sdk/sdk) -target_link_options(perfetto_plugin - PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap -Wl,--no-undefined) +target_link_options( + perfetto_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap + -Wl,--no-undefined) -target_link_libraries(perfetto_plugin PRIVATE rocprofiler-v2 Threads::Threads stdc++fs amd_comgr) +target_link_libraries(perfetto_plugin PRIVATE rocprofiler-v2 Threads::Threads stdc++fs + amd_comgr) -install(TARGETS perfetto_plugin LIBRARY - DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} - COMPONENT plugins) \ No newline at end of file +install(TARGETS perfetto_plugin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} COMPONENT plugins) diff --git a/projects/rocprofiler/plugin/perfetto/perfetto.cpp b/projects/rocprofiler/plugin/perfetto/perfetto.cpp index 140dab9a00..cb2053c91d 100644 --- a/projects/rocprofiler/plugin/perfetto/perfetto.cpp +++ b/projects/rocprofiler/plugin/perfetto/perfetto.cpp @@ -556,8 +556,7 @@ class perfetto_plugin_t { if (tracer_record.name) { kernel_name = rocprofiler::cxx_demangle(tracer_record.name); TRACE_EVENT_BEGIN( - "HIP_OPS", - perfetto::StaticString(rocprofiler::truncate_name(kernel_name).c_str()), + "HIP_OPS", perfetto::StaticString(rocprofiler::truncate_name(kernel_name).c_str()), gpu_track, tracer_record.timestamps.begin.value, "Agent ID", tracer_record.agent_id.handle, "Process ID", GetPid(), "Kernel Name", kernel_name, perfetto::Flow::ProcessScoped(tracer_record.correlation_id.value)); diff --git a/projects/rocprofiler/plugin/perfetto/perfetto_sdk/sdk/perfetto.cc b/projects/rocprofiler/plugin/perfetto/perfetto_sdk/sdk/perfetto.cc index 9a07ce4a35..9ece1fb2cd 100644 --- a/projects/rocprofiler/plugin/perfetto/perfetto_sdk/sdk/perfetto.cc +++ b/projects/rocprofiler/plugin/perfetto/perfetto_sdk/sdk/perfetto.cc @@ -239,17 +239,14 @@ class Hasher { Hasher() {} // Hashes a numeric value. - template < - typename T, - typename std::enable_if::value, bool>::type = true> + template ::value, bool>::type = true> void Update(T data) { Update(reinterpret_cast(&data), sizeof(data)); } // Using the loop instead of "Update(str, strlen(str))" to avoid looping twice void Update(const char* str) { - for (const auto* p = str; *p; ++p) - Update(*p); + for (const auto* p = str; *p; ++p) Update(*p); } // Hashes a byte array. @@ -265,8 +262,7 @@ class Hasher { // Allow hashing anything that has a |data| field, a |size| field, // and has the kHashable trait (e.g., base::StringView). - template > - void Update(const T& t) { + template > void Update(const T& t) { Update(t.data(), t.size()); } @@ -276,8 +272,7 @@ class Hasher { // Usage: // uint64_t hashed_value = Hash::Combine(33, false, "ABC", 458L, 3u, 'x'); - template - static uint64_t Combine(Ts&&... args) { + template static uint64_t Combine(Ts&&... args) { Hasher hasher; hasher.UpdateAll(std::forward(args)...); return hasher.digest(); @@ -287,8 +282,7 @@ class Hasher { // `hasher.Update(33); hasher.Update(false); hasher.Update("ABC");` void UpdateAll() {} - template - void UpdateAll(T&& arg, Ts&&... args) { + template void UpdateAll(T&& arg, Ts&&... args) { Update(arg); UpdateAll(std::forward(args)...); } @@ -303,8 +297,7 @@ class Hasher { // This is for using already-hashed key into std::unordered_map and avoid the // cost of re-hashing. Example: // unordered_map my_map. -template -struct AlreadyHashed { +template struct AlreadyHashed { size_t operator()(const T& x) const { return static_cast(x); } }; @@ -313,13 +306,11 @@ struct AlreadyHashed { // identity function and Perfetto uses open-addressing hash table, which are // very sensitive to hash quality and are known to degrade in performance // when using std::hash. -template -struct Hash { +template struct Hash { // Version for ints, using base::Hasher. template auto operator()(const U& x) -> - typename std::enable_if::value, size_t>::type - const { + typename std::enable_if::value, size_t>::type const { Hasher hash; hash.Update(x); return static_cast(hash.digest()); @@ -328,8 +319,7 @@ struct Hash { // Version for non-ints, falling back to std::hash. template auto operator()(const U& x) -> - typename std::enable_if::value, size_t>::type - const { + typename std::enable_if::value, size_t>::type const { return std::hash()(x); } }; @@ -399,8 +389,7 @@ class StringView { // This instead has to be explicit, as creating a StringView out of a // std::string can be subtle. - explicit StringView(const std::string& str) - : data_(str.data()), size_(str.size()) {} + explicit StringView(const std::string& str) : data_(str.data()), size_(str.size()) {} bool empty() const { return size_ == 0; } size_t size() const { return size_; } @@ -415,15 +404,13 @@ class StringView { size_t find(char c, size_t start_pos = 0) const { for (size_t i = start_pos; i < size_; ++i) { - if (data_[i] == c) - return i; + if (data_[i] == c) return i; } return npos; } size_t find(const StringView& str, size_t start_pos = 0) const { - if (start_pos > size()) - return npos; + if (start_pos > size()) return npos; auto it = std::search(begin() + start_pos, end(), str.begin(), str.end()); size_t pos = static_cast(it - begin()); return pos + str.size() <= size() ? pos : npos; @@ -435,24 +422,20 @@ class StringView { size_t rfind(char c) const { for (size_t i = size_; i > 0; --i) { - if (data_[i - 1] == c) - return i - 1; + if (data_[i - 1] == c) return i - 1; } return npos; } StringView substr(size_t pos, size_t count = npos) const { - if (pos >= size_) - return StringView("", 0); + if (pos >= size_) return StringView("", 0); size_t rcount = std::min(count, size_ - pos); return StringView(data_ + pos, rcount); } bool CaseInsensitiveEq(const StringView& other) const { - if (size() != other.size()) - return false; - if (size() == 0) - return true; + if (size() != other.size()) return false; + if (size() == 0) return true; #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) return _strnicmp(data(), other.data(), size()) == 0; #else @@ -461,29 +444,21 @@ class StringView { } bool StartsWith(const StringView& other) const { - if (other.size() == 0) - return true; - if (size() == 0) - return false; - if (other.size() > size()) - return false; + if (other.size() == 0) return true; + if (size() == 0) return false; + if (other.size() > size()) return false; return memcmp(data(), other.data(), other.size()) == 0; } bool EndsWith(const StringView& other) const { - if (other.size() == 0) - return true; - if (size() == 0) - return false; - if (other.size() > size()) - return false; + if (other.size() == 0) return true; + if (size() == 0) return false; + if (other.size() > size()) return false; size_t off = size() - other.size(); return memcmp(data() + off, other.data(), other.size()) == 0; } - std::string ToStdString() const { - return size_ == 0 ? "" : std::string(data_, size_); - } + std::string ToStdString() const { return size_ == 0 ? "" : std::string(data_, size_); } uint64_t Hash() const { base::Hasher hasher; @@ -497,42 +472,30 @@ class StringView { }; inline bool operator==(const StringView& x, const StringView& y) { - if (x.size() != y.size()) - return false; - if (x.size() == 0) - return true; + if (x.size() != y.size()) return false; + if (x.size() == 0) return true; return memcmp(x.data(), y.data(), x.size()) == 0; } -inline bool operator!=(const StringView& x, const StringView& y) { - return !(x == y); -} +inline bool operator!=(const StringView& x, const StringView& y) { return !(x == y); } inline bool operator<(const StringView& x, const StringView& y) { auto size = std::min(x.size(), y.size()); - if (size == 0) - return x.size() < y.size(); + if (size == 0) return x.size() < y.size(); int result = memcmp(x.data(), y.data(), size); return result < 0 || (result == 0 && x.size() < y.size()); } -inline bool operator>=(const StringView& x, const StringView& y) { - return !(x < y); -} +inline bool operator>=(const StringView& x, const StringView& y) { return !(x < y); } -inline bool operator>(const StringView& x, const StringView& y) { - return y < x; -} +inline bool operator>(const StringView& x, const StringView& y) { return y < x; } -inline bool operator<=(const StringView& x, const StringView& y) { - return !(y < x); -} +inline bool operator<=(const StringView& x, const StringView& y) { return !(y < x); } } // namespace base } // namespace perfetto -template <> -struct std::hash<::perfetto::base::StringView> { +template <> struct std::hash<::perfetto::base::StringView> { size_t operator()(const ::perfetto::base::StringView& sv) const { return static_cast(sv.Hash()); } @@ -632,13 +595,13 @@ constexpr pid_t kInvalidPid = static_cast(-1); // Chromium does the same. #define PERFETTO_EINTR(x) (x) #else -#define PERFETTO_EINTR(x) \ - ([&] { \ - decltype(x) eintr_wrapper_result; \ - do { \ - eintr_wrapper_result = (x); \ - } while (eintr_wrapper_result == -1 && errno == EINTR); \ - return eintr_wrapper_result; \ +#define PERFETTO_EINTR(x) \ + ([&] { \ + decltype(x) eintr_wrapper_result; \ + do { \ + eintr_wrapper_result = (x); \ + } while (eintr_wrapper_result == -1 && errno == EINTR); \ + return eintr_wrapper_result; \ }()) #endif @@ -657,10 +620,7 @@ constexpr size_t kPageSize = 4096; // similar mm-related syscalls. uint32_t GetSysPageSize(); -template -constexpr size_t ArraySize(const T (&)[TSize]) { - return TSize; -} +template constexpr size_t ArraySize(const T (&)[TSize]) { return TSize; } // Function object which invokes 'free' on its parameter, which must be // a pointer. Can be used to store malloc-allocated pointers in std::unique_ptr: @@ -671,8 +631,7 @@ struct FreeDeleter { inline void operator()(void* ptr) const { free(ptr); } }; -template -constexpr T AssumeLittleEndian(T value) { +template constexpr T AssumeLittleEndian(T value) { #if !PERFETTO_IS_LITTLE_ENDIAN() static_assert(false, "Unimplemented on big-endian archs"); #endif @@ -680,15 +639,12 @@ constexpr T AssumeLittleEndian(T value) { } // Round up |size| to a multiple of |alignment| (must be a power of two). -template -constexpr size_t AlignUp(size_t size) { +template constexpr size_t AlignUp(size_t size) { static_assert((alignment & (alignment - 1)) == 0, "alignment must be a pow2"); return (size + alignment - 1) & ~(alignment - 1); } -inline bool IsAgain(int err) { - return err == EAGAIN || err == EWOULDBLOCK; -} +inline bool IsAgain(int err) { return err == EAGAIN || err == EWOULDBLOCK; } // setenv(2)-equivalent. Deals with Windows vs Posix discrepancies. void SetEnv(const std::string& key, const std::string& value); @@ -725,8 +681,7 @@ void* AlignedAlloc(size_t alignment, size_t size); void AlignedFree(void*); // A RAII version of the above, which takes care of pairing Aligned{Alloc,Free}. -template -struct AlignedDeleter { +template struct AlignedDeleter { inline void operator()(T* ptr) const { AlignedFree(ptr); } }; @@ -734,19 +689,15 @@ struct AlignedDeleter { // As per https://en.cppreference.com/w/cpp/memory/unique_ptr the Deleter takes // always a T*, not a T[]*. template -using AlignedUniquePtr = - std::unique_ptr::type>>; +using AlignedUniquePtr = std::unique_ptr::type>>; -template -AlignedUniquePtr AlignedAllocTyped(size_t n_membs) { +template AlignedUniquePtr AlignedAllocTyped(size_t n_membs) { using TU = typename std::remove_extent::type; - return AlignedUniquePtr( - static_cast(AlignedAlloc(alignof(TU), sizeof(TU) * n_membs))); + return AlignedUniquePtr(static_cast(AlignedAlloc(alignof(TU), sizeof(TU) * n_membs))); } // A RAII wrapper to invoke a function when leaving a function/scope. -template -class OnScopeExitWrapper { +template class OnScopeExitWrapper { public: explicit OnScopeExitWrapper(Func f) : f_(std::move(f)), active_(true) {} OnScopeExitWrapper(OnScopeExitWrapper&& other) noexcept @@ -754,8 +705,7 @@ class OnScopeExitWrapper { other.active_ = false; } ~OnScopeExitWrapper() { - if (active_) - f_(); + if (active_) f_(); } private: @@ -763,15 +713,13 @@ class OnScopeExitWrapper { bool active_; }; -template -PERFETTO_WARN_UNUSED_RESULT OnScopeExitWrapper OnScopeExit(Func f) { +template PERFETTO_WARN_UNUSED_RESULT OnScopeExitWrapper OnScopeExit(Func f) { return OnScopeExitWrapper(std::move(f)); } // Returns a xxd-style hex dump (hex + ascii chars) of the input data. std::string HexDump(const void* data, size_t len, size_t bytes_per_line = 16); -inline std::string HexDump(const std::string& data, - size_t bytes_per_line = 16) { +inline std::string HexDump(const std::string& data, size_t bytes_per_line = 16) { return HexDump(data.data(), data.size(), bytes_per_line); } @@ -809,33 +757,21 @@ namespace base { // Returns the length of the destination string (included '=' padding). // Does NOT include the size of the string null terminator. -inline size_t Base64EncSize(size_t src_size) { - return (src_size + 2) / 3 * 4; -} +inline size_t Base64EncSize(size_t src_size) { return (src_size + 2) / 3 * 4; } // Returns the upper bound on the length of the destination buffer. // The actual decoded length might be <= the number returned here. -inline size_t Base64DecSize(size_t src_size) { - return (src_size + 3) / 4 * 3; -} +inline size_t Base64DecSize(size_t src_size) { return (src_size + 3) / 4 * 3; } // Does NOT null-terminate |dst|. -ssize_t Base64Encode(const void* src, - size_t src_size, - char* dst, - size_t dst_size); +ssize_t Base64Encode(const void* src, size_t src_size, char* dst, size_t dst_size); std::string Base64Encode(const void* src, size_t src_size); -inline std::string Base64Encode(StringView sv) { - return Base64Encode(sv.data(), sv.size()); -} +inline std::string Base64Encode(StringView sv) { return Base64Encode(sv.data(), sv.size()); } // Returns -1 in case of failure. -ssize_t Base64Decode(const char* src, - size_t src_size, - uint8_t* dst, - size_t dst_size); +ssize_t Base64Decode(const char* src, size_t src_size, uint8_t* dst, size_t dst_size); std::optional Base64Decode(const char* src, size_t src_size); @@ -872,8 +808,7 @@ namespace { constexpr char kPadding = '='; -constexpr char kEncTable[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +constexpr char kEncTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static_assert(sizeof(kEncTable) == (1u << 6) + sizeof('\0'), "Bad table size"); // Maps an ASCII character to its 6-bit value. It only contains translations @@ -894,20 +829,15 @@ constexpr char kMaxDecChar = 'z'; static_assert(kMaxDecChar - kMinDecChar <= sizeof(kDecTable), "Bad table size"); inline uint8_t DecodeChar(char c) { - if (c < kMinDecChar || c > kMaxDecChar) - return kX; + if (c < kMinDecChar || c > kMaxDecChar) return kX; return kDecTable[c - kMinDecChar]; } } // namespace -ssize_t Base64Encode(const void* src, - size_t src_size, - char* dst, - size_t dst_size) { +ssize_t Base64Encode(const void* src, size_t src_size, char* dst, size_t dst_size) { const size_t padded_dst_size = Base64EncSize(src_size); - if (dst_size < padded_dst_size) - return -1; // Not enough space in output. + if (dst_size < padded_dst_size) return -1; // Not enough space in output. const uint8_t* rd = static_cast(src); const uint8_t* const end = rd + src_size; @@ -952,13 +882,9 @@ std::string Base64Encode(const void* src, size_t src_size) { return dst; } -ssize_t Base64Decode(const char* src, - size_t src_size, - uint8_t* dst, - size_t dst_size) { +ssize_t Base64Decode(const char* src, size_t src_size, uint8_t* dst, size_t dst_size) { const size_t min_dst_size = Base64DecSize(src_size); - if (dst_size < min_dst_size) - return -1; + if (dst_size < min_dst_size) return -1; const char* rd = src; const char* const end = src + src_size; @@ -971,8 +897,7 @@ ssize_t Base64Decode(const char* src, // Padding is only feasible for the last 2 chars of each group of 4. s[j] = rd < end ? *(rd++) : (j < 2 ? '\0' : kPadding); d[j] = DecodeChar(s[j]); - if (d[j] == kX) - return -1; // Invalid input char. + if (d[j] == kX) return -1; // Invalid input char. } dst[wr_size] = static_cast((d[0] << 2) | (d[1] >> 4)); dst[wr_size + 1] = static_cast((d[1] << 4) | (d[2] >> 2)); @@ -988,10 +913,8 @@ ssize_t Base64Decode(const char* src, std::optional Base64Decode(const char* src, size_t src_size) { std::string dst; dst.resize(Base64DecSize(src_size)); - auto res = Base64Decode(src, src_size, reinterpret_cast(&dst[0]), - dst.size()); - if (res < 0) - return std::nullopt; // Decoding error. + auto res = Base64Decode(src, src_size, reinterpret_cast(&dst[0]), dst.size()); + if (res < 0) return std::nullopt; // Decoding error. PERFETTO_CHECK(res <= static_cast(dst.size())); dst.resize(static_cast(res)); @@ -1077,15 +1000,12 @@ class CrashKey { public: explicit ScopedClear(CrashKey* k) : key_(k) {} ~ScopedClear() { - if (key_) - key_->Clear(); + if (key_) key_->Clear(); } ScopedClear(const ScopedClear&) = delete; ScopedClear& operator=(const ScopedClear&) = delete; ScopedClear& operator=(ScopedClear&&) = delete; - ScopedClear(ScopedClear&& other) noexcept : key_(other.key_) { - other.key_ = nullptr; - } + ScopedClear(ScopedClear&& other) noexcept : key_(other.key_) { other.key_ = nullptr; } private: CrashKey* key_; @@ -1111,18 +1031,15 @@ class CrashKey { void Set(int64_t value) { int_value_.store(value, std::memory_order_relaxed); type_.store(Type::kInt, std::memory_order_relaxed); - if (PERFETTO_UNLIKELY(!registered_.load(std::memory_order_relaxed))) - Register(); + if (PERFETTO_UNLIKELY(!registered_.load(std::memory_order_relaxed))) Register(); } void Set(StringView sv) { size_t len = std::min(sv.size(), sizeof(str_value_) - 1); - for (size_t i = 0; i < len; ++i) - str_value_[i].store(sv.data()[i], std::memory_order_relaxed); + for (size_t i = 0; i < len; ++i) str_value_[i].store(sv.data()[i], std::memory_order_relaxed); str_value_[len].store('\0', std::memory_order_relaxed); type_.store(Type::kStr, std::memory_order_relaxed); - if (PERFETTO_UNLIKELY(!registered_.load(std::memory_order_relaxed))) - Register(); + if (PERFETTO_UNLIKELY(!registered_.load(std::memory_order_relaxed))) Register(); } ScopedClear SetScoped(int64_t value) PERFETTO_WARN_UNUSED_RESULT { @@ -1137,9 +1054,7 @@ class CrashKey { void Register(); - int64_t int_value() const { - return int_value_.load(std::memory_order_relaxed); - } + int64_t int_value() const { return int_value_.load(std::memory_order_relaxed); } size_t ToString(char* dst, size_t len); private: @@ -1237,28 +1152,23 @@ inline std::optional CStringToDouble(const char* s) { char* endptr = nullptr; double value = StrToD(s, &endptr); std::optional result(std::nullopt); - if (*s != '\0' && *endptr == '\0') - result = value; + if (*s != '\0' && *endptr == '\0') result = value; return result; } -inline std::optional StringToUInt32(const std::string& s, - int base = 10) { +inline std::optional StringToUInt32(const std::string& s, int base = 10) { return CStringToUInt32(s.c_str(), base); } -inline std::optional StringToInt32(const std::string& s, - int base = 10) { +inline std::optional StringToInt32(const std::string& s, int base = 10) { return CStringToInt32(s.c_str(), base); } -inline std::optional StringToUInt64(const std::string& s, - int base = 10) { +inline std::optional StringToUInt64(const std::string& s, int base = 10) { return CStringToUInt64(s.c_str(), base); } -inline std::optional StringToInt64(const std::string& s, - int base = 10) { +inline std::optional StringToInt64(const std::string& s, int base = 10) { return CStringToInt64(s.c_str(), base); } @@ -1268,33 +1178,25 @@ inline std::optional StringToDouble(const std::string& s) { bool StartsWith(const std::string& str, const std::string& prefix); bool EndsWith(const std::string& str, const std::string& suffix); -bool StartsWithAny(const std::string& str, - const std::vector& prefixes); +bool StartsWithAny(const std::string& str, const std::vector& prefixes); bool Contains(const std::string& haystack, const std::string& needle); bool Contains(const std::string& haystack, char needle); size_t Find(const StringView& needle, const StringView& haystack); bool CaseInsensitiveEqual(const std::string& first, const std::string& second); -std::string Join(const std::vector& parts, - const std::string& delim); -std::vector SplitString(const std::string& text, - const std::string& delimiter); +std::string Join(const std::vector& parts, const std::string& delim); +std::vector SplitString(const std::string& text, const std::string& delimiter); std::string StripPrefix(const std::string& str, const std::string& prefix); std::string StripSuffix(const std::string& str, const std::string& suffix); std::string TrimWhitespace(const std::string& str); std::string ToLower(const std::string& str); std::string ToUpper(const std::string& str); -std::string StripChars(const std::string& str, - const std::string& chars, - char replacement); +std::string StripChars(const std::string& str, const std::string& chars, char replacement); std::string ToHex(const char* data, size_t size); -inline std::string ToHex(const std::string& s) { - return ToHex(s.c_str(), s.size()); -} +inline std::string ToHex(const std::string& s) { return ToHex(s.c_str(), s.size()); } std::string IntToHexString(uint32_t number); std::string Uint64ToHexString(uint64_t number); std::string Uint64ToHexStringNoPrefix(uint64_t number); -std::string ReplaceAll(std::string str, - const std::string& to_replace, +std::string ReplaceAll(std::string str, const std::string& to_replace, const std::string& replacement); // A BSD-style strlcpy without the return value. @@ -1315,8 +1217,7 @@ inline void StringCopy(char* dst, const char* src, size_t dst_size) { } // We were left off at dst_size. We over copied 1 byte. Null terminate. - if (PERFETTO_LIKELY(dst_size > 0)) - dst[dst_size - 1] = 0; + if (PERFETTO_LIKELY(dst_size > 0)) dst[dst_size - 1] = 0; } // Like snprintf() but returns the number of chars *actually* written (without @@ -1336,8 +1237,7 @@ inline void StringCopy(char* dst, const char* src, size_t dst_size) { // SprintfTrunc(x, 0, "123"): returns 0 and writes nothing. // NOTE: This means that the caller has no way to tell when truncation happens // vs the edge case of *just* fitting in the buffer. -size_t SprintfTrunc(char* dst, size_t dst_size, const char* fmt, ...) - PERFETTO_PRINTF_FORMAT(3, 4); +size_t SprintfTrunc(char* dst, size_t dst_size, const char* fmt, ...) PERFETTO_PRINTF_FORMAT(3, 4); // Line number starts from 1 struct LineWithOffset { @@ -1350,8 +1250,7 @@ struct LineWithOffset { // which offset points, what number is this line (starts from 1), and the offset // inside this line. returns std::nullopt if the offset points to // line break character or exceeds string length. -std::optional FindLineWithOffset(base::StringView str, - uint32_t offset); +std::optional FindLineWithOffset(base::StringView str, uint32_t offset); // A helper class to facilitate construction and usage of write-once stack // strings. @@ -1364,11 +1263,9 @@ std::optional FindLineWithOffset(base::StringView str, // by fearing unknown snprintf failure modes). // - Makes the code more robust in case of snprintf truncations (len() and // string_view() will return the truncated length, unlike snprintf). -template -class StackString { +template class StackString { public: - explicit PERFETTO_PRINTF_FORMAT(/* 1=this */ 2, 3) - StackString(const char* fmt, ...) { + explicit PERFETTO_PRINTF_FORMAT(/* 1=this */ 2, 3) StackString(const char* fmt, ...) { buf_[0] = '\0'; va_list args; va_start(args, fmt); @@ -1434,8 +1331,7 @@ void CrashKey::Register() { // keep trying re-registering on every Set(), the outcome won't change. // If two threads raced on the Register(), avoid registering the key twice. - if (registered_.exchange(true)) - return; + if (registered_.exchange(true)) return; uint32_t slot = g_num_keys.fetch_add(1); if (slot >= kMaxKeys) { @@ -1447,8 +1343,7 @@ void CrashKey::Register() { // Returns the number of chars written, without counting the \0. size_t CrashKey::ToString(char* dst, size_t len) { - if (len > 0) - *dst = '\0'; + if (len > 0) *dst = '\0'; switch (type_.load(std::memory_order_relaxed)) { case Type::kUnset: break; @@ -1468,19 +1363,16 @@ size_t CrashKey::ToString(char* dst, size_t len) { void UnregisterAllCrashKeysForTesting() { g_num_keys.store(0); - for (auto& key : g_keys) - key.store(nullptr); + for (auto& key : g_keys) key.store(nullptr); } size_t SerializeCrashKeys(char* dst, size_t len) { size_t written = 0; uint32_t num_keys = g_num_keys.load(); - if (len > 0) - *dst = '\0'; + if (len > 0) *dst = '\0'; for (uint32_t i = 0; i < num_keys && written < len; i++) { CrashKey* key = g_keys[i].load(); - if (!key) - continue; // Can happen if we hit this between the add and the store. + if (!key) continue; // Can happen if we hit this between the add and the store. written += key->ToString(dst + written, len - written); } PERFETTO_DCHECK(written <= len); @@ -1574,8 +1466,7 @@ void InstallCtrlCHandler(CtrlCHandlerFunction handler) { return false; }; ::SetConsoleCtrlHandler(trampoline, true); -#elif PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \ - PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) || \ +#elif PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) || \ PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE) // Setup signal handler. struct sigaction sa {}; @@ -1702,8 +1593,7 @@ namespace base { namespace internal { // Used for the most common cases of ScopedResource where there is only one // invalid value. -template -struct DefaultValidityChecker { +template struct DefaultValidityChecker { static bool IsValid(T t) { return t != InvalidValue; } }; } // namespace internal @@ -1711,10 +1601,7 @@ struct DefaultValidityChecker { // RAII classes for auto-releasing fds and dirs. // if T is a pointer type, InvalidValue must be nullptr. Doing otherwise // causes weird unexpected behaviors (See https://godbolt.org/z/5nGMW4). -template > class ScopedResource { public: @@ -1737,8 +1624,7 @@ class ScopedResource { void reset(T r = InvalidValue) { if (Checker::IsValid(t_)) { int res = CloseFunction(t_); - if (CheckClose) - PERFETTO_CHECK(res == 0); + if (CheckClose) PERFETTO_CHECK(res == 0); } t_ = r; } @@ -1765,11 +1651,9 @@ using ScopedFstream = ScopedResource; // Use this for resources that are HANDLE on Windows. See comments in // platform_handle.h #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) -using ScopedPlatformHandle = ScopedResource; + /*CheckClose=*/true, PlatformHandleChecker>; #else // On non-windows systems we alias ScopedPlatformHandle to ScopedFile because // they are really the same. This is to allow assignments between the two in @@ -1836,8 +1720,7 @@ class EventFd { // the pipe for fallback mode. ScopedPlatformHandle event_handle_; -#if !PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) && \ - !PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) && \ +#if !PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) && !PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) && \ !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) // On Mac and other non-Linux UNIX platforms a pipe-based fallback is used. // The write end of the wakeup pipe. @@ -1924,8 +1807,7 @@ class Pipe { #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) #include #include -#elif PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \ - PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) +#elif PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) #include #include #else // Mac, Fuchsia and other non-Linux UNIXes @@ -1944,9 +1826,8 @@ EventFd::~EventFd() = default; #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) EventFd::EventFd() { - event_handle_.reset( - CreateEventA(/*lpEventAttributes=*/nullptr, /*bManualReset=*/true, - /*bInitialState=*/false, /*bInitialState=*/nullptr)); + event_handle_.reset(CreateEventA(/*lpEventAttributes=*/nullptr, /*bManualReset=*/true, + /*bInitialState=*/false, /*bInitialState=*/nullptr)); } void EventFd::Notify() { @@ -1959,8 +1840,7 @@ void EventFd::Clear() { PERFETTO_DFATAL("EventFd::Clear()"); } -#elif PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \ - PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) +#elif PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) EventFd::EventFd() { event_handle_.reset(eventfd(/*initval=*/0, EFD_CLOEXEC | EFD_NONBLOCK)); @@ -1970,16 +1850,13 @@ EventFd::EventFd() { void EventFd::Notify() { const uint64_t value = 1; ssize_t ret = write(event_handle_.get(), &value, sizeof(value)); - if (ret <= 0 && errno != EAGAIN) - PERFETTO_DFATAL("EventFd::Notify()"); + if (ret <= 0 && errno != EAGAIN) PERFETTO_DFATAL("EventFd::Notify()"); } void EventFd::Clear() { uint64_t value; - ssize_t ret = - PERFETTO_EINTR(read(event_handle_.get(), &value, sizeof(value))); - if (ret <= 0 && errno != EAGAIN) - PERFETTO_DFATAL("EventFd::Clear()"); + ssize_t ret = PERFETTO_EINTR(read(event_handle_.get(), &value, sizeof(value))); + if (ret <= 0 && errno != EAGAIN) PERFETTO_DFATAL("EventFd::Clear()"); } #else @@ -1995,18 +1872,15 @@ EventFd::EventFd() { void EventFd::Notify() { const uint64_t value = 1; ssize_t ret = write(write_fd_.get(), &value, sizeof(uint8_t)); - if (ret <= 0 && errno != EAGAIN) - PERFETTO_DFATAL("EventFd::Notify()"); + if (ret <= 0 && errno != EAGAIN) PERFETTO_DFATAL("EventFd::Notify()"); } void EventFd::Clear() { // Drain the byte(s) written to the wake-up pipe. We can potentially read // more than one byte if several wake-ups have been scheduled. char buffer[16]; - ssize_t ret = - PERFETTO_EINTR(read(event_handle_.get(), &buffer[0], sizeof(buffer))); - if (ret <= 0 && errno != EAGAIN) - PERFETTO_DFATAL("EventFd::Clear()"); + ssize_t ret = PERFETTO_EINTR(read(event_handle_.get(), &buffer[0], sizeof(buffer))); + if (ret <= 0 && errno != EAGAIN) PERFETTO_DFATAL("EventFd::Clear()"); } #endif @@ -2075,9 +1949,7 @@ class PERFETTO_EXPORT_COMPONENT Status { }; // Returns a status object which represents the Ok status. -inline Status OkStatus() { - return Status(); -} +inline Status OkStatus() { return Status(); } PERFETTO_PRINTF_FORMAT(1, 2) Status ErrStatus(const char* format, ...); @@ -2147,9 +2019,7 @@ ssize_t WriteAll(int fd, const void* buf, size_t count); ssize_t WriteAllHandle(PlatformHandle, const void* buf, size_t count); -ScopedFile OpenFile(const std::string& path, - int flags, - FileOpenMode = kFileModeInvalid); +ScopedFile OpenFile(const std::string& path, int flags, FileOpenMode = kFileModeInvalid); ScopedFstream OpenFstream(const char* path, const char* mode); // This is an alias for close(). It's to avoid leaking Windows.h in headers. @@ -2177,8 +2047,7 @@ std::string GetFileExtension(const std::string& filename); // subdirectories. File paths are relative to |dir_path|. Only files are // included, not directories. Path separator is always '/', even on windows (not // '\'). -base::Status ListFilesRecursive(const std::string& dir_path, - std::vector& output); +base::Status ListFilesRecursive(const std::string& dir_path, std::vector& output); } // namespace base } // namespace perfetto @@ -2236,26 +2105,21 @@ constexpr size_t kBufSize = 2048; #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) // Wrap FindClose to: (1) make the return unix-style; (2) deal with stdcall. -int CloseFindHandle(HANDLE h) { - return FindClose(h) ? 0 : -1; -} +int CloseFindHandle(HANDLE h) { return FindClose(h) ? 0 : -1; } std::optional ToUtf16(const std::string str) { - int len = MultiByteToWideChar(CP_UTF8, 0, str.data(), - static_cast(str.size()), nullptr, 0); + int len = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), nullptr, 0); if (len < 0) { return std::nullopt; } std::vector tmp; tmp.resize(static_cast::size_type>(len)); - len = - MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), - tmp.data(), static_cast(tmp.size())); + len = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), tmp.data(), + static_cast(tmp.size())); if (len < 0) { return std::nullopt; } - PERFETTO_CHECK(static_cast::size_type>(len) == - tmp.size()); + PERFETTO_CHECK(static_cast::size_type>(len) == tmp.size()); return std::wstring(tmp.data(), tmp.size()); } @@ -2281,14 +2145,12 @@ bool ReadFileDescriptor(int fd, std::string* out) { struct stat buf {}; if (fstat(fd, &buf) != -1) { - if (buf.st_size > 0) - out->resize(i + static_cast(buf.st_size)); + if (buf.st_size > 0) out->resize(i + static_cast(buf.st_size)); } ssize_t bytes_read; for (;;) { - if (out->size() < i + kBufSize) - out->resize(out->size() + kBufSize); + if (out->size() < i + kBufSize) out->resize(out->size() + kBufSize); bytes_read = Read(fd, &((*out)[i]), kBufSize); if (bytes_read > 0) { @@ -2306,8 +2168,7 @@ bool ReadPlatformHandle(PlatformHandle h, std::string* out) { size_t i = out->size(); for (;;) { - if (out->size() < i + kBufSize) - out->resize(out->size() + kBufSize); + if (out->size() < i + kBufSize) out->resize(out->size() + kBufSize); DWORD bytes_read = 0; auto res = ::ReadFile(h, &((*out)[i]), kBufSize, &bytes_read, nullptr); if (res && bytes_read > 0) { @@ -2329,14 +2190,11 @@ bool ReadPlatformHandle(PlatformHandle h, std::string* out) { #endif } -bool ReadFileStream(FILE* f, std::string* out) { - return ReadFileDescriptor(fileno(f), out); -} +bool ReadFileStream(FILE* f, std::string* out) { return ReadFileDescriptor(fileno(f), out); } bool ReadFile(const std::string& path, std::string* out) { base::ScopedFile fd = base::OpenFile(path, O_RDONLY); - if (!fd) - return false; + if (!fd) return false; return ReadFileDescriptor(*fd, out); } @@ -2345,16 +2203,13 @@ ssize_t WriteAll(int fd, const void* buf, size_t count) { size_t written = 0; while (written < count) { // write() on windows takes an unsigned int size. - uint32_t bytes_left = static_cast( - std::min(count - written, static_cast(UINT32_MAX))); + uint32_t bytes_left = + static_cast(std::min(count - written, static_cast(UINT32_MAX))); platform::BeforeMaybeBlockingSyscall(); - ssize_t wr = PERFETTO_EINTR( - write(fd, static_cast(buf) + written, bytes_left)); + ssize_t wr = PERFETTO_EINTR(write(fd, static_cast(buf) + written, bytes_left)); platform::AfterMaybeBlockingSyscall(); - if (wr == 0) - break; - if (wr < 0) - return wr; + if (wr == 0) break; + if (wr < 0) return wr; written += static_cast(wr); } return static_cast(written); @@ -2375,8 +2230,7 @@ ssize_t WriteAllHandle(PlatformHandle h, const void* buf, size_t count) { bool FlushFile(int fd) { PERFETTO_DCHECK(fd != 0); -#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || \ - PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) +#if PERFETTO_BUILDFLAG(PERFETTO_OS_LINUX) || PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) return !PERFETTO_EINTR(fdatasync(fd)); #elif PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) return !PERFETTO_EINTR(_commit(fd)); @@ -2401,9 +2255,7 @@ bool Rmdir(const std::string& path) { #endif } -int CloseFile(int fd) { - return close(fd); -} +int CloseFile(int fd) { return close(fd); } ScopedFile OpenFile(const std::string& path, int flags, FileOpenMode mode) { // If a new file might be created, ensure that the permissions for the new @@ -2454,8 +2306,7 @@ int ClosePlatformHandle(PlatformHandle handle) { #endif } -base::Status ListFilesRecursive(const std::string& dir_path, - std::vector& output) { +base::Status ListFilesRecursive(const std::string& dir_path, std::vector& output) { std::string root_dir_path = dir_path; if (root_dir_path.back() == '\\') { root_dir_path.back() = '/'; @@ -2480,8 +2331,7 @@ base::Status ListFilesRecursive(const std::string& dir_path, return base::ErrStatus("Directory path %s is too long", dir_path.c_str()); WIN32_FIND_DATAA ffd; - base::ScopedResource + base::ScopedResource hFind(FindFirstFileA(glob_path.c_str(), &ffd)); if (!hFind) { // For empty directories, there should be at least one entry '.'. @@ -2490,8 +2340,7 @@ base::Status ListFilesRecursive(const std::string& dir_path, return base::ErrStatus("Failed to open directory %s", cur_dir.c_str()); } do { - if (strcmp(ffd.cFileName, ".") == 0 || strcmp(ffd.cFileName, "..") == 0) - continue; + if (strcmp(ffd.cFileName, ".") == 0 || strcmp(ffd.cFileName, "..") == 0) continue; if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { std::string subdir_path = cur_dir + ffd.cFileName + '/'; dir_queue.push_back(subdir_path); @@ -2506,10 +2355,8 @@ base::Status ListFilesRecursive(const std::string& dir_path, if (!dir) { return base::ErrStatus("Failed to open directory %s", cur_dir.c_str()); } - for (auto* dirent = readdir(dir.get()); dirent != nullptr; - dirent = readdir(dir.get())) { - if (strcmp(dirent->d_name, ".") == 0 || - strcmp(dirent->d_name, "..") == 0) { + for (auto* dirent = readdir(dir.get()); dirent != nullptr; dirent = readdir(dir.get())) { + if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) { continue; } if (dirent->d_type == DT_DIR) { @@ -2527,8 +2374,7 @@ base::Status ListFilesRecursive(const std::string& dir_path, std::string GetFileExtension(const std::string& filename) { auto ext_idx = filename.rfind('.'); - if (ext_idx == std::string::npos) - return std::string(); + if (ext_idx == std::string::npos) return std::string(); return filename.substr(ext_idx); } @@ -2594,10 +2440,7 @@ extern int optind; extern int optopt; extern int opterr; -int getopt_long(int argc, - char** argv, - const char* shortopts, - const option* longopts, +int getopt_long(int argc, char** argv, const char* shortopts, const option* longopts, std::nullptr_t /*longindex is not supported*/); int getopt(int argc, char** argv, const char* shortopts); @@ -2646,32 +2489,25 @@ namespace { char* nextchar = nullptr; -const option* LookupLongOpt(const std::vector