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

[TIMOB-26115] TiAPI: Add support for console.timeLog #10156

Merged
merged 4 commits into from Jul 11, 2018

Conversation

ewanharris
Copy link
Collaborator

JIRA: https://jira.appcelerator.org/browse/TIMOB-26115

Implement console.timeLog for Android and iOS

Test:

console.time('mytimer'); // Start timer
console.timeLog('mytimer'); // Log time taken so far
console.timeLog('mytimer', 'with', 'some', 'extra', 'info'); // Log time taken with extra logging
console.timeLog('mytimer', [ 'a', 'b', 'c' ], { objects: true }); // Should handle Arrays and Objects
console.timeEnd('mytimer');

Should log something like the below, there's some slight discrepancies between how Arrays/Objects are logged on platforms.

[INFO]  mytimer: 1ms
[INFO]  mytimer: 2ms with some extra info
[INFO]  mytimer: 3ms ["a","b","c"] {"objects":true}
[INFO]  mytimer: 3ms

@ewanharris ewanharris changed the title Timob 26115 [TIMOB-26115] TiAPI: Add support for console.timeLog Jul 6, 2018
@build
Copy link
Contributor

build commented Jul 6, 2018

Messages
📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

@@ -50,6 +50,27 @@ - (void)timeEnd:(id)label
[_times removeObjectForKey:label];
}

- (void)timeLog:(id)args
{
NSString *label = [args objectAtIndex:0];
Copy link
Collaborator

Choose a reason for hiding this comment

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

NSString *label = [args objectAtIndex:0] ?: @"default";

[self logMessage:[logMessage componentsSeparatedByString:@" "] severity:@"warn"];
return;
}
double duration = [startTime timeIntervalSinceNow] * -1000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use NSTimeInterval instead of double. They are the same, but NSTimeInterval is more known for storing time values.

}
double duration = [startTime timeIntervalSinceNow] * -1000;
NSString *logMessage = [NSString stringWithFormat:@"%@: %0.fms ", label, duration];
if ([logData count]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use [logData count] > 0 for clearance.

Copy link
Collaborator

@hansemannn hansemannn left a comment

Choose a reason for hiding this comment

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

iOS approved

if (!startTime) {
exports.warn(`Label "${label}" does not exist`);
return;
const warned = logTime(label);
Copy link
Contributor

Choose a reason for hiding this comment

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

the use of warned here is a little confusing. What you're really determining is if the label existed.

@sgtcoolguy sgtcoolguy added this to the 7.4.0 milestone Jul 11, 2018
…warn and inspect the string for console.timeLog. Have to skip on iOS due to native implementation.
Copy link
Contributor

@sgtcoolguy sgtcoolguy left a comment

Choose a reason for hiding this comment

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

Looks good. The ti.shell/common JS bootstrap stuff that Josh Quick is doing could lead us to define this just once in JS code across all platforms and thereby allow the fancier unit tests I added to work on iOS too. But for now, this works.

@sgtcoolguy sgtcoolguy merged commit 1b8f096 into tidev:master Jul 11, 2018
@hansemannn hansemannn modified the milestones: 7.4.0, 7.5.0 Aug 24, 2018
@ewanharris ewanharris deleted the TIMOB-26115 branch August 31, 2021 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants