Add 'projects/rocprofiler-systems/' from commit '92e1d84c72c9321d79a1866e0090fae0215e6557'

git-subtree-dir: projects/rocprofiler-systems
git-subtree-mainline: ee9e74df21
git-subtree-split: 92e1d84c72
此提交包含在:
systems-assistant[bot]
2025-07-17 18:13:44 +00:00
當前提交 6755fa3a36
共有 699 個檔案被更改,包括 179131 行新增0 行删除
+50
查看文件
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.18.4 FATAL_ERROR)
project(rocprofiler-systems-code-coverage-example LANGUAGES CXX)
if(ROCPROFSYS_DISABLE_EXAMPLES)
get_filename_component(_DIR ${CMAKE_CURRENT_LIST_DIR} NAME)
if(
${PROJECT_NAME} IN_LIST ROCPROFSYS_DISABLE_EXAMPLES
OR ${_DIR} IN_LIST ROCPROFSYS_DISABLE_EXAMPLES
)
return()
endif()
endif()
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
string(REPLACE " " ";" _FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
find_package(Threads REQUIRED)
add_executable(code-coverage code-coverage.cpp)
target_link_libraries(code-coverage PRIVATE Threads::Threads)
target_compile_options(code-coverage PRIVATE ${_FLAGS})
if(ROCPROFSYS_INSTALL_EXAMPLES)
install(TARGETS code-coverage DESTINATION bin COMPONENT rocprofiler-systems-examples)
endif()
set(PYTHON_FILES code-coverage.py)
find_package(Python3 COMPONENTS Interpreter)
if(Python3_FOUND)
set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
foreach(_FILE ${PYTHON_FILES})
configure_file(
${PROJECT_SOURCE_DIR}/${_FILE}
${PROJECT_BINARY_DIR}/${_FILE}
@ONLY
)
if(ROCPROFSYS_INSTALL_EXAMPLES)
install(
PROGRAMS ${PROJECT_BINARY_DIR}/${_FILE}
DESTINATION bin
COMPONENT rocprofiler-systems-examples
)
endif()
endforeach()
endif()
+88
查看文件
@@ -0,0 +1,88 @@
#include <atomic>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <thread>
#include <vector>
#define NOINLINE __attribute__((noinline))
std::atomic<long> total{ 0 };
long
fib(long n) NOINLINE;
void
run_real(size_t nitr, long) NOINLINE;
void
run_fake(size_t nitr, long) NOINLINE;
int
main(int argc, char** argv)
{
using exec_t = void (*)(size_t, long);
std::string _name = argv[0];
auto _pos = _name.find_last_of('/');
if(_pos != std::string::npos) _name = _name.substr(_pos + 1);
size_t nthread = std::min<size_t>(16, std::thread::hardware_concurrency());
size_t nitr = 5000;
long nfib = 10;
if(argc > 1) nfib = atol(argv[1]);
if(argc > 2) nthread = atol(argv[2]);
if(argc > 3) nitr = atol(argv[3]);
exec_t _exec = &run_real;
// ensure that compiler cannot optimize run_fake away
if(std::getenv("CODE_COVERAGE_USE_FAKE") != nullptr) _exec = &run_fake;
printf("[%s] Threads: %zu\n[%s] Iterations: %zu\n[%s] fibonacci(%li)...\n",
_name.c_str(), nthread, _name.c_str(), nitr, _name.c_str(), nfib);
std::vector<std::thread> threads{};
for(size_t i = 0; i < nthread; ++i)
{
size_t _nitr = ((i % 2) == 1) ? (nitr - (0.1 * nitr)) : (nitr + (0.1 * nitr));
_nitr = std::max<size_t>(_nitr, 1);
threads.emplace_back(_exec, _nitr, nfib);
}
auto _nitr = std::max<size_t>(nitr - 0.25 * nitr, 1);
(*_exec)(_nitr, nfib - 0.1 * nfib);
for(auto& itr : threads)
itr.join();
printf("[%s] fibonacci(%li) x %lu = %li\n", _name.c_str(), nfib, nthread,
total.load());
return 0;
}
long
fib(long n)
{
return (n < 2) ? n : fib(n - 1) + fib(n - 2);
}
void
run_real(size_t nitr, long n)
{
long local = 0;
for(size_t i = 0; i < nitr; ++i)
local += fib(n);
total += local;
}
void
run_fake(size_t nitr, long n)
{
long local = 0;
for(size_t i = 0; i < nitr; ++i)
local += fib(n);
total += local;
}
+54
查看文件
@@ -0,0 +1,54 @@
#!@PYTHON_EXECUTABLE@
import rocprofsys
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-i",
"--input",
type=str,
nargs="+",
help="Input code coverage",
default=None,
required=True,
)
parser.add_argument(
"-o",
"--output",
type=str,
help="Output code coverage",
default=None,
required=True,
)
args = parser.parse_args()
data = None
for itr in args.input:
_summary, _details = rocprofsys.coverage.load(itr)
if data is None:
data = _details
else:
data = rocprofsys.coverage.concat(data, _details)
summary = rocprofsys.coverage.get_summary(data)
top = rocprofsys.coverage.get_top(data)
bottom = rocprofsys.coverage.get_bottom(data)
print("Top code coverage:")
for itr in top:
print(
f" {itr.count} | {itr.function} | {itr.module}:{itr.line} | {itr.source}"
)
print("Bottom code coverage:")
for itr in bottom:
print(
f" {itr.count} | {itr.function} | {itr.module}:{itr.line} | {itr.source}"
)
print("\nSaving code coverage")
rocprofsys.coverage.save(summary, data, args.output)