<commit_before>/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (<EMAIL>)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
**************************************************************************/

import QtQuick 1.0
import Monitor 1.0
import "MainView.js" as Plotter

Rectangle {
    id: root

    property bool dataAvailable: false;
    property int eventCount: 0;

    // move the cursor in the editor
    signal updateCursorPosition
    property string fileName: ""
    property int lineNumber: -1
    function gotoSourceLocation(file,line) {
        root.fileName = file;
        root.lineNumber = line;
        root.updateCursorPosition();
    }

    function clearData() {
        Plotter.reset();
        view.clearData();
        root.dataAvailable = false;
        root.eventCount = 0;
        rangeMover.x = 2
        rangeMover.opacity = 0
    }

    function clearAll() {
        clearData();
        selectedEventIndex = -1;
        canvas.requestPaint();
        view.visible = false;
        root.elapsedTime = 0;
        root.updateTimer();
    }

    property int selectedEventIndex : -1;
    property bool mouseTracking: false;

    onSelectedEventIndexChanged: {
        if ((!mouseTracking) && Plotter.ranges.length > 0
                && selectedEventIndex > -1 && selectedEventIndex < Plotter.ranges.length) {
            // re-center flickable if necessary
            var event = Plotter.ranges[selectedEventIndex];
            var xs = Plotter.xScale(canvas);
            var startTime = Plotter.ranges[0].start;
            if (rangeMover.value + startTime> event.start) {
                rangeMover.x = Math.max(0,
                    Math.floor((event.start - startTime) / xs - canvas.canvasWindow.x - rangeMover.zoomWidth/2) );
            } else if (rangeMover.value + startTime + rangeMover.zoomWidth * xs < event.start + event.duration) {
                rangeMover.x = Math.floor((event.start + event.duration - startTime) / xs - canvas.canvasWindow.x - rangeMover.zoomWidth/2);
            }
        }
    }

    function nextEvent() {
        if (Plotter.ranges.length > 0) {
            ++selectedEventIndex;
            if (selectedEventIndex >= Plotter.ranges.length)
                selectedEventIndex = 0;
        }
    }

    function prevEvent() {
        if (Plotter.ranges.length > 0) {
            --selectedEventIndex;
            if (selectedEventIndex < 0)
                selectedEventIndex = Plotter.ranges.length - 1;
        }
    }

    function zoomIn() {
        // 10%
        var newZoom = rangeMover.zoomWidth / 1.1;

        // 0.1 ms minimum zoom
        if (newZoom * Plotter.xScale(canvas) > 100000) {
            hideRangeDetails();
            rangeMover.zoomWidth =  newZoom
            rangeMover.updateZoomControls();
        }
    }

    function zoomOut() {
        hideRangeDetails();
        // 10%
        var newZoom = rangeMover.zoomWidth * 1.1;
        if (newZoom > canvas.width)
            newZoom = canvas.width;
        if (newZoom + rangeMover.x > canvas.width)
            rangeMover.x = canvas.width - newZoom;
        rangeMover.zoomWidth = newZoom;
        rangeMover.updateZoomControls();
    }

    //handle debug data coming from C++
    Connections {
        target: connection
        onEvent: {
            if (root.dataAvailable) {
                root.clearData();
            }

            if (!root.dataAvailable && event === 0) { //### only handle paint event
                Plotter.values.push(time);
            }
        }

        onRange: {
            if (root.dataAvailable) {
                root.clearData();
            }

            // todo: consider nestingLevel
            if (!root.dataAvailable) {
                if (!Plotter.nestingDepth[type])
                    Plotter.nestingDepth[type] = nestingInType;
                else
                    Plotter.nestingDepth[type] = Math.max(Plotter.nestingDepth[type], nestingInType);
                Plotter.ranges.push( { type: type, start: startTime, duration: length, label: data, fileName: fileName, line: line, nestingLevel: nestingInType, nestingDepth: Plotter.nestingDepth[type] } );
                if (nestingInType == 1)
                    Plotter.nestingDepth[type] = 1;
                root.eventCount = Plotter.ranges.length;

            }
        }

        onComplete: {
            root.dataAvailable = true;
            Plotter.calcFps();
            view.visible = true;
            view.setRanges(Plotter.ranges);
            view.updateTimeline();
            canvas.requestPaint();
            rangeMover.x = 1    //### hack to get view to display things immediately
            rangeMover.x = 0
            rangeMover.opacity = 1
        }

        onClear: {
            root.clearAll();
        }

    }

    // Elapsed
    property real elapsedTime;
    signal updateTimer;
    Timer {
        property date startDate
        property bool reset:  true
        running: connection.recording
        repeat: true
        onRunningChanged: if (running) reset = true
        interval:  100<commit_msg>QmlProfiler: displaying events only when available<commit_after>/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (<EMAIL>)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
**************************************************************************/

import QtQuick 1.0
import Monitor 1.0
import "MainView.js" as Plotter

Rectangle {
    id: root

    property bool dataAvailable: false;
    property int eventCount: 0;

    // move the cursor in the editor
    signal updateCursorPosition
    property string fileName: ""
    property int lineNumber: -1
    function gotoSourceLocation(file,line) {
        root.fileName = file;
        root.lineNumber = line;
        root.updateCursorPosition();
    }

    function clearData() {
        Plotter.reset();
        view.clearData();
        root.dataAvailable = false;
        root.eventCount = 0;
        rangeMover.x = 2
        rangeMover.opacity = 0
    }

    function clearAll() {
        clearData();
        selectedEventIndex = -1;
        canvas.requestPaint();
        view.visible = false;
        root.elapsedTime = 0;
        root.updateTimer();
    }

    property int selectedEventIndex : -1;
    property bool mouseTracking: false;

    onSelectedEventIndexChanged: {
        if ((!mouseTracking) && Plotter.ranges.length > 0
                && selectedEventIndex > -1 && selectedEventIndex < Plotter.ranges.length) {
            // re-center flickable if necessary
            var event = Plotter.ranges[selectedEventIndex];
            var xs = Plotter.xScale(canvas);
            var startTime = Plotter.ranges[0].start;
            if (rangeMover.value + startTime> event.start) {
                rangeMover.x = Math.max(0,
                    Math.floor((event.start - startTime) / xs - canvas.canvasWindow.x - rangeMover.zoomWidth/2) );
            } else if (rangeMover.value + startTime + rangeMover.zoomWidth * xs < event.start + event.duration) {
                rangeMover.x = Math.floor((event.start + event.duration - startTime) / xs - canvas.canvasWindow.x - rangeMover.zoomWidth/2);
            }
        }
    }

    function nextEvent() {
        if (Plotter.ranges.length > 0) {
            ++selectedEventIndex;
            if (selectedEventIndex >= Plotter.ranges.length)
                selectedEventIndex = 0;
        }
    }

    function prevEvent() {
        if (Plotter.ranges.length > 0) {
            --selectedEventIndex;
            if (selectedEventIndex < 0)
                selectedEventIndex = Plotter.ranges.length - 1;
        }
    }

    function zoomIn() {
        // 10%
        var newZoom = rangeMover.zoomWidth / 1.1;

        // 0.1 ms minimum zoom
        if (newZoom * Plotter.xScale(canvas) > 100000) {
            hideRangeDetails();
            rangeMover.zoomWidth =  newZoom
            rangeMover.updateZoomControls();
        }
    }

    function zoomOut() {
        hideRangeDetails();
        // 10%
        var newZoom = rangeMover.zoomWidth * 1.1;
        if (newZoom > canvas.width)
            newZoom = canvas.width;
        if (newZoom + rangeMover.x > canvas.width)
            rangeMover.x = canvas.width - newZoom;
        rangeMover.zoomWidth = newZoom;
        rangeMover.updateZoomControls();
    }

    //handle debug data coming from C++
    Connections {
        target: connection
        onEvent: {
            if (root.dataAvailable) {
                root.clearData();
            }

            if (!root.dataAvailable && event === 0) { //### only handle paint event
                Plotter.values.push(time);
            }
        }

        onRange: {
            if (root.dataAvailable) {
                root.clearData();
            }

            // todo: consider nestingLevel
            if (!root.dataAvailable) {
                if (!Plotter.nestingDepth[type])
                    Plotter.nestingDepth[type] = nestingInType;
                else
                    Plotter.nestingDepth[type] = Math.max(Plotter.nestingDepth[type], nestingInType);
                Plotter.ranges.push( { type: type, start: startTime, duration: length, label: data, fileName: fileName, line: line, nestingLevel: nestingInType, nestingDepth: Plotter.nestingDepth[type] } );
                if (nestingInType == 1)
                    Plotter.nestingDepth[type] = 1;
                root.eventCount = Plotter.ranges.length;

            }
        }

        onComplete: {
            root.dataAvailable = true;
            Plotter.calcFps();
            if (Plotter.ranges.length > 0) {
                view.visible = true;
                view.setRanges(Plotter.ranges);
                view.updateTimeline();
                canvas.requestPaint();
                rangeMover.x = 1    //### hack to get view to display things immediately
                rangeMover.x = 0
                rangeMover.opacity = 1
            }
        }

        onClear: {
            root.clearAll();
        }

    }

    // Elapsed
    property real elapsedTime;
    signal updateTimer;
    Timer {
        property date startDate
        property bool reset:  true
        running: connection.recording
        repeat: true
        onRunningChanged: if (running) reset = true
        interval:  100
{'fraction_non_alphanumeric': 0.11936467190758863, 'fraction_numerical': 0.009706401411840206, 'mean_word_length': 2.0201065891472867, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4613631', 'n_tokens_mistral': 3508, 'n_tokens_neox': 3248, 'n_words': 917}