cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [1/2] docs commit: Added --timing switch (closes #252)
Date Mon, 05 Jan 2015 15:24:11 GMT
Repository: cordova-docs
Updated Branches:
  refs/heads/master a9639bd16 -> 7bd3f8d38


Added --timing switch (closes #252)

As a side effect all generated content is not cleared, so it could be generated in two steps
in case of failure


Project: http://git-wip-us.apache.org/repos/asf/cordova-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-docs/commit/4137aec0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-docs/tree/4137aec0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-docs/diff/4137aec0

Branch: refs/heads/master
Commit: 4137aec0e433c4a3baafc8f338b4d8622f10ea45
Parents: a9639bd
Author: Andrey Kurdyumov <kant2002@gmail.com>
Authored: Mon Jan 5 18:06:16 2015 +0600
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Jan 5 10:22:02 2015 -0500

----------------------------------------------------------------------
 .gitignore            |   1 +
 bin/genjs             |   5 +-
 lib/docs_generator.js | 151 ++++++++++++++++++++++++++++++++-------------
 3 files changed, 114 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/4137aec0/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index acdbf02..0f60d79 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
 .DS_Store
 tmp/
 node_modules/
+v8.log
 public/
 release/
 TAGS

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/4137aec0/bin/genjs
----------------------------------------------------------------------
diff --git a/bin/genjs b/bin/genjs
index e7eb35b..39081c5 100755
--- a/bin/genjs
+++ b/bin/genjs
@@ -25,10 +25,13 @@ var yargs = require('yargs')
     .describe('edge', 'Generate edge version of English docs')
     .count("verbose")
     .alias('v', 'verbose')
+    .describe('timing', 'Species level of timing measurements. If level not provided level
0 is used.')
     .describe('verbose', 'Increase verbosity level of produced output')
     .describe('source', 'Path to the documentation sources. Default: docs')
     .describe('out', 'Path where documentation would be generated. Default: public')
     .example('./bin/genjs --out public/test en', 'Generates English docs in the directory
public/test')
+    .example('./bin/genjs --timing', 'Basic timing measurements')
+    .example('./bin/genjs --timing 1', 'Detailed timing measurements')
     .usage('Usage: $0 [-v] [...options] [--edge] [lang] [version]\n' +
         '    <lang>: Language for which generate docs. If not specified then generate
for all languages.\n' +
         '    <version>: Version for which generate docs. If not specified then generate
all versions.');
@@ -61,4 +64,4 @@ if (argv.edge) {
     }
 }
 
-new generator(argv.source, argv.out).run(language, version, argv.verbose);
\ No newline at end of file
+new generator(argv.source, argv.out).run(language, version, argv.verbose, !!argv.timing);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/4137aec0/lib/docs_generator.js
----------------------------------------------------------------------
diff --git a/lib/docs_generator.js b/lib/docs_generator.js
index c5f6758..8a6bdc8 100644
--- a/lib/docs_generator.js
+++ b/lib/docs_generator.js
@@ -66,74 +66,107 @@ var DocsGenerator = (function () {
     *   - Pre-file processing
     *   - Release and cleanup
     */
-    DocsGenerator.prototype.run = function (language, version, verbose_mode) {
+    DocsGenerator.prototype.run = function (language, version, verbose_mode, timing) {
         var self = this,
             ignore_list = ['.', '..', '.DS_Store'];
 
         verbose_mode = verbose_mode || 0;
         if (verbose_mode > 0) {
             console.log("Generating docs for lang " + language + " and version " + version);
-            console.log("Clearing output directory");
+            // console.log("Clearing output directory");
             if (verbose_mode > 1) {
                 console.log("Sources directory: " + this.input_directory);
                 console.log("Output directory: " + this.output_directory);
             }
         }
 
-        fs.removeSync(this.output_directory);
+        // fs.removeSync(this.output_directory);
 
-        fs.readdirSync(this.input_directory).forEach(function (language_dir) {
-            if (ignore_list.indexOf(language_dir) !== -1) {
-                return;
-            }
-
-            if (language && language_dir !== language) {
-                return;
-            }
-
-            var language_path = path.join(self.input_directory, language_dir);
-
-            fs.readdirSync(language_path).forEach(function (version_dir) {
-                if (ignore_list.indexOf(version_dir) !== -1) {
+        self.options = {
+            verbose: verbose_mode,
+            timing: timing
+        };
+        self.captureExecutionTime("Generate all docs", 0, function () {
+            fs.readdirSync(this.input_directory).forEach(function (language_dir) {
+                if (ignore_list.indexOf(language_dir) !== -1) {
                     return;
                 }
 
-                if (version && version_dir !== version) {
+                if (language && language_dir !== language) {
                     return;
                 }
 
-                var output_path = path.join(self.output_directory, language_dir, version_dir),
-                    input_path = path.join(self.input_directory, language_dir, version_dir),
-                    options = {
-                        lang: language_dir,
-                        version: version_dir,
-                        verbose: verbose_mode
+                var language_path = path.join(self.input_directory, language_dir);
+
+                fs.readdirSync(language_path).forEach(function (version_dir) {
+                    if (ignore_list.indexOf(version_dir) !== -1) {
+                        return;
+                    }
+
+                    if (version && version_dir !== version) {
+                        return;
+                    }
+
+                    var output_path = path.join(self.output_directory, language_dir, version_dir),
+                        input_path = path.join(self.input_directory, language_dir, version_dir),
+                        options = {
+                            lang: language_dir,
+                            version: version_dir,
+                            verbose: verbose_mode,
+                            timing: timing
+                        };
+                    self.options = options;
+                    console.log(" => Generating the Cordova Documentation for " + version_dir
+ "-" + language_dir + "...");
+                    self.captureExecutionTime("Generate docs for " + version_dir + "-" +
language_dir, 0, function () {
+                        self.process(input_path, output_path, options);
+                    });
+                    self.options = {
+                        verbose: verbose_mode,
+                        timing: timing
                     };
-
-                console.log(" => Generating the Cordova Documentation for " + version_dir
+ "-" + language_dir + "...");
-                self.process(input_path, output_path, options);
+                });
             });
         });
     };
 
     DocsGenerator.prototype.process = function (input_path, output_path, options) {
-        fs.copySync(input_path, this.working_directory);
-
+        if (options.verbose > 0) {
+            console.log("Clearing output directory for lang " + options.lang + " and version
" + options.version);
+            if (options.verbose > 1) {
+                console.log("Output directory: " + output_path);
+            }
+        }
+        
+        this.captureExecutionTime("Removing lang output directory", 1, function () {
+            fs.removeSync(output_path);
+        });
+        this.captureExecutionTime("Copy source files to temp", 1, function () {
+            fs.copySync(input_path, this.working_directory);
+        });
+        
         var preprocessPath,
             processPath,
             generated_path;
-        preprocessPath = this.before_jodoc(this.working_directory, options);
-        processPath = this.jodocify(preprocessPath, options);
-        generated_path = this.after_jodoc(processPath, options);
-
-        fs.ensureDirSync(path.dirname(output_path));
-        fs.renameSync(generated_path, output_path);
-
-        fs.removeSync(FileHelpers.getTmpDirectory());
+        this.captureExecutionTime("Pre processing docs", 1, function () {
+            preprocessPath = this.before_jodoc(this.working_directory, options);
+        });
+        this.captureExecutionTime("joDoc-ify", 1, function () {
+            processPath = this.jodocify(preprocessPath, options);
+        });
+        this.captureExecutionTime("Post processing docs", 1, function () {
+            generated_path = this.after_jodoc(processPath, options);
+        });
+        
+        this.captureExecutionTime("Moving to results folder", 1, function () {
+            fs.ensureDirSync(path.dirname(output_path));
+            fs.renameSync(generated_path, output_path);
+            fs.removeSync(FileHelpers.getTmpDirectory());
+        });
     };
 
     DocsGenerator.prototype.run_process_sequence = function (sequence_name, source_path,
options) {
-        var currentModuleDir = path.dirname(module.filename),
+        var self = this,
+            currentModuleDir = path.dirname(module.filename),
             directoryEntries,
             sequenceProcessors,
             processors;
@@ -143,12 +176,14 @@ var DocsGenerator = (function () {
             return new ProcessorConstructor(options);
         });
         processors.forEach(function (process_module) {
-            if (options.verbose > 0) {
-                console.log("Stage: " + process_module.stage);
-            }
+            self.captureExecutionTime("Processor: " + process_module.stage, 1, function ()
{
+                if (options.verbose > 0) {
+                    console.log("Stage: " + process_module.stage);
+                }
 
-            processEachFile(source_path, function (filename) {
-                process_module.run(filename);
+                processEachFile(source_path, function (filename) {
+                    process_module.run(filename);
+                });
             });
         });
 
@@ -174,6 +209,38 @@ var DocsGenerator = (function () {
         this.run_process_sequence("post", source_path, options);
         return source_path;
     };
+    
+    DocsGenerator.prototype.captureExecutionTime = function (step_name, level, callback)
{
+        var startDate,
+            finishDate,
+            timingLevel = -1,
+            secondsPassed;
+        if (this.options.timing) {
+            if (this.options.timing === true) {
+                timingLevel = 0;
+            } else {
+                timingLevel = this.options.timing;
+            }
+        }
+        
+        if (timingLevel >= level) {
+            startDate = new Date();
+            if (this.options.verbose > 0) {
+                console.log(startDate, "Start " + step_name);
+            }
+        }
+        
+        callback.apply(this);
+        if (timingLevel >= level) {
+            finishDate = new Date();
+            if (this.options.verbose > 0) {
+                console.log(finishDate, "Finish " + step_name);
+            }
+            
+            secondsPassed = (finishDate.valueOf() - startDate.valueOf()) / 1000;
+            console.log(step_name + ". Total time: ", secondsPassed);
+        }
+    };
 
     return DocsGenerator;
 }());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message