Skip to content

Commit

Permalink
Create file with unique name to dump usage metrics (Xilinx#7831)
Browse files Browse the repository at this point in the history
* Create file with unique name to dump usage metrics

Signed-off-by: rbramand <[email protected]>

* Address comments on PR

Signed-off-by: rbramand <[email protected]>

---------

Signed-off-by: rbramand <[email protected]>
Co-authored-by: rbramand <[email protected]>
  • Loading branch information
rbramand-xilinx and rbramand authored Dec 5, 2023
1 parent 7b819f0 commit 8eefcb7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
16 changes: 2 additions & 14 deletions src/runtime_src/core/common/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,13 @@
# include <linux/limits.h>
# include <sys/stat.h>
# include <sys/types.h>
#include <unistd.h>
#endif
#ifdef _WIN32
# include <process.h>
# include <winsock.h>
#endif

namespace {

static int
get_processid()
{
#ifdef _WIN32
return _getpid();
#else
return getpid();
#endif
}

static unsigned int
get_userid()
{
Expand Down Expand Up @@ -206,7 +194,7 @@ file_dispatch(const std::string &file)
handle << "Build date: " << xrt_build_version_date << "\n";
handle << "Git branch: " << xrt_build_version_branch<< "\n";
handle << "[" << xrt_core::timestamp() << "]" << "\n";
handle << "PID: " << get_processid() << "\n";
handle << "PID: " << xrt_core::utils::get_pid() << "\n";
handle << "UID: " << get_userid() << "\n";
handle << "HOST: " << xrt_core::utils::get_hostname() << "\n";
handle << "EXE: " << get_exe_path() << std::endl;
Expand Down Expand Up @@ -235,7 +223,7 @@ console_dispatch()
std::cerr << "Build hash: " << xrt_build_version_hash << "\n";
std::cerr << "Build date: " << xrt_build_version_date << "\n";
std::cerr << "Git branch: " << xrt_build_version_branch<< "\n";
std::cerr << "PID: " << get_processid() << "\n";
std::cerr << "PID: " << xrt_core::utils::get_pid() << "\n";
std::cerr << "UID: " << get_userid() << "\n";
std::cerr << "[" << xrt_core::timestamp() << "]\n";
std::cerr << "HOST: " << xrt_core::utils::get_hostname() << "\n";
Expand Down
4 changes: 3 additions & 1 deletion src/runtime_src/core/common/usage_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "core/common/query_requests.h"
#include "core/common/shim/buffer_handle.h"
#include "core/common/shim/hwctx_handle.h"
#include "core/common/utils.h"
#include "core/include/xrt/xrt_uuid.h"

#include <algorithm>
Expand Down Expand Up @@ -173,7 +174,8 @@ print_json(const bpt::ptree& pt)
time_stamp << std::put_time(std::localtime(&time), "%Y-%m-%d_%H-%M-%S");

// create json in pwd
std::string file_name{"XRT_usage_metrics_" + time_stamp.str() + ".json"};
// file name format - XRT_usage_metrics_##pid_YY-MM-DD_H-M-S.json
std::string file_name{"XRT_usage_metrics_" + std::to_string(xrt_core::utils::get_pid()) + "_" + time_stamp.str() + ".json"};
std::ofstream out_file{file_name};

if (out_file.is_open()) {
Expand Down
17 changes: 17 additions & 0 deletions src/runtime_src/core/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
#include <string>
#include <boost/algorithm/string.hpp>

#ifdef __linux__
# include <unistd.h>
#endif
#ifdef _WIN32
# include <process.h>
#endif

namespace {

inline unsigned int
Expand Down Expand Up @@ -325,4 +332,14 @@ value_to_mac_addr(const uint64_t mac_addr_value)
return mac_addr;
}

int
get_pid()
{
#ifdef _WIN32
return _getpid();
#else
return getpid();
#endif
}

}} // utils, xrt_core
4 changes: 4 additions & 0 deletions src/runtime_src/core/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ XRT_CORE_COMMON_EXPORT
std::string
value_to_mac_addr(const uint64_t mac_addr_value);

XRT_CORE_COMMON_EXPORT
int
get_pid();

}} // utils, xrt_core

#endif

0 comments on commit 8eefcb7

Please sign in to comment.