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
1 parent
1855144
commit e22142e
Showing
17 changed files
with
262 additions
and
5 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,56 @@ | ||
// 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/heap_snapshot.h" | ||
|
||
#include "v8/include/v8-profiler.h" | ||
|
||
namespace { | ||
|
||
class HeapSnapshotOutputStream : public v8::OutputStream { | ||
public: | ||
explicit HeapSnapshotOutputStream(base::File* file) : file_(file) { | ||
DCHECK(file_); | ||
} | ||
|
||
bool IsComplete() const { return is_complete_; } | ||
|
||
// v8::OutputStream | ||
int GetChunkSize() override { return 65536; } | ||
void EndOfStream() override { is_complete_ = true; } | ||
|
||
v8::OutputStream::WriteResult WriteAsciiChunk(char* data, int size) override { | ||
auto bytes_written = file_->WriteAtCurrentPos(data, size); | ||
return bytes_written == size ? kContinue : kAbort; | ||
} | ||
|
||
private: | ||
base::File* file_ = nullptr; | ||
bool is_complete_ = false; | ||
}; | ||
|
||
} // namespace | ||
|
||
namespace atom { | ||
|
||
bool TakeHeapSnapshot(v8::Isolate* isolate, base::File* file) { | ||
DCHECK(isolate); | ||
DCHECK(file); | ||
|
||
if (!file->IsValid()) | ||
return false; | ||
|
||
auto* snapshot = isolate->GetHeapProfiler()->TakeHeapSnapshot(); | ||
if (!snapshot) | ||
return false; | ||
|
||
HeapSnapshotOutputStream stream(file); | ||
snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | ||
|
||
const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); | ||
|
||
return stream.IsComplete(); | ||
} | ||
|
||
} // 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,17 @@ | ||
// 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_HEAP_SNAPSHOT_H_ | ||
#define ATOM_COMMON_HEAP_SNAPSHOT_H_ | ||
|
||
#include "base/files/file.h" | ||
#include "v8/include/v8.h" | ||
|
||
namespace atom { | ||
|
||
bool TakeHeapSnapshot(v8::Isolate* isolate, base::File* file); | ||
|
||
} // namespace atom | ||
|
||
#endif // ATOM_COMMON_HEAP_SNAPSHOT_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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.