Skip to content

Commit

Permalink
feat: Add creationTime function to process (#13542)
Browse files Browse the repository at this point in the history
* Add process creation time

* Making docs clear for process creation time

* Address comments for process creation time

* Add process info cc file

* fixing comments around documentation

* Update doc for return val

* Capitalize number in docs

* chore: bump electron-typescript-definitions
  • Loading branch information
husayn authored and ckerr committed Aug 10, 2018
1 parent 9902d42 commit 19cb5ba
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
12 changes: 12 additions & 0 deletions atom/common/api/atom_bindings.cc
Expand Up @@ -14,6 +14,7 @@
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_includes.h"
#include "base/logging.h"
#include "base/process/process_info.h"
#include "base/process/process_metrics_iocounters.h"
#include "base/sys_info.h"
#include "native_mate/dictionary.h"
Expand Down Expand Up @@ -55,6 +56,7 @@ void AtomBindings::BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process) {
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,
base::Unretained(this)));
Expand Down Expand Up @@ -177,6 +179,16 @@ v8::Local<v8::Value> AtomBindings::GetProcessMemoryInfo(v8::Isolate* isolate) {
return dict.GetHandle();
}

// static
v8::Local<v8::Value> AtomBindings::GetCreationTime(v8::Isolate* isolate) {
auto timeValue = base::CurrentProcessInfo::CreationTime();
if (timeValue.is_null()) {
return v8::Null(isolate);
}
double jsTime = timeValue.ToJsTime();
return v8::Number::New(isolate, jsTime);
}

// static
v8::Local<v8::Value> AtomBindings::GetSystemMemoryInfo(v8::Isolate* isolate,
mate::Arguments* args) {
Expand Down
1 change: 1 addition & 0 deletions atom/common/api/atom_bindings.h
Expand Up @@ -37,6 +37,7 @@ class AtomBindings {
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);
v8::Local<v8::Value> GetCPUUsage(v8::Isolate* isolate);
Expand Down
7 changes: 7 additions & 0 deletions docs/api/process.md
Expand Up @@ -111,6 +111,13 @@ The `process` object has the following methods:

Causes the main thread of the current process crash.

### `process.getCreationTime()`

Returns `Number | null` - The number of milliseconds since epoch, or `null` if the information is unavailable

Indicates the creation time of the application.
The time is represented as number of milliseconds since epoch. It returns null if it is unable to get the process creation time.

### `process.getCPUUsage()`

Returns [`CPUUsage`](structures/cpu-usage.md)
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -13,7 +13,7 @@
"dugite": "^1.45.0",
"electabul": "~0.0.4",
"electron-docs-linter": "^2.3.4",
"electron-typescript-definitions": "^1.3.5",
"electron-typescript-definitions": "^1.3.6",
"github": "^9.2.0",
"html-entities": "^1.2.1",
"husky": "^0.14.3",
Expand Down
7 changes: 7 additions & 0 deletions spec/api-process-spec.js
@@ -1,6 +1,13 @@
const {expect} = require('chai')

describe('process module', () => {
describe('process.getCreationTime()', () => {
it('returns a creation time', () => {
const creationTime = process.getCreationTime()
expect(creationTime).to.be.a('number').and.be.at.least(0)
})
})

describe('process.getCPUUsage()', () => {
it('returns a cpu usage object', () => {
const cpuUsage = process.getCPUUsage()
Expand Down

0 comments on commit 19cb5ba

Please sign in to comment.