Skip to content

Commit 9d0d5aa

Browse files
Add better consistency check and error output to plot script.
[email protected] BUG= Review URL: https://codereview.chromium.org/23736004 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@16537 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent 0a8ad2d commit 9d0d5aa

File tree

6 files changed

+49
-78
lines changed

6 files changed

+49
-78
lines changed

tools/plot-timer-events

+10-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,13 @@ cat $log_file |
6767
$tools_path/codemap.js $tools_path/profile.js $tools_path/profile_view.js \
6868
$tools_path/logreader.js $tools_path/tickprocessor.js \
6969
$tools_path/profviz/composer.js $tools_path/profviz/stdio.js \
70-
-- $@ $options 2>/dev/null | gnuplot > timer-events.png
70+
-- $@ $options 2>/dev/null > timer-events.plot
71+
72+
success=$?
73+
if [[ $success != 0 ]] ; then
74+
cat timer-events.plot
75+
else
76+
cat timer-events.plot | gnuplot > timer-events.png
77+
fi
78+
79+
rm -f timer-events.plot

tools/profviz/composer.js

+11-62
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Array.prototype.top = function() {
3131
}
3232

3333

34-
function PlotScriptComposer(kResX, kResY) {
34+
function PlotScriptComposer(kResX, kResY, error_output) {
3535
// Constants.
3636
var kV8BinarySuffixes = ["/d8", "/libv8.so"];
3737
var kStackFrames = 8; // Stack frames to display in the plot.
@@ -149,7 +149,10 @@ function PlotScriptComposer(kResX, kResY) {
149149

150150
// Utility functions.
151151
function assert(something, message) {
152-
if (!something) print(new Error(message).stack);
152+
if (!something) {
153+
var error = new Error(message);
154+
error_output(error.stack);
155+
}
153156
}
154157

155158
function FindCodeKind(kind) {
@@ -208,10 +211,15 @@ function PlotScriptComposer(kResX, kResY) {
208211
// Public methods.
209212
this.collectData = function(input, distortion_per_entry) {
210213

214+
var last_timestamp = 0;
215+
211216
// Parse functions.
212217
var parseTimeStamp = function(timestamp) {
218+
int_timestamp = parseInt(timestamp);
219+
assert(int_timestamp >= last_timestamp, "Inconsistent timestamps.");
220+
last_timestamp = int_timestamp;
213221
distortion += distortion_per_entry;
214-
return parseInt(timestamp) / 1000 - distortion;
222+
return int_timestamp / 1000 - distortion;
215223
}
216224

217225
var processTimerEventStart = function(name, start) {
@@ -260,65 +268,6 @@ function PlotScriptComposer(kResX, kResY) {
260268
code_map.deleteCode(address);
261269
};
262270

263-
var processSharedLibrary = function(name, start, end) {
264-
var code_entry = new CodeMap.CodeEntry(end - start, name);
265-
code_entry.kind = -2; // External code kind.
266-
for (var i = 0; i < kV8BinarySuffixes.length; i++) {
267-
var suffix = kV8BinarySuffixes[i];
268-
if (name.indexOf(suffix, name.length - suffix.length) >= 0) {
269-
code_entry.kind = -1; // V8 runtime code kind.
270-
break;
271-
}
272-
}
273-
code_map.addLibrary(start, code_entry);
274-
};
275-
276-
var processTimerEventStart = function(name, start) {
277-
// Find out the thread id.
278-
var new_event = TimerEvents[name];
279-
if (new_event === undefined) return;
280-
var thread_id = new_event.thread_id;
281-
282-
start = Math.max(last_time_stamp[thread_id] + kMinRangeLength, start);
283-
284-
// Last event on this thread is done with the start of this event.
285-
var last_event = event_stack[thread_id].top();
286-
if (last_event !== undefined) {
287-
var new_range = new Range(last_time_stamp[thread_id], start);
288-
last_event.ranges.push(new_range);
289-
}
290-
event_stack[thread_id].push(new_event);
291-
last_time_stamp[thread_id] = start;
292-
};
293-
294-
var processTimerEventEnd = function(name, end) {
295-
// Find out about the thread_id.
296-
var finished_event = TimerEvents[name];
297-
var thread_id = finished_event.thread_id;
298-
assert(finished_event === event_stack[thread_id].pop(),
299-
"inconsistent event stack");
300-
301-
end = Math.max(last_time_stamp[thread_id] + kMinRangeLength, end);
302-
303-
var new_range = new Range(last_time_stamp[thread_id], end);
304-
finished_event.ranges.push(new_range);
305-
last_time_stamp[thread_id] = end;
306-
};
307-
308-
var processCodeCreateEvent = function(type, kind, address, size, name) {
309-
var code_entry = new CodeMap.CodeEntry(size, name);
310-
code_entry.kind = kind;
311-
code_map.addCode(address, code_entry);
312-
};
313-
314-
var processCodeMoveEvent = function(from, to) {
315-
code_map.moveCode(from, to);
316-
};
317-
318-
var processCodeDeleteEvent = function(address) {
319-
code_map.deleteCode(address);
320-
};
321-
322271
var processCodeDeoptEvent = function(time, size) {
323272
deopts.push(new Deopt(time, size));
324273
}

tools/profviz/profviz.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ <h1>
9696
or alternatively,<br/>
9797
Chrome with
9898
<span class="tt">
99-
--no-sandbox --js-flags="--prof --noprof-lazy --log-timer-events
99+
--no-sandbox --js-flags="--prof --log-timer-events"
100100
</span> to produce <span class="tt">v8.log</span>.
101101
</li>
102102
<li>
@@ -117,6 +117,11 @@ <h1>
117117
command-line utility
118118
</a> instead.
119119
</li>
120+
</ol>
121+
If you expect multiple V8 instances to run concurrently, for example
122+
with several tabs in Chrome,<br/>
123+
add the V8 flag <span class="tt">--logfile=v8.%p.log</span>
124+
so that each instance writes to its own log file.
120125
</div>
121126
</div>
122127

tools/profviz/profviz.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ var worker_scripts = [
4242
function plotWorker() {
4343
var worker = null;
4444

45-
var delegateList = {
46-
"log" : log,
47-
"error" : logError,
48-
"displayplot" : displayplot,
49-
"displayprof" : displayprof,
50-
"range" : setRange,
51-
"script" : scriptLoaded
52-
}
53-
5445
function initialize() {
5546
ui.freeze();
5647
worker = new Worker("worker.js");
@@ -89,6 +80,16 @@ function plotWorker() {
8980
if (worker) worker.terminate();
9081
initialize();
9182
}
83+
84+
var delegateList = {
85+
"log" : log,
86+
"error" : logError,
87+
"displayplot" : displayplot,
88+
"displayprof" : displayprof,
89+
"range" : setRange,
90+
"script" : scriptLoaded,
91+
"reset" : this.reset
92+
}
9293
}
9394

9495

@@ -233,9 +234,6 @@ function start(event) {
233234
function getSelectedFile() {
234235
var file = ui.file.files[0];
235236
if (!file) throw Error("No valid file selected.");
236-
if (!file.type.toString().match(/text/)) {
237-
throw Error("'" + escape(file.name) + "' is not a text file.");
238-
}
239237
return file;
240238
}
241239

tools/profviz/stdio.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ if (!isNaN(range_end)) range_end_override = range_end;
4444

4545
var kResX = 1600;
4646
var kResY = 600;
47-
var psc = new PlotScriptComposer(kResX, kResY);
47+
function log_error(text) {
48+
print(text);
49+
quit(1);
50+
}
51+
var psc = new PlotScriptComposer(kResX, kResY, log_error);
4852
psc.collectData(readline, distortion_per_entry);
4953
psc.findPlotRange(range_start_override, range_end_override);
5054
print("set terminal pngcairo size " + kResX + "," + kResY +

tools/profviz/worker.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ function load_scripts(scripts) {
7272
}
7373

7474

75+
function log_error(text) {
76+
self.postMessage({"call": "error", "args": text});
77+
self.postMessage({"call": "reset"});
78+
}
79+
80+
7581
function run(args) {
7682
var file = args["file"];
7783
var resx = args["resx"];
@@ -121,7 +127,7 @@ function run(args) {
121127
var input_file_name = "input_temp";
122128
var output_file_name = "output.svg";
123129

124-
var psc = new PlotScriptComposer(resx, resy);
130+
var psc = new PlotScriptComposer(resx, resy, log_error);
125131
var objects = 0;
126132

127133
time("Collecting events (" + content_lines.length + " entries)",

0 commit comments

Comments
 (0)