@@ -43,6 +43,7 @@ constexpr double SEC_PER_MICROS = 1e-6;
4343
4444namespace report {
4545using node::arraysize;
46+ using node::DiagnosticFilename;
4647using node::Environment;
4748using node::Mutex;
4849using node::NativeSymbolDebuggingContext;
@@ -92,46 +93,26 @@ std::string TriggerNodeReport(Isolate* isolate,
9293 const char * trigger,
9394 const std::string& name,
9495 Local<String> stackstr) {
95- std::ostringstream oss;
9696 std::string filename;
9797 std::shared_ptr<PerIsolateOptions> options;
9898 if (env != nullptr ) options = env->isolate_data ()->options ();
9999
100- // Obtain the current time and the pid (platform dependent)
100+ // Obtain the current time.
101101 TIME_TYPE tm_struct;
102102 LocalTime (&tm_struct);
103103 // Determine the required report filename. In order of priority:
104104 // 1) supplied on API 2) configured on startup 3) default generated
105105 if (!name.empty ()) {
106- // Filename was specified as API parameter, use that
107- oss << name;
106+ // Filename was specified as API parameter.
107+ filename = name;
108108 } else if (env != nullptr && options->report_filename .length () > 0 ) {
109- // File name was supplied via start-up option, use that
110- oss << options->report_filename ;
109+ // File name was supplied via start-up option.
110+ filename = options->report_filename ;
111111 } else {
112- // Construct the report filename, with timestamp, pid and sequence number
113- oss << " report" ;
114- #ifdef _WIN32
115- oss << " ." << std::setfill (' 0' ) << std::setw (4 ) << tm_struct.wYear ;
116- oss << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.wMonth ;
117- oss << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.wDay ;
118- oss << " ." << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.wHour ;
119- oss << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.wMinute ;
120- oss << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.wSecond ;
121- #else // UNIX, OSX
122- oss << " ." << std::setfill (' 0' ) << std::setw (4 ) << tm_struct.tm_year + 1900 ;
123- oss << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.tm_mon + 1 ;
124- oss << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.tm_mday ;
125- oss << " ." << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.tm_hour ;
126- oss << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.tm_min ;
127- oss << std::setfill (' 0' ) << std::setw (2 ) << tm_struct.tm_sec ;
128- #endif
129- oss << " ." << uv_os_getpid ();
130- oss << " ." << std::setfill (' 0' ) << std::setw (3 ) << ++seq;
131- oss << " .json" ;
112+ filename = *DiagnosticFilename (env != nullptr ? env->thread_id () : 0 ,
113+ " report" , " json" , seq++);
132114 }
133115
134- filename = oss.str ();
135116 // Open the report file stream for writing. Supports stdout/err,
136117 // user-specified or (default) generated name
137118 std::ofstream outfile;
0 commit comments