Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge proto files from multiprocess run into one file. #61

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ configure_file(
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/modulefiles/${PROJECT_NAME}/${ROCPROFSYS_VERSION}
@ONLY)

configure_file(
${PROJECT_SOURCE_DIR}/scripts/merge_multiprocess_output.sh
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/merge_multiprocess_output.sh COPYONLY)

install(
FILES ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/setup-env.sh
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/perfetto.cfg
Expand All @@ -422,6 +426,11 @@ install(
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}
COMPONENT setup)

install(
PROGRAMS ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/merge_multiprocess_output.sh
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/bin/
COMPONENT setup)

# ------------------------------------------------------------------------------#
#
# install
Expand Down
1 change: 1 addition & 0 deletions cmake/Templates/setup-env.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fi

@PROJECT_NAME_UNDERSCORED@_ROOT=${BASEDIR}
PATH=${BASEDIR}/bin:${PATH}
PATH=${BASEDIR}/share/rocprofiler-systems/bin:${PATH}
LD_LIBRARY_PATH=${BASEDIR}/@CMAKE_INSTALL_LIBDIR@:${LD_LIBRARY_PATH}
PYTHONPATH=${BASEDIR}/@CMAKE_INSTALL_PYTHONDIR@:${PYTHONPATH}
CMAKE_PREFIX_PATH=${BASEDIR}:${CMAKE_PREFIX_PATH}
Expand Down
39 changes: 39 additions & 0 deletions scripts/merge_multiprocess_output.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Check if the folder path is provided
if [ -z "$1" ]; then
echo "Usage: $0 <folder_path>"
exit 1
fi

# Assign the folder path to a variable
FOLDER_PATH=$1

# Check if the folder exists
if [ ! -d "$FOLDER_PATH" ]; then
echo "Error: Folder '$FOLDER_PATH' does not exist."
exit 1
fi

# Check if there are more than one .proto files
PROTO_FILES=("$FOLDER_PATH"/*.proto)
if [ ${#PROTO_FILES[@]} -le 1 ]; then
exit 0
fi

echo "Merging multiprocess files ..."
# Check if all .proto files have been fully written or wait
for file in "${PROTO_FILES[@]}"; do
while lsof "$file" > /dev/null 2>&1; do
echo "..."
sleep 1
done
done

# Output file name
OUTPUT_FILE="merged.proto"

# Merge all .proto files into one file
cat "$FOLDER_PATH"/*.proto > "$FOLDER_PATH"/"$OUTPUT_FILE"

echo "All multiprocess .proto files in '$FOLDER_PATH' have been merged into '$OUTPUT_FILE'."
12 changes: 12 additions & 0 deletions source/lib/core/perfetto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "utility.hpp"

#include <chrono>
#include <filesystem>

namespace rocprofsys
{
Expand Down Expand Up @@ -263,6 +264,17 @@ post_process(tim::manager* _timemory_manager, bool& _perfetto_output_error)
_timemory_manager->add_file_output("protobuf", "perfetto", _filename);
}
ofs.close();

if(dmp::rank() == 0){
std::filesystem::path file_path(_filename);
auto folder_path = file_path.parent_path();
// Execute the merge script
std::string command = "merge_multiprocess_output.sh '" + std::string(folder_path.c_str()) + "'";
int result = system(command.c_str());
if (result != 0) {
ROCPROFSYS_VERBOSE(0, "Failed to execute merge_multiprocess_output.sh with folder path: %s\n", folder_path.c_str());
}
}
}
else if(dmp::rank() == 0)
{
Expand Down
Loading