Repository: axemclion/perfjankie Branch: master Commit: 23c65ac3c8b4 Files: 71 Total size: 106.6 KB Directory structure: gitextract_r04kxl2y/ ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── Gruntfile.js ├── README.md ├── bower.json ├── lib/ │ ├── cli.js │ ├── couch-views/ │ │ ├── metrics_data.js │ │ ├── pagelist.js │ │ └── runs.js │ ├── couchData.js │ ├── couchSite.js │ ├── couchViews.js │ ├── index.js │ ├── init.js │ ├── mime.js │ ├── options.js │ ├── perfTests.js │ └── utils.js ├── migrations/ │ ├── cli.js │ ├── index.js │ ├── migrate-0.2.0.js │ ├── migrate-0.3.0.js │ ├── migrate-0.4.0.js │ └── utility.js ├── package.json ├── tasks/ │ ├── metricsgen.js │ └── task.js ├── test/ │ ├── index.spec.js │ ├── res/ │ │ ├── local.config.json │ │ ├── sample-perf-results.json │ │ ├── test1.html │ │ └── test2.html │ ├── seedData.js │ └── util.js └── www/ ├── app/ │ ├── all-metrics/ │ │ ├── all-metrics.html │ │ ├── all-metrics.less │ │ └── allmetrics.js │ ├── app.js │ ├── backend.js │ ├── font.less │ ├── main-page/ │ │ ├── error.less │ │ ├── navbar.html │ │ ├── navbar.less │ │ ├── no-pj-brand.less │ │ ├── sidebar.html │ │ ├── sidebar.js │ │ └── sidebar.less │ ├── main.less │ ├── metric-details/ │ │ ├── metric-detail.html │ │ ├── metric-detail.less │ │ ├── metricDetail.js │ │ └── metricDetailsGraph.js │ ├── page-select/ │ │ ├── page-select.html │ │ ├── page-select.less │ │ └── pageSelect.js │ └── summary/ │ ├── networkTimingGraph.js │ ├── paintCycleGraph.js │ ├── summary.html │ ├── summary.js │ ├── summary.less │ ├── tiles.js │ ├── tiles.less │ └── tiles.tpl.html ├── assets/ │ ├── css/ │ │ ├── animation.css │ │ ├── config.json │ │ └── fontello-codes.css │ └── fonts/ │ └── fontello-codes.css ├── index.html └── server/ └── endpoints.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ node_modules/ bower_components/ bin/ bin-site/ *.log .DS_Store .idea/* .tmp/* dist/* _replicator/* _users/* pouch__all_dbs__/* version/* log.txt ================================================ FILE: .jshintrc ================================================ { "curly": true, "eqeqeq": true, "immed": true, "latedef": true, "newcap": true, "noarg": true, "sub": true, "undef": true, "boss": true, "eqnull": true, "node": true, "shadow": true, "expr": true, "globals": { "angular": false, "$": false, "window": false, "ENDPOINTS": false, "describe": false, "it": false, "beforeEach": false, "before": false, "xit": false, "xdescribe": false } } ================================================ FILE: .npmignore ================================================ node_modules/ bower_components/ Gruntfile.js test/ www/ bower.json .jshintrc .gitignore ================================================ FILE: .travis.yml ================================================ sudo: false language: node_js node_js: - "0.12" - "4.0" - "4.3" - "4" - "5.0" - "5" - "6" - "stable" env: - NPM_VERSION=2 - NPM_VERSION=3 services: couchdb before_install: - npm install -g npm@$NPM_VERSION - npm install -g grunt-cli before_script: - npm install - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" - sleep 3 # give xvfb some time to start script: npm test ================================================ FILE: Gruntfile.js ================================================ module.exports = function(grunt) { var couchdb = require('./test/util').config({ log: 1 }).couch; var serveStatic = require('serve-static'); var path = require('path'); var jqplot = [ 'jquery.jqplot.min.js', 'plugins/jqplot.categoryAxisRenderer.min.js', 'plugins/jqplot.highlighter.min.js', 'plugins/jqplot.canvasTextRenderer.min.js', 'plugins/jqplot.canvasAxisTickRenderer.min.js', 'plugins/jqplot.canvasAxisLabelRenderer.min.js', 'plugins/jqplot.barRenderer.min.js', 'plugins/jqplot.trendline.min.js', 'plugins/jqplot.pieRenderer.min.js' ]; grunt.initConfig({ jshint: { all: [ 'Gruntfile.js', 'lib/*.js', 'test/**/*.js', 'www/**/*.js' ], options: { jshintrc: '.jshintrc' }, }, metricsgen: { files: { dest: 'bin-site/metrics.js' } }, uglify: { options: { mangle: false, sourceMap: true, sourceMapName: 'bin-site/main.js.map', }, js: { files: { 'bin-site/main.js': ['www/**/*.js', 'bin-site/**/*.js'] } } }, concat: { jqplot: { src: jqplot.map(function(file) { return 'bower_components/jqplot-bower/dist/' + file; }), dest: 'bin-site/jqplot.js' }, less: { src: ['bower_components/jqplot-bower/dist/jquery.jqplot.min.css', 'www/app/**/*.less', 'www/assets/css/*.css'], dest: 'bin-site/main.less' } }, less: { dev: { files: { 'bin-site/main.css': 'bin-site/main.less' } }, dist: { options: { compress: true }, files: { 'bin-site/main.css': 'bin-site/main.less' } } }, autoprefixer: { less: { src: 'bin-site/main.css', dest: 'bin-site/main.css' } }, copy: { partials: { expand: true, cwd: 'www/app', src: ['**/*.html'], dest: 'bin-site/app' }, fonts: { expand: true, cwd: 'www/assets', src: ['fonts/*.*'], dest: 'bin-site/assets' }, endpoints: { src: ['www/server/endpoints.js'], dest: 'bin-site/server/endpoints.js' } }, processhtml: { dev: { options: { strip: true, data: { scripts: jqplot.map(function(file) { return 'jqplot-bower/dist/' + file; }).concat(grunt.file.expand({ cwd: 'www' }, 'app/**/*.js')), } }, files: { 'bin-site/index.html': 'www/index.html' } }, dist: { options: { data: { scripts: ['main.js'] } }, files: { 'bin-site/index.html': 'www/index.html' } } }, htmlmin: { dist: { options: { removeComments: true, collapseWhitespace: true, conservativeCollapse: true, collapseBooleanAttributes: true }, files: { 'bin-site/index.html': 'bin-site/index.html' } }, }, connect: { proxies: [{ changeOrigin: false, host: 'localhost', port: '5984', context: grunt.file.expand('lib/couch-views/**/*.js').map(function(file) { return '/' + path.basename(file, '.js'); }), rewrite: (function(files) { var res = {}; files.forEach(function(file) { var view = path.basename(file, '.js'); res[view + '/_view'] = ['/', couchdb.database, '/_design/', view, '/_view'].join(''); }); return res; }(grunt.file.expand('lib/couch-views/**/*.js'))) }], dev: { options: { hostname: '*', port: 9000, base: ['test/res', 'bower_components', 'bin-site', 'www'], livereload: true, middleware: function(connect, options) { var middlewares = []; if (!Array.isArray(options.base)) { options.base = [options.base]; } middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest); options.base.forEach(function(base) { middlewares.push(serveStatic(base)); }); return middlewares; }, useAvailablePort: true, } } }, watch: { options: { livereload: true, }, views: { files: ['lib/couch-views/*.js'], tasks: ['deployViews'] }, less: { files: ['www/**/*.less'], tasks: ['concat:less', 'less:dev', 'autoprefixer'] }, html: { files: ['www/index.html'], tasks: ['processhtml:dev'] }, others: { files: ['www/app/**/*.html', 'www/app/**/*.js'], tasks: [] } }, mochaTest: { options: { reporter: 'dot', timeout: 1000 * 60 * 10 }, unit: { src: ['test/**/*.spec.js'], } }, clean: { all: ['bin-site', 'test.log'], dist: ['bin-site/jqplot.js', 'bin-site/main.less', 'bin-site/metrics.js'] } }); require('load-grunt-tasks')(grunt); require('./tasks/metricsgen')(grunt); grunt.registerTask('seedData', function() { var done = this.async(); require('./test/seedData')(done, 100); }); grunt.registerTask('deployViews', function() { var done = this.async(); require('./lib/couchViews')(require('./test/util.js').config(), function(err, res) { console.log(err, res); done(!err); }); }); grunt.registerTask('dev', ['metricsgen', 'concat:less', 'less:dev', 'autoprefixer', 'processhtml:dev', 'configureProxies:server', 'connect:dev', 'watch']); grunt.registerTask('dist', ['jshint', 'concat', 'metricsgen', 'uglify', 'less:dist', 'autoprefixer', 'copy', 'processhtml:dist', 'htmlmin', 'clean:dist']); grunt.registerTask('test', ['clean', 'dist', 'mochaTest']); grunt.registerTask('default', ['dev']); }; ================================================ FILE: README.md ================================================ # perfjankie PerfJankie is a tool to monitor smoothness and responsiveness of websites and Cordova/Hybrid apps over time. It runs performance tests using [browser-perf](http://github.com/axemclion/browser-perf) and saves the results in a CouchDB server. It also has a dashboard that displays graphs of the performance metrics collected over time that you help identify performance trends, or locate a single commit that can slow down a site. After running the tests, navigate to the following url to see the results dashboard. > http://couchdb.serverl.url/databasename/_design/site/index.html Here is a [dashboard](http://nparashuram.com/perfslides/perfjankie) created from a [sample project](http://github.com/axemclion/perfslides). ![Perfjankie sample dashboard](http://i.imgur.com/3VO8T4C.png "A sample dashboard for perfjankie") ## Why ? Checking for performance regressions is hard. Though most modern browsers have excellent performance measurement tools, it is hard for a developer to check these tools for every commit. Just as unit tests check for regressions in functionality, perfjankie will help with checking regressions in browser rendering performance when integrated into systems like Travis or Jenkins. The results dashboard ## Setup Perfjankie requires Selenium as the driver to run tests and CouchDB to store the results. Since this is based on browser-perf, look at [setting up browser-perf](https://github.com/axemclion/browser-perf/wiki/Setup-Instructions) for more information. ## Usage Perfjankie can be used as a node module, from the command line, or as a Grunt task and can be installed from npm using `npm install perfjankie`. ### Node Module The API call looks like the following ```javascript var perfjankie = require('perfjankie'); perfjankie({ "url": "http://localhost:9000/testpage.html", // URL of the page that you would like to test. /* The next set of values identify the test */ name: "Component or Webpage Name", // A friendly name for the URL. This is shown as component name in the dashboard suite: "optional suite name", // Displayed as the title in the dashboard. Only 1 suite name for all components time: new Date().getTime(), // Used to sort the data when displaying graph. Can be the time when a commit was made run: "commit#Hash", // A hash for the commit, displayed in the x-axis in the dashboard repeat: 3, // Run the tests 3 times. Default is 1 time /* Identifies where the data and the dashboard are saved */ couch: { server: 'http://localhost:5984', requestOptions : { "proxy" : "http://someproxy" }, // optional, e.g. useful for http basic auth, see Please check [request] for more information on the defaults. They support features like cookie jar, proxies, ssl, etc. database: 'performance', updateSite: !process.env.CI, // If true, updates the couchApp that shows the dashboard. Set to false in when running Continuous integration, run this the first time using command line. onlyUpdateSite: false // No data to upload, just update the site. Recommended to do from dev box as couchDB instance may require special access to create views. }, callback: function(err, res) { // The callback function, err is falsy if all of the following happen // 1. Browsers perf tests ran // 2. Data has been saved in couchDB // err is not falsy even if update site fails. }, /* OPTIONS PASSED TO BROWSER-PERF */ // Properties identifying the test environment */ browsers: [{ // This can also be a ["chrome", "firefox"] or "chrome,firefox" browserName: "chrome", version: 32, platform: "Windows 8.1" }], // See browser perf browser configuration for all options. selenium: { hostname: "ondemand.saucelabs.com", // or localhost or hub.browserstack.com port: 80, }, BROWSERSTACK_USERNAME: process.env.BROWSERSTACK_USERNAME, // If using browserStack BROWSERSTACK_KEY: process.env.BROWSERSTACK_KEY, // If using browserStack, this is automatically added to browsers object SAUCE_USERNAME: process.env.SAUCE_USERNAME, // If using Saucelabs SAUCE_ACCESSKEY: process.env.SAUCE_ACCESSKEY, // If using Saucelabs /* A way to log the information - can be bunyan, or grunt logs. */ log: { // Expects the following methods, fatal: grunt.fail.fatal.bind(grunt.fail), error: grunt.fail.warn.bind(grunt.fail), warn: grunt.log.error.bind(grunt.log), info: grunt.log.ok.bind(grunt.log), debug: grunt.verbose.writeln.bind(grunt.verbose), trace: grunt.log.debug.bind(grunt.log) } }); ``` Other options that can be passed include `preScript`, `actions`, `metrics`, `preScriptFile`, etc. Note that most of these options are similar to the options passed to browser-perf. Refer to the [browser-perf options](https://github.com/axemclion/browser-perf/wiki/Node-Module---API) for a mode detailed explanation. ### Grunt Task To run perfjankie as a Grunt task, simple load task using `grunt.loadNpmTasks('perfjankie');`, define a `perfjankie` task and pass in all the options from above as options to the Grunt task. [Here](https://github.com/axemclion/perfslides/blob/38b4f6e246c5ab971ce2957ec78bb701dbbc3038/Gruntfile.js#L57) is an example. ### Command line Run `perfjankie --help` to see a list of all the options. Quick Note - to only update site the first time, run the following from the command line. You need to quote the URL to work with parameters, e.g. https://www.google.de/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=angular ```bash $ perfjankie --config-file=local.config.json --only-update-site 'example.com' ``` Or without a config file ```bash $ perfjankie --couch-server=http://localhost:5984 --couch-database=perfjankie-test --couch-user=admin_user --couch-pwd=admin_pass --name=Google 'https://www.google.de/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=angular' ``` The config file can contain server configuration and can look like [this](https://github.com/axemclion/perfjankie/blob/master/test/res/local.config.json). ## Hosting dashboard on a different server You can also host the HTML/CSS/JS for displaying the results dashboard on not on CouchDB, but a different static server, possibly behind a CDN. In such cases, 1. Use the npm module and host the contents of the `site` folder. 2. Open index.html and insert the following snippet in the `` section ```html ``` This will ensure that all requests for data are made to the other CouchDB server. Also ensure that the CouchDB server has CORS turned on. ## Login before running tests You can login a user, or perform other kinds of page setup using the [preScript](https://github.com/axemclion/browser-perf/wiki/Node-Module---API#prescript) or the [preScriptFile](https://github.com/axemclion/browser-perf/wiki/Node-Module---API#prescriptfile) options. Here is an [example](https://github.com/axemclion/browser-perf/wiki/FAQ#how-can-i-test-a-page-that-requires-login) of a login action that can be passed in the preScript option. ## Migrating data from older versions If you have older data and want to move to the latest release of perfjankie, you may also have to migrate your data. You can migrate from older version of a database to a newer version using ```bash $ perfjankie --config-file=local.config.json --migrate=newDatabaseName ``` This simply transforms all the old data into a format that will work with the newer version of perfjankie. Your version of the database is stored under a document called `version`, and the version supported by your installed version of perfjankie is the key `dbVersion` in the `package.json` ## What does it measure? Perfjankie measures page rendering times. It collects metrics like frame times, page load time, first paint time, scroll time, etc. It can be used on * long, scrollable web pages (like a search result page, an article page, etc). The impact of changes to CSS, sticky headers and scrolling event handlers can be seen in the results. * components (like bootstrap, jQuery UI components, ReactJS components, AngularJS components, etc). Component developers just have to place the component multiple times on a page and will know if they caused perf regressions as they continue developing the component. For more information, see the documentation for [browser-perf](http://github.com/axemclion/browser-perf) # Development ## Dev setup Any changes should be verified with unit tests, see `test`-folder. To run the tests you local couchdb installed with a database, see `test/res/local.config.json` for details: 1. start couchdb 2. start a local selenium grd: `java -jar node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.0.jar -Dwebdriver.chrome.driver=$(pwd)/chromedriver/lib/chromedriver/chromedriver` 3. run tests via `npm test` ================================================ FILE: bower.json ================================================ { "name": "perfjankie", "main": "index.js", "version": "0.0.0", "homepage": "https://github.com/axemclion/perfjankie", "authors": [ "Parashuram " ], "description": "Website for Perfjankie", "license": "MIT", "private": true, "ignore": [ "**/.*", "node_modules", "bower_components", "test", "tests" ], "dependencies": { "angular": "~1.2.18", "bootstrap": "~3.1.1", "jqplot-bower": "~1.0.8", "jquery": "~2.1.1", "angular-route": "~1.2.25" } } ================================================ FILE: lib/cli.js ================================================ #!/usr/bin/env node var program = require('commander'), fs = require('fs'); program .version('0.0.1') .option('-c --config-file ', 'Specify a configuration file. If other options are specified, they have precedence over options in config file') .option('-s, --selenium ', 'Specify Selenium Server, like localhost:4444 or ondemand.saucelabs.com:80', 'localhost:4444') .option('-u --username ', 'Sauce, BrowserStack or Selenium User Name') .option('-a --accesskey ', 'Sauce, BrowserStack or Selenium Access Key') .option('--browsers ', 'List of browsers to run the tests on') .option('--couch-server ', 'Location of the couchDB server') .option('--couch-database ', 'Name of the couch database') .option('--couch-user ', 'Username of the couch user that can create design documents and save data') .option('--couch-pwd ', 'Password of the couchDB user') .option('--name ', 'A friendly name for the URL. This is shown as component name in the dashboard') .option('--run ', 'A hash for the commit, or any identifier displayed in the x-axis in the dashboard') .option('--time