* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
* libkperf licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: Wu
* Create: 2025-10-21
* Description: common funcions
******************************************************************************/
#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <limits.h>
#include "utils.h"
std::string GetTimeStr() {
auto now = std::chrono::system_clock::now();
std::time_t t = std::chrono::system_clock::to_time_t(now);
std::tm tm{};
localtime_r(&t, &tm);
std::ostringstream oss;
oss << std::put_time(&tm, "%Y%m%d_%H%M%S");
return oss.str();
}
std::string GetFullPath(const std::string& filename) {
char buf[PATH_MAX];
if (getcwd(buf, sizeof(buf)) != nullptr) {
return std::string(buf) + "/" + filename;
}
return filename;
}
std::string ProcessFunctionString(const std::string& input) {
std::ostringstream oss;
for (char ch : input) {
if (ch == ' ') {
oss << "\\ ";
} else {
oss << ch;
}
}
oss << "/1";
return oss.str();
}