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() / webContents.takeHeapSnapshot()
- Loading branch information
Showing
14 changed files
with
228 additions
and
1 deletion.
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,52 @@ | ||
// 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/heap_snapshot_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 { | ||
|
||
HeapSnapshotOutputStream::HeapSnapshotOutputStream(base::File* file) | ||
: file_(file) { | ||
DCHECK(file_); | ||
} | ||
|
||
bool HeapSnapshotOutputStream::IsComplete() const { | ||
return is_complete_; | ||
} | ||
|
||
int HeapSnapshotOutputStream::GetChunkSize() { | ||
return 65536; | ||
} | ||
|
||
void HeapSnapshotOutputStream::EndOfStream() { | ||
is_complete_ = true; | ||
} | ||
|
||
v8::OutputStream::WriteResult HeapSnapshotOutputStream::WriteAsciiChunk( | ||
char* data, | ||
int size) { | ||
auto bytes_written = file_->WriteAtCurrentPos(data, size); | ||
return bytes_written == size ? kContinue : kAbort; | ||
} | ||
|
||
// static | ||
base::FilePath HeapSnapshotOutputStream::GetFilePath() { | ||
base::FilePath user_data; | ||
if (!PathService::Get(brightray::DIR_USER_DATA, &user_data)) | ||
return base::FilePath(); | ||
|
||
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_HEAP_SNAPSHOT_OUTPUT_STREAM_H_ | ||
#define ATOM_COMMON_API_HEAP_SNAPSHOT_OUTPUT_STREAM_H_ | ||
|
||
#include "base/files/file.h" | ||
#include "base/files/file_path.h" | ||
#include "v8/include/v8-profiler.h" | ||
|
||
namespace atom { | ||
|
||
class HeapSnapshotOutputStream : public v8::OutputStream { | ||
public: | ||
explicit HeapSnapshotOutputStream(base::File* file); | ||
|
||
bool IsComplete() const; | ||
|
||
// v8::OutputStream | ||
int GetChunkSize() override; | ||
void EndOfStream() override; | ||
v8::OutputStream::WriteResult WriteAsciiChunk(char* data, int size) override; | ||
|
||
static base::FilePath GetFilePath(); | ||
|
||
private: | ||
base::File* file_ = nullptr; | ||
bool is_complete_ = false; | ||
}; | ||
|
||
} // namespace atom | ||
|
||
#endif // ATOM_COMMON_API_HEAP_SNAPSHOT_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
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,16 @@ | ||
const {ipcRenderer} = require('electron') | ||
const errorUtils = require('../common/error-utils') | ||
|
||
module.exports = (process) => { | ||
ipcRenderer.on('ELECTRON_RENDERER_TAKE_HEAP_SNAPSHOT', (event, requestId, args) => { | ||
new Promise(resolve => | ||
process.takeHeapSnapshot(...args) | ||
).then(result => { | ||
return [null, result] | ||
}, error => { | ||
return [errorUtils.serialize(error)] | ||
}).then(responseArgs => { | ||
event.sender.send(`ELECTRON_BROWSER_TAKE_HEAP_SNAPSHOT_RESULT_${requestId}`, ...responseArgs) | ||
}) | ||
}) | ||
} |
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