v8/test/mjsunit/tools/codemap.js
mikhail.naganov@gmail.com aa2c33126c TickProcessor script reimplemented in JavaScript.
This is an effort to reuse profiler data processing code both in
TickProcessor and Dev Tools Profiler. The old Python implementation
will be removed.

The new TickProcessor works almost identical to the previous one.
However, it has some differences:

1. Not very useful "Call profile" section is replaced with a new
   WebKit-like "Bottom up (heavy) profile" which shows the most
   expensive functions together with their callers. I used it
   personally in order to find and remove bottlenecks in the
   tickprocessor script itself, and found it quite helpful.

2. Code entries with duplicate names (they occur for RegExes, stubs
   and sometimes for anonymous Function objects) are now distinguished
   by adding an occurence number inside curly brackets.

3. (Address -> code entry) mapping is more precise in boundary cases.

4. Windows version no more requires specifying .map file location.

5. Works faster.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1802 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-04-27 13:50:42 +00:00

127 lines
5.2 KiB
JavaScript

// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Load Splay tree and CodeMap implementations from <project root>/tools.
// Files: tools/splaytree.js tools/codemap.js
function newCodeEntry(size, name) {
return new devtools.profiler.CodeMap.CodeEntry(size, name);
};
function assertEntry(codeMap, expected_name, addr) {
var entry = codeMap.findEntry(addr);
assertNotNull(entry, 'no entry at ' + addr.toString(16));
assertEquals(expected_name, entry.name, 'at ' + addr.toString(16));
};
function assertNoEntry(codeMap, addr) {
assertNull(codeMap.findEntry(addr), 'at ' + addr.toString(16));
};
(function testStaticCode() {
var codeMap = new devtools.profiler.CodeMap();
codeMap.addStaticCode(0x1500, newCodeEntry(0x3000, 'lib1'));
codeMap.addStaticCode(0x15500, newCodeEntry(0x5000, 'lib2'));
codeMap.addStaticCode(0x155500, newCodeEntry(0x10000, 'lib3'));
assertNoEntry(codeMap, 0);
assertNoEntry(codeMap, 0x1500 - 1);
assertEntry(codeMap, 'lib1', 0x1500);
assertEntry(codeMap, 'lib1', 0x1500 + 0x100);
assertEntry(codeMap, 'lib1', 0x1500 + 0x1000);
assertEntry(codeMap, 'lib1', 0x1500 + 0x3000 - 1);
assertNoEntry(codeMap, 0x1500 + 0x3000);
assertNoEntry(codeMap, 0x15500 - 1);
assertEntry(codeMap, 'lib2', 0x15500);
assertEntry(codeMap, 'lib2', 0x15500 + 0x100);
assertEntry(codeMap, 'lib2', 0x15500 + 0x1000);
assertEntry(codeMap, 'lib2', 0x15500 + 0x5000 - 1);
assertNoEntry(codeMap, 0x15500 + 0x5000);
assertNoEntry(codeMap, 0x155500 - 1);
assertEntry(codeMap, 'lib3', 0x155500);
assertEntry(codeMap, 'lib3', 0x155500 + 0x100);
assertEntry(codeMap, 'lib3', 0x155500 + 0x1000);
assertEntry(codeMap, 'lib3', 0x155500 + 0x10000 - 1);
assertNoEntry(codeMap, 0x155500 + 0x10000);
assertNoEntry(codeMap, 0xFFFFFFFF);
})();
(function testDynamicCode() {
var codeMap = new devtools.profiler.CodeMap();
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
codeMap.addCode(0x1900, newCodeEntry(0x50, 'code3'));
codeMap.addCode(0x1950, newCodeEntry(0x10, 'code4'));
assertNoEntry(codeMap, 0);
assertNoEntry(codeMap, 0x1500 - 1);
assertEntry(codeMap, 'code1', 0x1500);
assertEntry(codeMap, 'code1', 0x1500 + 0x100);
assertEntry(codeMap, 'code1', 0x1500 + 0x200 - 1);
assertEntry(codeMap, 'code2', 0x1700);
assertEntry(codeMap, 'code2', 0x1700 + 0x50);
assertEntry(codeMap, 'code2', 0x1700 + 0x100 - 1);
assertNoEntry(codeMap, 0x1700 + 0x100);
assertNoEntry(codeMap, 0x1900 - 1);
assertEntry(codeMap, 'code3', 0x1900);
assertEntry(codeMap, 'code3', 0x1900 + 0x28);
assertEntry(codeMap, 'code4', 0x1950);
assertEntry(codeMap, 'code4', 0x1950 + 0x7);
assertEntry(codeMap, 'code4', 0x1950 + 0x10 - 1);
assertNoEntry(codeMap, 0x1950 + 0x10);
assertNoEntry(codeMap, 0xFFFFFFFF);
})();
(function testCodeMovesAndDeletions() {
var codeMap = new devtools.profiler.CodeMap();
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
assertEntry(codeMap, 'code1', 0x1500);
assertEntry(codeMap, 'code2', 0x1700);
codeMap.moveCode(0x1500, 0x1800);
assertNoEntry(codeMap, 0x1500);
assertEntry(codeMap, 'code2', 0x1700);
assertEntry(codeMap, 'code1', 0x1800);
codeMap.deleteCode(0x1700);
assertNoEntry(codeMap, 0x1700);
assertEntry(codeMap, 'code1', 0x1800);
})();
(function testDynamicNamesDuplicates() {
var codeMap = new devtools.profiler.CodeMap();
// Code entries with same names but different addresses.
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code'));
assertEntry(codeMap, 'code', 0x1500);
assertEntry(codeMap, 'code {1}', 0x1700);
})();