Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add creationTime function to process #13542

Merged
merged 9 commits into from Aug 10, 2018
Merged

Conversation

husayn
Copy link
Contributor

@husayn husayn commented Jul 3, 2018

Expose the creationTime that chromium provides us on the process object.

@husayn husayn requested review from a team July 3, 2018 04:12

Returns [`number`]
Indicates the creation time of the application.
The time is represented as microseconds (s/1,000,000) since the Windows epoch (1601-01-01 00:00:00 UTC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mac & linux seem to return seconds from the start of the process.
And can be null or empty if the API fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the run from Mac it is giving back time since windows epoch as well
Here is what we get when run on a Mac.
131750664685357260
2018-07-03T04:41:08.535Z

Comment from time.h in chromium

/ Time represents an absolute point in coordinated universal time (UTC),
// internally represented as microseconds (s/1,000,000) since the Windows epoch
// (1601-01-01 00:00:00 UTC).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

microseconds since the Windows epoch

The returned value should be easy to use in JavaScript.
JavaScript Date object uses "number of milliseconds since 1 January 1970 UTC" (the epoch).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And can be null or empty if the API fails.

Please return null if the time cannot be obtained.

// static
int64_t AtomBindings::GetCreationTime(v8::Isolate* isolate) {
auto metrics = base::CurrentProcessInfo::CreationTime();
return metrics.ToInternalValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is deprecated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use

base::CurrentProcessInfo::CreationTime().ToJsTime()

Refs: ToJsTime()

Then users can just do new Date() on the ret value to get a JS date

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus points for a new mate converter to v8::Date

https://v8docs.nodesource.com/node-0.8/d4/df7/classv8_1_1_date.html

I.e. Convert base::Time to v8::Date


Returns [`number`]
Indicates the creation time of the application.
The time is represented as microseconds (s/1,000,000) since the Windows epoch (1601-01-01 00:00:00 UTC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

microseconds since the Windows epoch

The returned value should be easy to use in JavaScript.
JavaScript Date object uses "number of milliseconds since 1 January 1970 UTC" (the epoch).

describe('process.getCreationTime()', () => {
it('returns a creation time', () => {
const creationTime = process.getCreationTime()
assert.equal(typeof creationTime, 'number')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use expect() assertions from the Chai library, which produce much better failure message than assert.

const {expect} = require('chai')  // On the top of the file.
...
expect(creationTime).to.be.a('number').and.be.at.least(0)


Returns [`number`]
Indicates the creation time of the application.
The time is represented as microseconds (s/1,000,000) since the Windows epoch (1601-01-01 00:00:00 UTC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And can be null or empty if the API fails.

Please return null if the time cannot be obtained.

@codebytere
Copy link
Member

@husayn if you could please address the requested changes so we can get this across the finish line, that'd be great!

return v8::Null(isolate);
}
double jsTime = timeValue.ToJsTime();
return v8::Number::New(isolate, jsTime);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not do v8 conversions manually, native_mate will handle the conversions in a consistent way if you just return a cpp type.

I.e. Just make this return double

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarshallOfSound

double doesn't work if we want to return an "empty value".
And we have to return null when the time cannot be obtained.

if (timeValue.is_null()) {
  return v8::Null(isolate);
}

Copy link
Contributor Author

@husayn husayn Aug 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarshallOfSound can you please approve the changes if this looks good?

Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes RE return type

@@ -98,6 +98,12 @@ The `process` object has the following methods:

Causes the main thread of the current process crash.

### `process.getCreationTime()`

Returns [`number`]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we return null sometimes, it should be documented )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And btw there's no reasons to have square brackets there )

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@alexeykuzmin
Copy link
Contributor

@husayn
Can you please rebase your branch on the latest electron:master? to resolve conflicts.

Returns `number`
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to document this as "Returns Menu | null" for typescript. Something like

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done @ckerr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment got misplaced, no menu stuff here 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarshallOfSound you're correct, that should've read Number | null. I was cribbing from another documentation line and didn't clean it up correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@husayn I don't know if it the capitalization is required, but all our other documentation instances use Number rather than number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckerr capitalized it.

@MarshallOfSound MarshallOfSound added the semver/minor backwards-compatible functionality label Aug 10, 2018
@ckerr
Copy link
Member

ckerr commented Aug 10, 2018

The CI failures appear to be unrelated.

electron-gn-linux-ia32-debug-fyi is failing with wrong ELF class: ELFCLASS64

electron-gn-linux-ia32-release-fyi is failing with linker errors

@ckerr ckerr merged commit 19cb5ba into electron:master Aug 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants