* [html5] update perf time.
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/bd794e5e Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/bd794e5e Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/bd794e5e Branch: refs/heads/0.12-dev Commit: bd794e5e81b97d9503dc0166801c585dbcb5e98d Parents: f13c453 Author: MrRaindrop <tekk...@gmail.com> Authored: Wed Apr 19 12:17:02 2017 +0800 Committer: MrRaindrop <tekk...@gmail.com> Committed: Wed Apr 19 12:17:02 2017 +0800 ---------------------------------------------------------------------- html5/render/vue/mixins/base.js | 16 ++++++-- html5/render/vue/utils/perf.js | 76 +++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bd794e5e/html5/render/vue/mixins/base.js ---------------------------------------------------------------------- diff --git a/html5/render/vue/mixins/base.js b/html5/render/vue/mixins/base.js index c8185d5..819146e 100644 --- a/html5/render/vue/mixins/base.js +++ b/html5/render/vue/mixins/base.js @@ -24,7 +24,9 @@ import { import { tagBeforeCreate, - tagMounted, + // tagMounted, + tagRootMounted, + tagFirstScreen, tagBeforeUpdate, tagUpdated, tagBegin, @@ -61,14 +63,20 @@ export default { }, mounted () { + if (this.$options._componentTag === 'image') { + global._has_image_in_first_screen = true + } + if (this === this.$root) { + tagRootMounted() + if (!global._has_image_in_first_screen) { + tagFirstScreen() + } + } if (!weex._root) { weex._root = this.$root.$el weex._root.classList.add('weex-root') } watchAppear(this) - if (process.env.NODE_ENV === 'development') { - tagMounted() - } }, beforeUpdate () { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bd794e5e/html5/render/vue/utils/perf.js ---------------------------------------------------------------------- diff --git a/html5/render/vue/utils/perf.js b/html5/render/vue/utils/perf.js index f8540eb..13be79f 100644 --- a/html5/render/vue/utils/perf.js +++ b/html5/render/vue/utils/perf.js @@ -73,6 +73,45 @@ function getEntries (): Array<any> { : [{ responseEnd: getNow() - IMG_REC_INDENT }] } +function _d (func: Function, wait: number) { + let timerId + let now + function later (now) { + timerId = null + func(now) + } + return function () { + now = getNow() + clearTimeout(timerId) + timerId = setTimeout(later.bind(null, now), wait) + } +} + +export function tagFirstScreen (time?: number): void { + if (!time) { + time = getNow() + } + perf.latestRenderFinishes.push(time) + const start = Math.max(earliestBeforeCreateTime, earliestBeforeUpdateTime) + perf.renderTime.push({ + start, + end: time, + duration: time - start + }) + + const num = perf.renderTime.length + perf[`screenTime${num}`] = time + window.weex.emit('renderfinish', time) + if (!isFirstScreenDetected) { + isFirstScreenDetected = true + window.weex.emit('firstscreenfinish', time) + } + if (process.env.NODE_ENV === 'development') { + console.log(`screenTime[${num}]: ${time} ms.`) + console.log('_weex_perf:', window._weex_perf) + } +} + /** * get first screen time. */ @@ -90,25 +129,7 @@ const debouncedTagImg = debounce(function () { }) i++ } - perf.latestRenderFinishes.push(end) - const start = Math.max(earliestBeforeCreateTime, earliestBeforeUpdateTime) - perf.renderTime.push({ - start, - end, - duration: end - start - }) - - const num = perf.renderTime.length - perf[`screenTime${num}`] = end - window.weex.emit('renderfinish', end) - if (!isFirstScreenDetected) { - isFirstScreenDetected = true - window.weex.emit('firstscreenfinish', end) - } - if (process.env.NODE_ENV === 'development') { - console.log(`screenTime[${num}]: ${end} ms.`) - console.log('_weex_perf:', window._weex_perf) - } + tagFirstScreen(end) }, IMG_REC_INDENT) export function tagImg (): void { @@ -128,11 +149,21 @@ export function tagBeforeCreate (): void { depressedTagBeforeCreate() } +export function tagRootMounted (): void { + const now = getNow() + perf.latestMounts.push(now) + if (!perf.firstAllMountedTime) { + perf.firstAllMountedTime = now + if (process.env.NODE_ENV === 'development') { + console.log(`first all mounted time: ${now} ms.`) + } + } +} + /** * recording the latest 'mounted' time. */ -const debouncedTagMounted = debounce(function () { - const now = getNow() +const debouncedTagMounted = _d(function (now) { perf.latestMounts.push(now) perf.createTime.push({ start: earliestBeforeCreateTime, @@ -168,8 +199,7 @@ export function tagBeforeUpdate (): void { /** * recording the latest 'updated' time. */ -const debouncedTagUpdated = debounce(function () { - const now = getNow() +const debouncedTagUpdated = _d(function (now) { perf.latestUpdates.push(now) perf.updateTime.push({ start: earliestBeforeUpdateTime,