-
Notifications
You must be signed in to change notification settings - Fork 74
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
Onxy.printMetrics
MD, CSV and JSON formats
#90
Conversation
…available Since the update for Reanimated 2 (TurboModules/JSI) It's no longer possible to use the old (Chrome) debugging flow `react-native` runtime does not implement the `console.table` we're using to print information It was provided by Chrome, by launching the (old) debug flow `AsciiTable` allows us to print a MarkDown compatible table which is handy for posting data to github and other places that support MD
Oops some leftovers that should be cleaned up, will push another commit |
// Ignore modifying the first |---| for titled tables | ||
let idx = this.getTitle() ? -2 : -1; | ||
const ascii = super.toString() | ||
.replace(/-\|/g, () => { | ||
/* we replace "----|" with "---:|" to align the data to the right in MD */ | ||
idx++; | ||
|
||
if (idx < 0 || this.leftAlignedCols.includes(idx)) { | ||
return '-|'; | ||
} | ||
|
||
return ':|'; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is the most weird part of the PR
Markdown tables are left aligned by default
To align a column you add a :
column on the side you want it to align (or on both sides for centered)
|----------|---------:|----------:|
When we're printing a table with a title we want to skip the first row which looks like:
| Onyx:set |
|--------------------------------|
That's why we start with -2
on that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe could use a different token than Onyx:set
like Onyx~set
but this seems fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Individual tables would be labeled with whatever alias is provided here:
https://github.com/Expensify/react-native-onyx/blob/master/lib/Onyx.js#L771-L777
*/ | ||
function printMetrics(raw = false) { | ||
const {totalTime, summaries, lastCompleteCall = {endTime: -1}} = getMetrics(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this to print Last call finished at: N/A
when there are no calls made yet (or were cleared)
toDuration(call.startTime, raw), | ||
toDuration(call.endTime, raw), | ||
toDuration(call.duration, raw), | ||
call.args.map(String).join(', ').slice(0, 60), // Restrict cell width to 60 chars max |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're limiting this as it breaks the table when it's too large
I find it better to not JSON.stringify the data and instead keep it simple like: account, [object Object]
otherwise it adds too much noise
console.table(prettyData.map(({prettyCalls, ...summary}) => summary)); | ||
const mainOutput = [ | ||
'### Onyx Benchmark', | ||
` - Total: ${toDuration(totalTime, raw)}`, | ||
` - Last call finished at: ${lastCompleteCall ? toDuration(lastCompleteCall.endTime, raw) : 'N/A'}`, | ||
'', | ||
tableSummary.toString() | ||
]; | ||
|
||
prettyData.forEach((method) => { | ||
console.groupCollapsed(`[${method.methodName}] individual calls: `); | ||
console.table(method.prettyCalls); | ||
/* eslint-disable no-console */ | ||
console.info(mainOutput.join('\n')); | ||
methodCallTables.forEach((table) => { | ||
console.groupCollapsed(table.getTitle()); | ||
console.info(table.toString()); | ||
console.groupEnd(); | ||
}); | ||
|
||
console.groupEnd(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether we need console printing at all
The only convenience here is console.groupCollapsed
@@ -12,6 +12,7 @@ | |||
"test": "jest" | |||
}, | |||
"dependencies": { | |||
"ascii-table": "0.0.9", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was expecting to find something that will build directly as MD, but this was the closest thing I've found
This library required the least modifications to achieve an MD table
I've tried these alternatives:
This allows us to capture start/end time between different interactions e.g. resetMetrics then switch to a new chat When you print the stats you'll see the end time compared relative to the point before making the switch
This helps identify the tables when they are exported to excel
edfc47e
to
5111c1b
Compare
Is this ready for review? |
@johnmlee101 Yes |
default: | ||
return table.toString(); | ||
} | ||
}).join('\n\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason we join with 2 new lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To distinct separate tables easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me AFAICT, I asked @marcaaron to do final review
// Ignore modifying the first |---| for titled tables | ||
let idx = this.getTitle() ? -2 : -1; | ||
const ascii = super.toString() | ||
.replace(/-\|/g, () => { | ||
/* we replace "----|" with "---:|" to align the data to the right in MD */ | ||
idx++; | ||
|
||
if (idx < 0 || this.leftAlignedCols.includes(idx)) { | ||
return '-|'; | ||
} | ||
|
||
return ':|'; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe could use a different token than Onyx:set
like Onyx~set
but this seems fine.
@marcaaron
Details
This is a continuation of #89
This PR adds more print options:
It necessary to have something like this as it aids capturing and saving benchmark information
This PR does not change how Onyx works and only affects dev, debug, benchmark usages
Some examples
MD (Console)
CSV
When the data is too much it's not printed in full, but can be expanded and/or copied
![image](https://user-images.githubusercontent.com/12156624/125987452-f94803ae-1fdb-4ecf-abb5-c4c750030746.png)
JSON
MD (String)
This is useful when
__DEV__
isfalse
as callingconsole.info
would not output anythingRelated Issues
N/A
Automated Tests
Covered by existing tests,
Manually tested the printing functionality
Linked PRs