-
Notifications
You must be signed in to change notification settings - Fork 248
feat(scope): add scope digest stat collection #609
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,57 @@ _mapEqual(Map a, Map b) { | |
} | ||
} | ||
|
||
class ScopeStats { | ||
bool report = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. most properties could be final ( I'm all for writting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
NumberFormat nf = new NumberFormat.decimalPattern(); | ||
|
||
AvgStopwatch digestFieldStopwatch = new AvgStopwatch(); | ||
AvgStopwatch digestEvalStopwatch = new AvgStopwatch(); | ||
AvgStopwatch digestProcessStopwatch = new AvgStopwatch(); | ||
int _digestLoopNo = 0; | ||
|
||
AvgStopwatch flushFieldStopwatch = new AvgStopwatch(); | ||
AvgStopwatch flushEvalStopwatch = new AvgStopwatch(); | ||
AvgStopwatch flushProcessStopwatch = new AvgStopwatch(); | ||
|
||
ScopeStats({this.report: false}) { | ||
nf.maximumFractionDigits = 0; | ||
} | ||
|
||
void digestStart() { | ||
_digestStopwatchReset(); | ||
_digestLoopNo = 0; | ||
} | ||
|
||
_digestStopwatchReset() { | ||
digestFieldStopwatch.reset(); | ||
digestEvalStopwatch.reset(); | ||
digestProcessStopwatch.reset(); | ||
} | ||
|
||
void digestLoop(int changeCount) { | ||
_digestLoopNo++; | ||
if (report) { | ||
print('digest #$_digestLoopNo:' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to toString() |
||
'Field: ${_stat(digestFieldStopwatch)} ' | ||
'Eval: ${_stat(digestEvalStopwatch)} ' | ||
'Process: ${_stat(digestProcessStopwatch)}'); | ||
} | ||
_digestStopwatchReset(); | ||
} | ||
|
||
String _stat(AvgStopwatch s) { | ||
return '${nf.format(s.count)}' | ||
' / ${nf.format(s.elapsedMicroseconds)} us' | ||
' = ${nf.format(s.ratePerMs)} #/ms'; | ||
} | ||
|
||
void digestEnd() { | ||
|
||
} | ||
} | ||
|
||
|
||
class RootScope extends Scope { | ||
static final STATE_APPLY = 'apply'; | ||
static final STATE_DIGEST = 'digest'; | ||
|
@@ -378,11 +429,14 @@ class RootScope extends Scope { | |
_FunctionChain _domWriteHead, _domWriteTail; | ||
_FunctionChain _domReadHead, _domReadTail; | ||
|
||
final ScopeStats _scopeStats; | ||
|
||
String _state; | ||
|
||
RootScope(Object context, this._astParser, this._parser, | ||
GetterCache cacheGetter, FilterMap filterMap, | ||
this._exceptionHandler, this._ttl, this._zone) | ||
this._exceptionHandler, this._ttl, this._zone, | ||
this._scopeStats) | ||
: super(context, null, null, | ||
new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context), | ||
new RootWatchGroup(new DirtyCheckingChangeDetector(cacheGetter), context)) | ||
|
@@ -404,6 +458,7 @@ class RootScope extends Scope { | |
List digestLog; | ||
var count; | ||
ChangeLog changeLog; | ||
_scopeStats.digestStart(); | ||
do { | ||
while(_runAsyncHead != null) { | ||
try { | ||
|
@@ -416,7 +471,11 @@ class RootScope extends Scope { | |
|
||
digestTTL--; | ||
count = rootWatchGroup.detectChanges( | ||
exceptionHandler: _exceptionHandler, changeLog: changeLog); | ||
exceptionHandler: _exceptionHandler, | ||
changeLog: changeLog, | ||
fieldStopwatch: _scopeStats.digestFieldStopwatch, | ||
evalStopwatch: _scopeStats.digestEvalStopwatch, | ||
processStopwatch: _scopeStats.digestProcessStopwatch); | ||
|
||
if (digestTTL <= LOG_COUNT) { | ||
if (changeLog == null) { | ||
|
@@ -432,8 +491,10 @@ class RootScope extends Scope { | |
throw 'Model did not stabilize in ${_ttl.ttl} digests. ' | ||
'Last $LOG_COUNT iterations:\n${log.join('\n')}'; | ||
} | ||
_scopeStats.digestLoop(count); | ||
} while (count > 0); | ||
} finally { | ||
_scopeStats.digestEnd(); | ||
_transitionState(STATE_DIGEST, null); | ||
} | ||
} | ||
|
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.
is this needed to export
AvgStopwatch
or something else? maybe moveAvgStopwatch
to utils? I don't feel likedirty_checking_change_detector
needs to be exported.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.
removed, I think this was left over accidentally.