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); } }
QVector<ApiTraceCall*> TraceLoader::fetchFrameContents(ApiTraceFrame *currentFrame) { Q_ASSERT(currentFrame); if (currentFrame->isLoaded()) { return currentFrame->calls(); } if (m_parser.supportsOffsets()) { unsigned frameIdx = currentFrame->number; int numOfCalls = numberOfCallsInFrame(frameIdx); if (numOfCalls) { quint64 binaryDataSize = 0; QVector<ApiTraceCall*> calls(numOfCalls); const FrameBookmark &frameBookmark = m_frameBookmarks[frameIdx]; m_parser.setBookmark(frameBookmark.start); trace::Call *call; int parsedCalls = 0; while ((call = m_parser.parse_call())) { ApiTraceCall *apiCall = apiCallFromTraceCall(call, m_helpHash, currentFrame, this); calls[parsedCalls] = apiCall; Q_ASSERT(calls[parsedCalls]); if (apiCall->hasBinaryData()) { QByteArray data = apiCall->arguments()[ apiCall->binaryDataIndex()].toByteArray(); binaryDataSize += data.size(); } ++parsedCalls; delete call; if (apiCall->flags() & trace::CALL_FLAG_END_FRAME) { break; } } assert(parsedCalls == numOfCalls); Q_ASSERT(parsedCalls == calls.size()); calls.squeeze(); Q_ASSERT(parsedCalls == currentFrame->numChildrenToLoad()); emit frameContentsLoaded(currentFrame, calls, binaryDataSize); return calls; } } return QVector<ApiTraceCall*>(); }
void MainWindow::slotTraceChanged(ApiTraceEvent *event) { Q_ASSERT(event); if (event == m_selectedEvent) { if (event->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast<ApiTraceCall*>(event); m_ui.detailsWebView->setHtml(call->toHtml()); } } }
void MainWindow::slotGoFrameEnd() { ApiTraceFrame *frame = currentFrame(); ApiTraceCall *call = currentCall(); if (!frame && call) { frame = call->parentFrame(); } m_trace->findFrameEnd(frame); }
static ApiTraceCall * apiCallFromTraceCall(const trace::Call *call, const QHash<QString, QUrl> &helpHash, ApiTraceFrame *frame, TraceLoader *loader) { ApiTraceCall *apiCall = new ApiTraceCall(frame, loader, call); apiCall->setHelpUrl(helpHash.value(apiCall->name())); return apiCall; }
bool TraceLoader::callContains(trace::Call *call, const QString &str, Qt::CaseSensitivity sensitivity) { /* * FIXME: do string comparison directly on trace::Call */ ApiTraceCall *apiCall = apiCallFromTraceCall(call, m_helpHash, 0, 0, this); bool result = apiCall->contains(str, sensitivity); delete apiCall; return result; }
ApiTraceFrame * MainWindow::selectedFrame() const { if (m_selectedEvent) { if (m_selectedEvent->type() == ApiTraceEvent::Frame) { return static_cast<ApiTraceFrame*>(m_selectedEvent); } else { Q_ASSERT(m_selectedEvent->type() == ApiTraceEvent::Call); ApiTraceCall *call = static_cast<ApiTraceCall*>(m_selectedEvent); return call->parentFrame(); } } return NULL; }
QModelIndex ApiTraceModel::parent(const QModelIndex &index) const { if (!index.isValid()) return QModelIndex(); ApiTraceEvent *event = item(index); if (event && event->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast<ApiTraceCall*>(event); Q_ASSERT(call->parentFrame()); return createIndex(call->parentFrame()->number, 0, call->parentFrame()); } return QModelIndex(); }
void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity) { ApiTraceCall *call = currentCall(); ApiTraceFrame *frame = currentFrame(); Q_ASSERT(call || frame); if (!frame) { frame = call->parentFrame(); } Q_ASSERT(frame); m_trace->findPrev(frame, call, str, sensitivity); }
QVariant ApiTraceModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.column() != 0) return QVariant(); ApiTraceEvent *itm = item(index); if (!itm) { return QVariant(); } switch (role) { case Qt::DisplayRole: return itm->staticText().text(); case Qt::DecorationRole: return QImage(); case Qt::ToolTipRole: { const QString stateText = tr("State info available."); if (itm->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast<ApiTraceCall*>(itm); if (call->state().isEmpty()) return QString::fromLatin1("%1) <b>%2</b>") .arg(call->index) .arg(call->name); else return QString::fromLatin1("%1) <b>%2</b><br/>%3") .arg(call->index) .arg(call->name) .arg(stateText); } else { ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(itm); QString text = frame->staticText().text(); if (frame->state().isEmpty()) return QString::fromLatin1("<b>%1</b>").arg(text); else return QString::fromLatin1("<b>%1</b><br/>%2") .arg(text) .arg(stateText); } } case ApiTraceModel::EventRole: return QVariant::fromValue(itm); } return QVariant(); }
bool ApiTraceModel::hasChildren(const QModelIndex &parent) const { if (parent.isValid()) { ApiTraceEvent *event = item(parent); if (!event) return false; if (event->type() == ApiTraceEvent::Frame) { ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event); return !frame->isEmpty(); } else { Q_ASSERT(event->type() == ApiTraceEvent::Call); ApiTraceCall *call = static_cast<ApiTraceCall*>(event); return call->numChildren() != 0; } } else { return (rowCount() > 0); } }
void MainWindow::trimEvent() { int trimIndex; if (m_trimEvent->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast<ApiTraceCall*>(m_trimEvent); trimIndex = call->index(); } else if (m_trimEvent->type() == ApiTraceEvent::Frame) { ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(m_trimEvent); const QList<ApiTraceFrame*> frames = m_trace->frames(); trimIndex = frame->lastCallIndex(); } m_trimProcess->setTracePath(m_trace->fileName()); m_trimProcess->setTrimIndex(trimIndex); m_trimProcess->start(); }
void ApiTraceModel::stateSetOnEvent(ApiTraceEvent *event) { if (!event) return; if (event->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast<ApiTraceCall*>(event); ApiTraceFrame *frame = call->parentFrame(); int row = frame->callIndex(call); QModelIndex index = createIndex(row, 0, call); emit dataChanged(index, index); } else if (event->type() == ApiTraceEvent::Frame) { ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(event); const QList<ApiTraceFrame*> frames = m_trace->frames(); int row = frames.indexOf(frame); QModelIndex index = createIndex(row, 0, frame); emit dataChanged(index, index); } }
QModelIndex ApiTraceModel::parent(const QModelIndex &index) const { if (!index.isValid()) return QModelIndex(); ApiTraceEvent *event = item(index); if (event->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast<ApiTraceCall*>(event); if (call->parentCall()) { ApiTraceCall *parentCall = call->parentCall(); ApiTraceEvent *topEvent = parentCall->parentEvent(); return createIndex(topEvent->callIndex(parentCall), 0, parentCall); } else { Q_ASSERT(call->parentFrame()); return createIndex(call->parentFrame()->number, 0, call->parentFrame()); } } return QModelIndex(); }
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); } }
bool TraceLoader::FrameContents::load(TraceLoader *loader, ApiTraceFrame *currentFrame, QHash<QString, QUrl> helpHash, trace::Parser &parser) { bool bEndFrameReached = false; int initNumOfCalls = m_allCalls.count(); trace::Call *call; ApiTraceCall *apiCall = NULL; while ((call = parser.parse_call())) { apiCall = apiCallFromTraceCall(call, helpHash, currentFrame, m_groups.isEmpty() ? 0 : m_groups.top(), loader); Q_ASSERT(apiCall); if (initNumOfCalls) { Q_ASSERT(m_parsedCalls < m_allCalls.size()); m_allCalls[m_parsedCalls++] = apiCall; } else { m_allCalls.append(apiCall); } if (m_groups.count() == 0) { m_topLevelItems.append(apiCall); } else { m_groups.top()->addChild(apiCall); } if (call->flags & trace::CALL_FLAG_MARKER_PUSH) { m_groups.push(apiCall); } else if (call->flags & trace::CALL_FLAG_MARKER_POP) { if (m_groups.count()) { m_groups.top()->finishedAddingChildren(); m_groups.pop(); } } if (apiCall->hasBinaryData()) { QByteArray data = apiCall->arguments()[apiCall->binaryDataIndex()]. toByteArray(); m_binaryDataSize += data.size(); } delete call; if (apiCall->flags() & trace::CALL_FLAG_END_FRAME) { bEndFrameReached = true; break; } } if (initNumOfCalls) { // There can be fewer parsed calls when call in different // threads cross the frame boundary Q_ASSERT(m_parsedCalls <= initNumOfCalls); Q_ASSERT(m_parsedCalls <= m_allCalls.size()); m_allCalls.resize(m_parsedCalls); Q_ASSERT(m_parsedCalls <= currentFrame->numChildrenToLoad()); } m_allCalls.squeeze(); m_topLevelItems.squeeze(); return bEndFrameReached; }
void MainWindow::callItemSelected(const QModelIndex &index) { ApiTraceEvent *event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>(); if (event && event->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast<ApiTraceCall*>(event); m_ui.detailsDock->setWindowTitle( tr("Details View. Frame %1, Call %2") .arg(call->parentFrame() ? call->parentFrame()->number : 0) .arg(call->index())); m_ui.detailsWebView->setHtml(call->toHtml()); m_ui.detailsDock->show(); m_ui.callView->scrollTo(index); if (call->hasBinaryData()) { QByteArray data = call->arguments()[call->binaryDataIndex()].toByteArray(); m_vdataInterpreter->setData(data); QVector<QVariant> args = call->arguments(); for (int i = 0; i < call->argNames().count(); ++i) { QString name = call->argNames()[i]; if (name == QLatin1String("stride")) { int stride = args[i].toInt(); m_ui.vertexStrideSB->setValue(stride); } else if (name == QLatin1String("size")) { int components = args[i].toInt(); m_ui.vertexComponentsSB->setValue(components); } else if (name == QLatin1String("type")) { QString val = args[i].toString(); int textIndex = m_ui.vertexTypeCB->findText(val); if (textIndex >= 0) { m_ui.vertexTypeCB->setCurrentIndex(textIndex); } } } } m_ui.backtraceBrowser->setText(call->backtrace()); m_ui.backtraceDock->setVisible(!call->backtrace().isNull()); m_ui.vertexDataDock->setVisible(call->hasBinaryData()); m_selectedEvent = call; } else { if (event && event->type() == ApiTraceEvent::Frame) { m_selectedEvent = static_cast<ApiTraceFrame*>(event); } else { m_selectedEvent = 0; } m_ui.detailsDock->hide(); m_ui.backtraceDock->hide(); m_ui.vertexDataDock->hide(); } if (m_selectedEvent && m_selectedEvent->hasState()) { fillStateForFrame(); } else { m_ui.stateDock->hide(); } }
QVariant ApiTraceModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.column() != 0) return QVariant(); ApiTraceEvent *itm = item(index); if (!itm) { return QVariant(); } switch (role) { case Qt::DisplayRole: return itm->staticText().text(); case Qt::DecorationRole: return QImage(); case Qt::ToolTipRole: { const QString stateText = tr("State info available."); if (itm->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast<ApiTraceCall*>(itm); if (!call->hasState()) return QString::fromLatin1("%1) <b>%2</b>") .arg(call->index()) .arg(call->name()); else return QString::fromLatin1("%1) <b>%2</b><br/>%3") .arg(call->index()) .arg(call->name()) .arg(stateText); } else { const char *htmlTempl = "<div>\n" "<div>\n" "%1" "<span style=\"font-weight:bold; font-size:large; vertical-align:center; padding-bottom: 30px \">\n" "Frame %2</span>\n" "</div>\n" "<div >%3 calls%4</div>\n" "</div>\n"; ApiTraceFrame *frame = static_cast<ApiTraceFrame*>(itm); QString thumbStr, sizeStr; if (frame->hasState()) { static const char *imgTempl = "<img style=\"float:left;\" " "src=\"data:image/png;base64,%1\"/>\n"; static const char *sizeTempl = ", %1kb"; ApiFramebuffer fbo = frame->state()->colorBuffer(); QImage thumb = fbo.thumb(); if (!thumb.isNull()) { QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); thumb.save(&buffer, "PNG"); thumbStr = tr(imgTempl).arg( QString(buffer.data().toBase64())); } int binaryDataSize = frame->binaryDataSize() / 1024; if (binaryDataSize > 0) { sizeStr = tr(sizeTempl).arg(binaryDataSize); } } int numCalls = frame->isLoaded() ? frame->numTotalCalls() : frame->numChildrenToLoad(); return tr(htmlTempl) .arg(thumbStr) .arg(frame->number) .arg(numCalls) .arg(sizeStr); } } case ApiTraceModel::EventRole: return QVariant::fromValue(itm); } return QVariant(); }
QVector<ApiTraceCall*> TraceLoader::fetchFrameContents(ApiTraceFrame *currentFrame) { Q_ASSERT(currentFrame); if (currentFrame->isLoaded()) { return currentFrame->calls(); } if (m_parser.supportsOffsets()) { unsigned frameIdx = currentFrame->number; int numOfCalls = numberOfCallsInFrame(frameIdx); if (numOfCalls) { quint64 binaryDataSize = 0; QStack<ApiTraceCall*> groups; QVector<ApiTraceCall*> topLevelItems; QVector<ApiTraceCall*> allCalls(numOfCalls); const FrameBookmark &frameBookmark = m_frameBookmarks[frameIdx]; m_parser.setBookmark(frameBookmark.start); trace::Call *call; int parsedCalls = 0; while ((call = m_parser.parse_call())) { ApiTraceCall *apiCall = apiCallFromTraceCall(call, m_helpHash, currentFrame, groups.isEmpty() ? 0 : groups.top(), this); Q_ASSERT(apiCall); Q_ASSERT(parsedCalls < allCalls.size()); allCalls[parsedCalls++] = apiCall; if (groups.count() == 0) { topLevelItems.append(apiCall); } else { groups.top()->addChild(apiCall); } if (call->flags & trace::CALL_FLAG_MARKER_PUSH) { groups.push(apiCall); } else if (call->flags & trace::CALL_FLAG_MARKER_POP) { if (groups.count()) { groups.top()->finishedAddingChildren(); groups.pop(); } } if (apiCall->hasBinaryData()) { QByteArray data = apiCall->arguments()[ apiCall->binaryDataIndex()].toByteArray(); binaryDataSize += data.size(); } delete call; if (apiCall->flags() & trace::CALL_FLAG_END_FRAME) { break; } } // There can be fewer parsed calls when call in different // threads cross the frame boundary Q_ASSERT(parsedCalls <= numOfCalls); Q_ASSERT(parsedCalls <= allCalls.size()); allCalls.resize(parsedCalls); allCalls.squeeze(); Q_ASSERT(parsedCalls <= currentFrame->numChildrenToLoad()); if (topLevelItems.count() == allCalls.count()) { emit frameContentsLoaded(currentFrame, allCalls, allCalls, binaryDataSize); } else { emit frameContentsLoaded(currentFrame, topLevelItems, allCalls, binaryDataSize); } return allCalls; } } return QVector<ApiTraceCall*>(); }