Profiler tick processor: exploit d8's readline to avoid reading
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 8 Feb 2010 08:15:18 +0000 (08:15 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 8 Feb 2010 08:15:18 +0000 (08:15 +0000)
entire file prior to parsing it. This allows processing of huge
log files (over 200 MB.)

Review URL: http://codereview.chromium.org/574015

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3811 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

tools/linux-tick-processor
tools/logreader.js
tools/tickprocessor.js
tools/windows-tick-processor.bat

index ca1c721..1715705 100755 (executable)
@@ -16,8 +16,17 @@ else
   [ -x $d8_exec ] || scons -j4 -C $D8_PATH -Y $tools_path/.. d8
 fi
 
+# find the name of the log file to process, it must not start with a dash.
+log_file="v8.log"
+for arg in "$@"
+do
+  if [[ "${arg}" != -* ]]; then
+    log_file=${arg}
+  fi
+done
+
 # nm spits out 'no symbols found' messages to stderr.
-$d8_exec $tools_path/splaytree.js $tools_path/codemap.js \
+cat $log_file | $d8_exec $tools_path/splaytree.js $tools_path/codemap.js \
   $tools_path/csvparser.js $tools_path/consarray.js \
   $tools_path/profile.js $tools_path/profile_view.js \
   $tools_path/logreader.js $tools_path/tickprocessor.js \
index 20a1f54..b2aca73 100644 (file)
@@ -76,6 +76,18 @@ devtools.profiler.LogReader = function(dispatchTable) {
    * @type {Array.<string>}
    */
   this.backRefs_ = [];
+
+  /**
+   * Current line.
+   * @type {number}
+   */
+  this.lineNum_ = 0;
+
+  /**
+   * CSV lines parser.
+   * @type {devtools.profiler.CsvParser}
+   */
+  this.csvParser_ = new devtools.profiler.CsvParser();
 };
 
 
@@ -136,6 +148,16 @@ devtools.profiler.LogReader.prototype.processLogChunk = function(chunk) {
 
 
 /**
+ * Processes a line of V8 profiler event log.
+ *
+ * @param {string} line A line of log.
+ */
+devtools.profiler.LogReader.prototype.processLogLine = function(line) {
+  this.processLog_([line]);
+};
+
+
+/**
  * Processes stack record.
  *
  * @param {number} pc Program counter.
@@ -280,25 +302,20 @@ devtools.profiler.LogReader.prototype.processAlias_ = function(
  * @private
  */
 devtools.profiler.LogReader.prototype.processLog_ = function(lines) {
-  var csvParser = new devtools.profiler.CsvParser();
-  try {
-    for (var i = 0, n = lines.length; i < n; ++i) {
-      var line = lines[i];
-      if (!line) {
-        continue;
-      }
+  for (var i = 0, n = lines.length; i < n; ++i, ++this.lineNum_) {
+    var line = lines[i];
+    if (!line) {
+      continue;
+    }
+    try {
       if (line.charAt(0) == '#' ||
           line.substr(0, line.indexOf(',')) in this.backRefsCommands_) {
         line = this.expandBackRef_(line);
       }
-      var fields = csvParser.parseLine(line);
+      var fields = this.csvParser_.parseLine(line);
       this.dispatchLogRow_(fields);
-    }
-  } catch (e) {
-    // An error on the last line is acceptable since log file can be truncated.
-    if (i < n - 1) {
-      this.printError('line ' + (i + 1) + ': ' + (e.message || e));
-      throw e;
+    } catch (e) {
+      this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e));
     }
   }
 };
index 73bdf35..a40d95d 100644 (file)
@@ -262,8 +262,10 @@ TickProcessor.prototype.isJsCode = function(name) {
 
 TickProcessor.prototype.processLogFile = function(fileName) {
   this.lastLogFileName_ = fileName;
-  var contents = readFile(fileName);
-  this.processLogChunk(contents);
+  var line;
+  while (line = readline()) {
+    this.processLogLine(line);
+  }
 };
 
 
index 6743f68..33b1f77 100755 (executable)
@@ -2,4 +2,28 @@
 
 SET tools_dir=%~dp0
 
-%tools_dir%..\d8 %tools_dir%splaytree.js %tools_dir%codemap.js %tools_dir%csvparser.js %tools_dir%consarray.js %tools_dir%profile.js %tools_dir%profile_view.js %tools_dir%logreader.js %tools_dir%tickprocessor.js %tools_dir%tickprocessor-driver.js -- --windows %*
+SET log_file=v8.log
+
+rem find the name of the log file to process, it must not start with a dash.
+rem we prepend cmdline args with a number (in fact, any letter or number)
+rem to cope with empty arguments.
+SET arg1=1%1
+IF NOT %arg1:~0,2% == 1 (IF NOT %arg1:~0,2% == 1- SET log_file=%1)
+SET arg2=2%2
+IF NOT %arg2:~0,2% == 2 (IF NOT %arg2:~0,2% == 2- SET log_file=%2)
+SET arg3=3%3
+IF NOT %arg3:~0,2% == 3 (IF NOT %arg3:~0,2% == 3- SET log_file=%3)
+SET arg4=4%4
+IF NOT %arg4:~0,2% == 4 (IF NOT %arg4:~0,2% == 4- SET log_file=%4)
+SET arg5=5%5
+IF NOT %arg5:~0,2% == 5 (IF NOT %arg5:~0,2% == 5- SET log_file=%5)
+SET arg6=6%6
+IF NOT %arg6:~0,2% == 6 (IF NOT %arg6:~0,2% == 6- SET log_file=%6)
+SET arg7=7%7
+IF NOT %arg7:~0,2% == 7 (IF NOT %arg7:~0,2% == 7- SET log_file=%7)
+SET arg8=8%8
+IF NOT %arg8:~0,2% == 8 (IF NOT %arg8:~0,2% == 8- SET log_file=%8)
+SET arg9=9%9
+IF NOT %arg9:~0,2% == 9 (IF NOT %arg9:~0,2% == 9- SET log_file=%9)
+
+type %log_file% | %tools_dir%..\d8 %tools_dir%splaytree.js %tools_dir%codemap.js %tools_dir%csvparser.js %tools_dir%consarray.js %tools_dir%profile.js %tools_dir%profile_view.js %tools_dir%logreader.js %tools_dir%tickprocessor.js %tools_dir%tickprocessor-driver.js -- --windows %*