Samuel Attard 2018-07-22 00:27:38 +10:00 committed by Aleksei Kuzmin
parent 833b55107d
commit 14df89f214
9 changed files with 27 additions and 67 deletions

View file

@ -55,7 +55,6 @@ void AtomBindings::BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process) {
dict.SetMethod("hang", &Hang);
dict.SetMethod("log", &Log);
dict.SetMethod("getHeapStatistics", &GetHeapStatistics);
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
dict.SetMethod("getCreationTime", &GetCreationTime);
dict.SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
dict.SetMethod("getCPUUsage", base::Bind(&AtomBindings::GetCPUUsage,
@ -159,26 +158,6 @@ v8::Local<v8::Value> AtomBindings::GetHeapStatistics(v8::Isolate* isolate) {
return dict.GetHandle();
}
// static
v8::Local<v8::Value> AtomBindings::GetProcessMemoryInfo(v8::Isolate* isolate) {
auto metrics = base::ProcessMetrics::CreateCurrentProcessMetrics();
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.SetHidden("simple", true);
dict.Set("workingSetSize",
static_cast<double>(metrics->GetWorkingSetSize() >> 10));
dict.Set("peakWorkingSetSize",
static_cast<double>(metrics->GetPeakWorkingSetSize() >> 10));
size_t private_bytes, shared_bytes;
if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) {
dict.Set("privateBytes", static_cast<double>(private_bytes >> 10));
dict.Set("sharedBytes", static_cast<double>(shared_bytes >> 10));
}
return dict.GetHandle();
}
// static
v8::Local<v8::Value> AtomBindings::GetCreationTime(v8::Isolate* isolate) {
auto timeValue = base::CurrentProcessInfo::CreationTime();

View file

@ -36,7 +36,6 @@ class AtomBindings {
static void Crash();
static void Hang();
static v8::Local<v8::Value> GetHeapStatistics(v8::Isolate* isolate);
static v8::Local<v8::Value> GetProcessMemoryInfo(v8::Isolate* isolate);
static v8::Local<v8::Value> GetCreationTime(v8::Isolate* isolate);
static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
mate::Arguments* args);

View file

@ -153,7 +153,6 @@ void AtomSandboxedRendererClient::InitializeBindings(
b.SetMethod("getPid", &base::GetCurrentProcId);
b.SetMethod("getResourcesPath", &NodeBindings::GetHelperResourcesPath);
b.SetMethod("getHeapStatistics", &AtomBindings::GetHeapStatistics);
b.SetMethod("getProcessMemoryInfo", &AtomBindings::GetProcessMemoryInfo);
b.SetMethod("getSystemMemoryInfo", &AtomBindings::GetSystemMemoryInfo);
b.SetMethod("getCPUUsage", base::Bind(&AtomBindings::GetCPUUsage,
base::Unretained(metrics_.get())));

View file

@ -135,8 +135,6 @@ nativeImage.createFromBuffer(buffer, {
```js
// Deprecated
const info = process.getProcessMemoryInfo()
const privateBytes = info.privateBytes // deprecated property
const sharedBytes = info.sharedBytes // deprecated property
```
## `screen`

View file

@ -14,7 +14,6 @@ In sandboxed renderers the `process` object contains only a subset of the APIs:
- `crash()`
- `hang()`
- `getHeapStatistics()`
- `getProcessMemoryInfo()`
- `getSystemMemoryInfo()`
- `getCPUUsage()`
- `getIOCounters()`
@ -156,22 +155,6 @@ Returns `Object`:
Returns an object with V8 heap statistics. Note that all statistics are reported in Kilobytes.
### `process.getProcessMemoryInfo()`
Returns `Object`:
* `workingSetSize` Integer - The amount of memory currently pinned to actual physical
RAM.
* `peakWorkingSetSize` Integer - The maximum amount of memory that has ever been pinned
to actual physical RAM.
* `privateBytes` Integer - The amount of memory not shared by other processes, such as
JS heap or HTML content.
* `sharedBytes` Integer - The amount of memory shared between processes, typically
memory consumed by the Electron code itself.
Returns an object giving memory usage statistics about the current process. Note
that all statistics are reported in Kilobytes.
### `process.getSystemMemoryInfo()`
Returns `Object`:

View file

@ -49,7 +49,6 @@ const preloadProcess = new events.EventEmitter()
preloadProcess.crash = () => binding.crash()
preloadProcess.hang = () => binding.hang()
preloadProcess.getHeapStatistics = () => binding.getHeapStatistics()
preloadProcess.getProcessMemoryInfo = () => binding.getProcessMemoryInfo()
preloadProcess.getSystemMemoryInfo = () => binding.getSystemMemoryInfo()
preloadProcess.getCPUUsage = () => binding.getCPUUsage()
preloadProcess.getIOCounters = () => binding.getIOCounters()

View file

@ -1627,7 +1627,8 @@ describe('BrowserWindow module', () => {
w.loadFile(path.join(fixtures, 'pages', 'window-open.html'))
})
it('releases memory after popup is closed', (done) => {
// TODO(alexeykuzmin): `GetProcessMemoryInfo()` is not available starting Ch67.
xit('releases memory after popup is closed', (done) => {
w.destroy()
w = new BrowserWindow({
show: false,

View file

@ -34,15 +34,16 @@ describe('process module', () => {
})
})
describe('process.getProcessMemoryInfo()', () => {
it('returns process memory info object', () => {
const processMemoryInfo = process.getProcessMemoryInfo()
expect(processMemoryInfo.peakWorkingSetSize).to.be.a('number')
expect(processMemoryInfo.privateBytes).to.be.a('number')
expect(processMemoryInfo.sharedBytes).to.be.a('number')
expect(processMemoryInfo.workingSetSize).to.be.a('number')
})
})
// FIXME: Chromium 67 - getProcessMemoryInfo has been removed
// describe('process.getProcessMemoryInfo()', () => {
// it('returns process memory info object', () => {
// const processMemoryInfo = process.getProcessMemoryInfo()
// expect(processMemoryInfo.peakWorkingSetSize).to.be.a('number')
// expect(processMemoryInfo.privateBytes).to.be.a('number')
// expect(processMemoryInfo.sharedBytes).to.be.a('number')
// expect(processMemoryInfo.workingSetSize).to.be.a('number')
// })
// })
describe('process.getSystemMemoryInfo()', () => {
it('returns system memory info object', () => {

View file

@ -35,20 +35,21 @@
await invokeGc()
ipcRenderer.send('answer', new Hello().say())
},
'allocate-memory': async () => {
await invokeGc()
const {privateBytes: bytesBeforeOpen} = process.getProcessMemoryInfo()
let w = open('./allocate-memory.html')
await invokeGc()
const {privateBytes: bytesAfterOpen} = process.getProcessMemoryInfo()
w.close()
w = null
await invokeGc()
const {privateBytes: bytesAfterClose} = process.getProcessMemoryInfo()
ipcRenderer.send('answer', {
bytesBeforeOpen, bytesAfterOpen, bytesAfterClose
})
},
// FIXME: Chromium 67 - getProcessMemoryInfo has been removed
// 'allocate-memory': async () => {
// await invokeGc()
// const {privateBytes: bytesBeforeOpen} = process.getProcessMemoryInfo()
// let w = open('./allocate-memory.html')
// await invokeGc()
// const {privateBytes: bytesAfterOpen} = process.getProcessMemoryInfo()
// w.close()
// w = null
// await invokeGc()
// const {privateBytes: bytesAfterClose} = process.getProcessMemoryInfo()
// ipcRenderer.send('answer', {
// bytesBeforeOpen, bytesAfterOpen, bytesAfterClose
// })
// },
'window-events': () => {
document.title = 'changed'
},