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

src: always use diagnostic file sequence number #27142

Merged
merged 1 commit into from
Apr 11, 2019
Merged
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
13 changes: 5 additions & 8 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,24 +334,21 @@ class DiagnosticFilename {

DiagnosticFilename(Environment* env,
const char* prefix,
const char* ext,
int seq = -1) :
filename_(MakeFilename(env->thread_id(), prefix, ext, seq)) {}
const char* ext) :
filename_(MakeFilename(env->thread_id(), prefix, ext)) {}

DiagnosticFilename(uint64_t thread_id,
const char* prefix,
const char* ext,
int seq = -1) :
filename_(MakeFilename(thread_id, prefix, ext, seq)) {}
const char* ext) :
filename_(MakeFilename(thread_id, prefix, ext)) {}

const char* operator*() const { return filename_.c_str(); }

private:
static std::string MakeFilename(
uint64_t thread_id,
const char* prefix,
const char* ext,
int seq = -1);
const char* ext);

std::string filename_;
};
Expand Down
6 changes: 1 addition & 5 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <cstring>
#include <ctime>
#include <cwctype>
#include <atomic>
#include <fstream>
#include <iomanip>
#include <climits> // PATH_MAX
Expand Down Expand Up @@ -73,9 +72,6 @@ static void PrintLoadedLibraries(JSONWriter* writer);
static void PrintComponentVersions(JSONWriter* writer);
static void PrintRelease(JSONWriter* writer);

// Global variables
static std::atomic_int seq = {0}; // sequence number for report filenames

// External function to trigger a report, writing to file.
// The 'name' parameter is in/out: an input filename is used
// if supplied, and the actual filename is returned.
Expand All @@ -99,7 +95,7 @@ std::string TriggerNodeReport(Isolate* isolate,
filename = options->report_filename;
} else {
filename = *DiagnosticFilename(env != nullptr ? env->thread_id() : 0,
"report", "json", seq++);
"report", "json");
}

// Open the report file stream for writing. Supports stdout/err,
Expand Down
9 changes: 5 additions & 4 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
#include <sys/types.h>
#endif

#include <atomic>
#include <cstdio>
#include <iomanip>
#include <sstream>

static std::atomic_int seq = {0}; // Sequence number for diagnostic filenames.

namespace node {

// Microseconds in a second, as a float.
Expand Down Expand Up @@ -225,8 +228,7 @@ void DiagnosticFilename::LocalTime(TIME_TYPE* tm_struct) {
std::string DiagnosticFilename::MakeFilename(
uint64_t thread_id,
const char* prefix,
const char* ext,
int seq) {
const char* ext) {
std::ostringstream oss;
TIME_TYPE tm_struct;
LocalTime(&tm_struct);
Expand Down Expand Up @@ -262,8 +264,7 @@ std::string DiagnosticFilename::MakeFilename(
#endif
oss << "." << uv_os_getpid();
oss << "." << thread_id;
if (seq >= 0)
oss << "." << std::setfill('0') << std::setw(3) << ++seq;
oss << "." << std::setfill('0') << std::setw(3) << ++seq;
oss << "." << ext;
return oss.str();
}
Expand Down