1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at info@qt.nokia.com.
32 **************************************************************************/
36 var values = [ ]; //events
41 var drawFpsGraph = false;
42 var nestingDepth = [];
44 var names = [ "Painting", "Compiling", "Creating", "Binding", "Handling Signal"]
45 //### need better way to manipulate color from QML. In the meantime, these need to be kept in sync.
46 var colors = [ "#99CCB3", "#99CCCC", "#99B3CC", "#9999CC", "#CC99B3", "#CC99CC", "#CCCC99", "#CCB399" ];
47 var origColors = [ "#99CCB3", "#99CCCC", "#99B3CC", "#9999CC", "#CC99B3", "#CC99CC", "#CCCC99", "#CCB399" ];
48 var xRayColors = [ "#6699CCB3", "#6699CCCC", "#6699B3CC", "#669999CC", "#66CC99B3", "#66CC99CC", "#66CCCC99", "#66CCB399" ];
64 frameFps = new Array(values.length - 1);
65 for (var i = 0; i < values.length - 1; ++i) {
66 var frameTime = (values[i + 1] - values[i]) / 1000000;
67 frameFps[i] = 1000 / frameTime;
72 //draw background of the graph
73 function drawGraph(canvas, ctxt, region)
75 var grad = ctxt.createLinearGradient(0, 0, 0, canvas.canvasSize.height);
76 grad.addColorStop(0, '#fff');
77 grad.addColorStop(1, '#ccc');
78 ctxt.fillStyle = grad;
80 ctxt.fillRect(0, 0, canvas.canvasSize.width + xmargin, canvas.canvasSize.height - ymargin);
83 //draw the actual data to be graphed
84 function drawData(canvas, ctxt, region)
86 if (values.length == 0 && ranges.length == 0)
89 var width = canvas.canvasSize.width - xmargin;
90 var height = canvas.height - ymargin;
92 var sumValue = ranges[ranges.length - 1].start + ranges[ranges.length - 1].duration - ranges[0].start;
93 var spacing = width / sumValue;
95 ctxt.fillStyle = "rgba(0,0,0,1)";
96 var highest = [0,0,0,0,0];
98 //### only draw those in range
99 for (var ii = 0; ii < ranges.length; ++ii) {
101 var xx = (ranges[ii].start - ranges[0].start) * spacing + xmargin;
102 if (xx > region.x + region.width)
105 var size = ranges[ii].duration * spacing;
106 if (xx + size < region.x)
113 if (xx + size > highest[ranges[ii].type]) {
114 ctxt.fillRect(xx, ranges[ii].type*10, size, 10);
115 highest[ranges[ii].type] = xx+size;
121 var heightScale = height / 60;
124 for (var i = 1; i < values.length; ++i) {
125 var xx = (values[i] - ranges[0].start) * spacing + xmargin;
126 ctxt.lineTo(xx, height - frameFps[i-1]*heightScale)
128 ctxt.lineTo(width, 0);
130 var grad = ctxt.createLinearGradient(0, 0, 0, canvas.canvasSize.height);
131 grad.addColorStop(0, "rgba(255,128,128,.5)");
132 grad.addColorStop(1, "rgba(255,0,0,.5)");
133 ctxt.fillStyle = grad;
138 function plot(canvas, ctxt, region)
140 drawGraph(canvas, ctxt, region);
141 drawData(canvas, ctxt, region);
144 function xScale(canvas)
146 if (values.length === 0 && ranges.length === 0)
149 var width = canvas.canvasSize.width - xmargin;
151 var sumValue = ranges[ranges.length - 1].start + ranges[ranges.length - 1].duration - ranges[0].start;
152 var spacing = sumValue / width;