From 6fa7e92fd8c301a8585b4259f5ef8a8c729b92c6 Mon Sep 17 00:00:00 2001 From: emizzle Date: Tue, 5 Jun 2018 17:15:21 +1000 Subject: [PATCH 1/3] Updates console to inform user of an ongoing package download. Console message turns red after 1 second. --- lib/versions/npm.js | 65 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/lib/versions/npm.js b/lib/versions/npm.js index 1bac4306..f7ca1751 100644 --- a/lib/versions/npm.js +++ b/lib/versions/npm.js @@ -1,6 +1,8 @@ -let fs = require('../core/fs.js'); - -let PluginManager = require('live-plugin-manager').PluginManager; +const fs = require('../core/fs.js'); +const {PerformanceObserver, performance} = require('perf_hooks'); +const PluginManager = require('live-plugin-manager').PluginManager; +require('colors'); +const _ = require('underscore'); class Npm { @@ -17,9 +19,62 @@ class Npm { return callback(null, packageDirectory + packageName); } - this.logger.info("downloading " + packageName + " " + version + "...."); - this.logger.info(__("downloading {{packageName}} {{version}}....", {packageName: packageName, version: version})); + this.logger.info(__("Downloading {{packageName}} {{version}}...", {packageName: packageName, version: version})); + + const obsMeasure = new PerformanceObserver((items) => { + let entry; + let strDuration; + + // find any download ongoing measurements we've made + entry = _.last(_.where(items.getEntries(), {name: downloadOngoing})); + if(entry){ + // ongoing performance mark + strDuration = __('Still downloading {{packageName}} {{version}}... ({{duration}}ms elapsed)', {packageName: packageName, version: version, duration: entry.duration}); + } + else{ + // otherwise, find our download complete measurement + entry = _.last(_.where(items.getEntries(), {name: downloadComplete})); + + if(entry){ + strDuration = __('Finished downloading {{packageName}} {{version}} in {{duration}}ms', {packageName: packageName, version: version, duration: entry.duration}); + performance.clearMarks(); + } + } + + // log our measurement and make it red if it has taken too long + if(entry && strDuration){ + if(entry.duration > 1000){ + strDuration = strDuration.red; + } + this.logger.info(strDuration); + } + + }); + obsMeasure.observe({entryTypes: ['measure']}); + + // define mark and measurement names + let startMark = 'downloadStart' + packageName + version; + let ongoingMark = 'downloadOngoingMark' + packageName + version; + let downloadOngoing = 'downloadOngoing' + packageName + version; + let endMark = 'downloadEnd' + packageName + version; + let downloadComplete = 'downloadComplete' + packageName + version; + + // mark our start time + performance.mark(startMark); + + // function that continually updates the console to show user that we're downloading a library + let intOngoingDownload = setInterval( + function(){ + performance.mark(ongoingMark); + performance.measure(downloadOngoing, startMark, ongoingMark); + }, 750); + + // do the package download/install manager.install(packageName, version).then((result) => { + // stop updating console for ongoing download + clearInterval(intOngoingDownload); + performance.mark(endMark); + performance.measure(downloadComplete, startMark, endMark); callback(null , result.location); }).catch(callback); } From bbaf1676fbb8532ab10d7ff8951009f5c6773b70 Mon Sep 17 00:00:00 2001 From: emizzle Date: Tue, 5 Jun 2018 17:15:21 +1000 Subject: [PATCH 2/3] Updates console to inform user of an ongoing package download. Console message turns red after 1 second. --- lib/versions/npm.js | 65 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/lib/versions/npm.js b/lib/versions/npm.js index 1bac4306..f7ca1751 100644 --- a/lib/versions/npm.js +++ b/lib/versions/npm.js @@ -1,6 +1,8 @@ -let fs = require('../core/fs.js'); - -let PluginManager = require('live-plugin-manager').PluginManager; +const fs = require('../core/fs.js'); +const {PerformanceObserver, performance} = require('perf_hooks'); +const PluginManager = require('live-plugin-manager').PluginManager; +require('colors'); +const _ = require('underscore'); class Npm { @@ -17,9 +19,62 @@ class Npm { return callback(null, packageDirectory + packageName); } - this.logger.info("downloading " + packageName + " " + version + "...."); - this.logger.info(__("downloading {{packageName}} {{version}}....", {packageName: packageName, version: version})); + this.logger.info(__("Downloading {{packageName}} {{version}}...", {packageName: packageName, version: version})); + + const obsMeasure = new PerformanceObserver((items) => { + let entry; + let strDuration; + + // find any download ongoing measurements we've made + entry = _.last(_.where(items.getEntries(), {name: downloadOngoing})); + if(entry){ + // ongoing performance mark + strDuration = __('Still downloading {{packageName}} {{version}}... ({{duration}}ms elapsed)', {packageName: packageName, version: version, duration: entry.duration}); + } + else{ + // otherwise, find our download complete measurement + entry = _.last(_.where(items.getEntries(), {name: downloadComplete})); + + if(entry){ + strDuration = __('Finished downloading {{packageName}} {{version}} in {{duration}}ms', {packageName: packageName, version: version, duration: entry.duration}); + performance.clearMarks(); + } + } + + // log our measurement and make it red if it has taken too long + if(entry && strDuration){ + if(entry.duration > 1000){ + strDuration = strDuration.red; + } + this.logger.info(strDuration); + } + + }); + obsMeasure.observe({entryTypes: ['measure']}); + + // define mark and measurement names + let startMark = 'downloadStart' + packageName + version; + let ongoingMark = 'downloadOngoingMark' + packageName + version; + let downloadOngoing = 'downloadOngoing' + packageName + version; + let endMark = 'downloadEnd' + packageName + version; + let downloadComplete = 'downloadComplete' + packageName + version; + + // mark our start time + performance.mark(startMark); + + // function that continually updates the console to show user that we're downloading a library + let intOngoingDownload = setInterval( + function(){ + performance.mark(ongoingMark); + performance.measure(downloadOngoing, startMark, ongoingMark); + }, 750); + + // do the package download/install manager.install(packageName, version).then((result) => { + // stop updating console for ongoing download + clearInterval(intOngoingDownload); + performance.mark(endMark); + performance.measure(downloadComplete, startMark, endMark); callback(null , result.location); }).catch(callback); } From 7e2f5624ba79ef83d0ade1186eb8f728bce2d20d Mon Sep 17 00:00:00 2001 From: emizzle Date: Wed, 6 Jun 2018 12:04:30 +1000 Subject: [PATCH 3/3] Increased time before reporting of library download duration goes red to 4 seconds. Incrased travis build version to node 8, as embark only supports 8.10, and also perf_hooks requires 8.5 --- .travis.yml | 2 +- lib/versions/npm.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1019d91d..b9912bde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - "7" + - "8" addons: code_climate: repo_token: 7454b1a666015e244c384d19f48c34e35d1ae58c3aa428ec542f10bbcb848358 diff --git a/lib/versions/npm.js b/lib/versions/npm.js index f7ca1751..0f245f78 100644 --- a/lib/versions/npm.js +++ b/lib/versions/npm.js @@ -43,7 +43,7 @@ class Npm { // log our measurement and make it red if it has taken too long if(entry && strDuration){ - if(entry.duration > 1000){ + if(entry.duration > 4000){ strDuration = strDuration.red; } this.logger.info(strDuration);