Exemplo n.º 1
0
void TraceLoader::parseTrace()
{
    QList<ApiTraceFrame*> frames;
    ApiTraceFrame *currentFrame = 0;
    int frameCount = 0;
    QVector<ApiTraceCall*> calls;
    quint64 binaryDataSize = 0;

    int lastPercentReport = 0;

    trace::Call *call = m_parser.parse_call();
    while (call) {
        //std::cout << *call;
        if (!currentFrame) {
            currentFrame = new ApiTraceFrame();
            currentFrame->number = frameCount;
            ++frameCount;
        }
        ApiTraceCall *apiCall =
            apiCallFromTraceCall(call, m_helpHash, currentFrame, this);
        calls.append(apiCall);
        if (apiCall->hasBinaryData()) {
            QByteArray data =
                apiCall->arguments()[apiCall->binaryDataIndex()].toByteArray();
            binaryDataSize += data.size();
        }
        if (ApiTrace::isCallAFrameMarker(apiCall,
                                         m_frameMarker)) {
            calls.squeeze();
            currentFrame->setCalls(calls, binaryDataSize);
            calls.clear();
            frames.append(currentFrame);
            currentFrame = 0;
            binaryDataSize = 0;
            if (frames.count() >= FRAMES_TO_CACHE) {
                emit framesLoaded(frames);
                frames.clear();
            }
            if (m_parser.percentRead() - lastPercentReport >= 5) {
                emit parsed(m_parser.percentRead());
                lastPercentReport = m_parser.percentRead();
            }
        }
        delete call;
        call = m_parser.parse_call();
    }

    //last frames won't have markers
    //  it's just a bunch of Delete calls for every object
    //  after the last SwapBuffers
    if (currentFrame) {
        calls.squeeze();
        currentFrame->setCalls(calls, binaryDataSize);
        frames.append(currentFrame);
        currentFrame = 0;
    }
    if (frames.count()) {
        emit framesLoaded(frames);
    }
}
Exemplo n.º 2
0
MouseProfile MouseProfileDialog::getProfile() const
{
	MouseProfile profile(m_profile);
	profile.setTitle(m_ui->titleLineEditWidget->text());
	profile.setDescription(m_ui->descriptionLineEditWidget->text());
	profile.setVersion(m_ui->versionLineEditWidget->text());
	profile.setAuthor(m_ui->authorLineEditWidget->text());

	QHash<int, QVector<MouseProfile::Gesture> > definitions;

	for (int i = 0; i < m_ui->gesturesViewWidget->getRowCount(); ++i)
	{
		const QModelIndex contextIndex(m_ui->gesturesViewWidget->getIndex(i, 0));
		const int gestureAmount(m_ui->gesturesViewWidget->getRowCount(contextIndex));

		if (gestureAmount > 0)
		{
			QVector<MouseProfile::Gesture> gestures;
			gestures.reserve(gestureAmount);

			for (int j = 0; j < gestureAmount; ++j)
			{
				const QModelIndex actionIndex(contextIndex.child(j, 0));
				const QStringList steps(actionIndex.sibling(actionIndex.row(), 2).data(Qt::DisplayRole).toString().split(QLatin1String(", "), QString::SkipEmptyParts));
				const int action(actionIndex.data(IdentifierRole).toInt());

				if (!steps.isEmpty() && action >= 0)
				{
					MouseProfile::Gesture gesture;
					gesture.action = action;
					gesture.parameters = actionIndex.data(ParametersRole).toMap();

					for (int k = 0; k < steps.count(); ++k)
					{
						gesture.steps.append(MouseProfile::Gesture::Step::fromString(steps.at(k)));
					}

					gestures.append(gesture);
				}
			}

			gestures.squeeze();

			if (gestures.count() > 0)
			{
				definitions[static_cast<GesturesManager::GesturesContext>(contextIndex.data(ContextRole).toInt())] = gestures;
			}
		}
	}

	profile.setDefinitions(definitions);
	profile.setModified(m_ui->gesturesViewWidget->isModified());

	return profile;
}
Exemplo n.º 3
0
void Column::calculateStatistics() {
    m_column_private->statistics = ColumnStatistics();
	ColumnStatistics& statistics = m_column_private->statistics;

    QVector<double>* rowValues = reinterpret_cast<QVector<double>*>(data());

    int notNanCount = 0;
    double val;
    double columnSum = 0.0;
    double columnProduct = 1.0;
    double columnSumNeg = 0.0;
    double columnSumSquare = 0.0;
    statistics.minimum = INFINITY;
    statistics.maximum = -INFINITY;
    QMap<double, int> frequencyOfValues;
    QVector<double> rowData;
    rowData.reserve(rowValues->size());
    for (int row = 0; row < rowValues->size(); ++row) {
        val = rowValues->value(row);
        if (std::isnan(val) || isMasked(row))
            continue;

        if (val < statistics.minimum){
            statistics.minimum = val;
        }
        if (val > statistics.maximum){
            statistics.maximum = val;
        }
        columnSum+= val;
        columnSumNeg += (1.0 / val);
        columnSumSquare += pow(val, 2.0);
        columnProduct *= val;
        if (frequencyOfValues.contains(val)){
            frequencyOfValues.operator [](val)++;
        }
        else{
            frequencyOfValues.insert(val, 1);
        }
        ++notNanCount;
        rowData.push_back(val);
    }

    if (notNanCount == 0) {
		setStatisticsAvailable(true);
		return;
	}

    if (rowData.size() < rowValues->size()){
        rowData.squeeze();
    }

    statistics.arithmeticMean = columnSum / notNanCount;
    statistics.geometricMean = pow(columnProduct, 1.0 / notNanCount);
    statistics.harmonicMean = notNanCount / columnSumNeg;
    statistics.contraharmonicMean = columnSumSquare / columnSum;

    double columnSumVariance = 0;
    double columnSumMeanDeviation = 0.0;
    double columnSumMedianDeviation = 0.0;
    double sumForCentralMoment_r3 = 0.0;
    double sumForCentralMoment_r4 = 0.0;

    gsl_sort(rowData.data(), 1, notNanCount);
    statistics.median = (notNanCount % 2 ? rowData.at((notNanCount-1)/2) :
                                             (rowData.at((notNanCount-1)/2) +
                                              rowData.at(notNanCount/2))/2.0);
    QVector<double> absoluteMedianList;
    absoluteMedianList.reserve(notNanCount);
    absoluteMedianList.resize(notNanCount);

    int idx = 0;
    for(int row = 0; row < rowValues->size(); ++row){
        val = rowValues->value(row);
        if ( std::isnan(val) || isMasked(row) )
            continue;
        columnSumVariance+= pow(val - statistics.arithmeticMean, 2.0);

        sumForCentralMoment_r3 += pow(val - statistics.arithmeticMean, 3.0);
        sumForCentralMoment_r4 += pow(val - statistics.arithmeticMean, 4.0);
        columnSumMeanDeviation += fabs( val - statistics.arithmeticMean );

        absoluteMedianList[idx] = fabs(val - statistics.median);
        columnSumMedianDeviation += absoluteMedianList[idx];
        idx++;
    }

    statistics.meanDeviationAroundMedian = columnSumMedianDeviation / notNanCount;
    statistics.medianDeviation = (notNanCount % 2 ? absoluteMedianList.at((notNanCount-1)/2) :
                                                      (absoluteMedianList.at((notNanCount-1)/2) + absoluteMedianList.at(notNanCount/2))/2.0);

    const double centralMoment_r3 = sumForCentralMoment_r3 / notNanCount;
    const double centralMoment_r4 = sumForCentralMoment_r4 / notNanCount;

    statistics.variance = columnSumVariance / notNanCount;
    statistics.standardDeviation = sqrt(statistics.variance);
    statistics.skewness = centralMoment_r3 / pow(statistics.standardDeviation, 3.0);
    statistics.kurtosis = (centralMoment_r4 / pow(statistics.standardDeviation, 4.0)) - 3.0;
    statistics.meanDeviation = columnSumMeanDeviation / notNanCount;

    double entropy = 0.0;
    QList<int> frequencyOfValuesValues = frequencyOfValues.values();
    for (int i = 0; i < frequencyOfValuesValues.size(); ++i){
        double frequencyNorm = static_cast<double>(frequencyOfValuesValues.at(i)) / notNanCount;
        entropy += (frequencyNorm * log2(frequencyNorm));
    }

    statistics.entropy = -entropy;
    setStatisticsAvailable(true);
}
Exemplo n.º 4
0
void TraceLoader::parseTrace()
{
    QList<ApiTraceFrame*> frames;
    ApiTraceFrame *currentFrame = 0;
    int frameCount = 0;
    QStack<ApiTraceCall*> groups;
    QVector<ApiTraceCall*> topLevelItems;
    QVector<ApiTraceCall*> allCalls;
    quint64 binaryDataSize = 0;

    int lastPercentReport = 0;

    trace::Call *call = m_parser.parse_call();
    while (call) {
        //std::cout << *call;
        if (!currentFrame) {
            currentFrame = new ApiTraceFrame();
            currentFrame->number = frameCount;
            ++frameCount;
        }
        ApiTraceCall *apiCall =
            apiCallFromTraceCall(call, m_helpHash, currentFrame, groups.isEmpty() ? 0 : groups.top(), this);
        allCalls.append(apiCall);
        if (groups.count() == 0) {
            topLevelItems.append(apiCall);
        }
        if (call->flags & trace::CALL_FLAG_MARKER_PUSH) {
            groups.push(apiCall);
        } else if (call->flags & trace::CALL_FLAG_MARKER_POP) {
            groups.top()->finishedAddingChildren();
            groups.pop();
        }
        if (!groups.isEmpty()) {
            groups.top()->addChild(apiCall);
        }
        if (apiCall->hasBinaryData()) {
            QByteArray data =
                apiCall->arguments()[apiCall->binaryDataIndex()].toByteArray();
            binaryDataSize += data.size();
        }
        if (call->flags & trace::CALL_FLAG_END_FRAME) {
            allCalls.squeeze();
            topLevelItems.squeeze();
            if (topLevelItems.count() == allCalls.count()) {
                currentFrame->setCalls(allCalls, allCalls, binaryDataSize);
            } else {
                currentFrame->setCalls(topLevelItems, allCalls, binaryDataSize);
            }
            allCalls.clear();
            groups.clear();
            topLevelItems.clear();
            frames.append(currentFrame);
            currentFrame = 0;
            binaryDataSize = 0;
            if (frames.count() >= FRAMES_TO_CACHE) {
                emit framesLoaded(frames);
                frames.clear();
            }
            if (m_parser.percentRead() - lastPercentReport >= 5) {
                emit parsed(m_parser.percentRead());
                lastPercentReport = m_parser.percentRead();
            }
        }
        delete call;
        call = m_parser.parse_call();
    }

    //last frames won't have markers
    //  it's just a bunch of Delete calls for every object
    //  after the last SwapBuffers
    if (currentFrame) {
        allCalls.squeeze();
        if (topLevelItems.count() == allCalls.count()) {
            currentFrame->setCalls(allCalls, allCalls, binaryDataSize);
        } else {
            currentFrame->setCalls(topLevelItems, allCalls, binaryDataSize);
        }
        frames.append(currentFrame);
        currentFrame = 0;
    }
    if (frames.count()) {
        emit framesLoaded(frames);
    }
}