Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add process.takeHeapSnapshot()
- Loading branch information
Showing
10 changed files
with
181 additions
and
0 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
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,47 @@ | ||
// Copyright (c) 2018 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "atom/common/api/file_output_stream.h" | ||
|
||
#include "base/path_service.h" | ||
#include "base/strings/stringprintf.h" | ||
#include "brightray/browser/brightray_paths.h" | ||
#include "uv.h" // NOLINT(build/include) | ||
|
||
namespace atom { | ||
|
||
FileOutputStream::FileOutputStream(base::File* file) : file_(file) {} | ||
|
||
bool FileOutputStream::IsComplete() const { | ||
return is_complete_; | ||
} | ||
|
||
int FileOutputStream::GetChunkSize() { | ||
return 65536; | ||
} | ||
|
||
void FileOutputStream::EndOfStream() { | ||
is_complete_ = true; | ||
} | ||
|
||
v8::OutputStream::WriteResult FileOutputStream::WriteAsciiChunk(char* data, | ||
int size) { | ||
auto bytes_written = file_->WriteAtCurrentPos(data, size); | ||
return bytes_written == size ? kContinue : kAbort; | ||
} | ||
|
||
// static | ||
base::FilePath FileOutputStream::GetFilePath() { | ||
base::FilePath user_data; | ||
PathService::Get(brightray::DIR_USER_DATA, &user_data); | ||
|
||
auto now = uv_hrtime(); | ||
auto sec = static_cast<unsigned int>(now / 1000000); | ||
auto usec = static_cast<unsigned int>(now % 1000000); | ||
auto filename = base::StringPrintf("heapdump-%u.%u.heapsnapshot", sec, usec); | ||
|
||
return user_data.AppendASCII(filename.c_str()); | ||
} | ||
|
||
} // namespace atom |
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,34 @@ | ||
// Copyright (c) 2018 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ATOM_COMMON_API_FILE_OUTPUT_STREAM_H_ | ||
#define ATOM_COMMON_API_FILE_OUTPUT_STREAM_H_ | ||
|
||
#include "base/files/file.h" | ||
#include "base/files/file_path.h" | ||
#include "v8/include/v8-profiler.h" | ||
|
||
namespace atom { | ||
|
||
class FileOutputStream : public v8::OutputStream { | ||
public: | ||
explicit FileOutputStream(base::File* file); | ||
|
||
bool IsComplete() const; | ||
|
||
// v8::OutputStream | ||
virtual int GetChunkSize(); | ||
virtual void EndOfStream(); | ||
virtual v8::OutputStream::WriteResult WriteAsciiChunk(char* data, int size); | ||
|
||
static base::FilePath GetFilePath(); | ||
|
||
private: | ||
base::File* file_ = nullptr; | ||
bool is_complete_ = false; | ||
}; | ||
|
||
} // namespace atom | ||
|
||
#endif // ATOM_COMMON_API_FILE_OUTPUT_STREAM_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
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