-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
243 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
profiler/src/ProfilerEngine/Datadog.Profiler.Native/FileHelper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc. | ||
|
||
#include "FileHelper.h" | ||
|
||
#include "OpSysTools.h" | ||
|
||
#include <fstream> | ||
|
||
|
||
std::string FileHelper::GenerateFilename(std::string const& filename, std::string const& extension, std::string const& serviceName, std::string const& id) | ||
{ | ||
static std::string pid = std::to_string(OpSysTools::GetProcId()); | ||
|
||
auto fileSuffix = GenerateFileSuffix(serviceName, extension, pid, id); | ||
|
||
if (filename.empty()) | ||
{ | ||
return fileSuffix; | ||
} | ||
return filename + "_" + fileSuffix; | ||
} | ||
|
||
std::string FileHelper::GenerateFileSuffix(const std::string& applicationName, const std::string& extension, std::string const& pid, std::string const& id) | ||
{ | ||
auto time = std::time(nullptr); | ||
struct tm buf = {}; | ||
|
||
#ifdef _WINDOWS | ||
localtime_s(&buf, &time); | ||
#else | ||
localtime_r(&time, &buf); | ||
#endif | ||
|
||
std::stringstream oss; | ||
oss << applicationName + "_" << pid << "_" << std::put_time(&buf, "%F_%H-%M-%S"); | ||
if (!id.empty()) | ||
{ | ||
oss << "_" << id; | ||
} | ||
|
||
oss << extension; | ||
return oss.str(); | ||
} |
19 changes: 19 additions & 0 deletions
19
profiler/src/ProfilerEngine/Datadog.Profiler.Native/FileHelper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2022 Datadog, Inc. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "shared/src/native-src/dd_filesystem.hpp" | ||
|
||
class FileHelper | ||
{ | ||
public: | ||
static std::string GenerateFilename(std::string const& filename, std::string const& extension, std::string const& serviceName, std::string const& id = ""); | ||
|
||
private: | ||
static std::string GenerateFileSuffix(const std::string& applicationName, const std::string& extension, std::string const& pid, std::string const &id); | ||
|
||
FileHelper() = default; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.