Dan McCabe | 1c3ddde | 2012-03-21 09:53:45 -0700 | [diff] [blame] | 1 | #include "trimprocess.h" |
| 2 | #include "apitrace.h" |
| 3 | |
| 4 | #include <QDebug> |
| 5 | #include <QDir> |
| 6 | #include <QFile> |
| 7 | #include <QFileInfo> |
| 8 | |
| 9 | TrimProcess::TrimProcess(QObject *parent) |
| 10 | : QObject(parent) |
| 11 | { |
| 12 | m_process = new QProcess(this); |
| 13 | |
| 14 | connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), |
| 15 | this, SLOT(trimFinished())); |
| 16 | connect(m_process, SIGNAL(error(QProcess::ProcessError)), |
| 17 | this, SLOT(trimError(QProcess::ProcessError))); |
Dan McCabe | 1c3ddde | 2012-03-21 09:53:45 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | TrimProcess::~TrimProcess() |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | void TrimProcess::trimFinished() |
| 25 | { |
| 26 | // consume verbose output spew |
| 27 | QByteArray outputStrings = m_process->readAllStandardOutput(); |
| 28 | QByteArray errorStrings = m_process->readAllStandardError(); |
| 29 | #if 0 |
| 30 | qDebug()<<"trim finished on " << m_trimPath; |
| 31 | qDebug()<<"\terr = "<<errorStrings; |
| 32 | qDebug()<<"\tout = "<<outputStrings; |
| 33 | #endif |
| 34 | emit trimmedFile(m_trimPath); |
| 35 | } |
| 36 | |
| 37 | void TrimProcess::trimError(QProcess::ProcessError err) |
| 38 | { |
| 39 | // consume verbose output spew |
| 40 | QByteArray outputStrings = m_process->readAllStandardOutput(); |
| 41 | QByteArray errorStrings = m_process->readAllStandardError(); |
| 42 | #if 1 |
| 43 | qDebug()<<"trace error = "<<m_tracePath; |
| 44 | qDebug()<<"\terr = "<<errorStrings; |
| 45 | qDebug()<<"\tout = "<<outputStrings; |
| 46 | #endif |
| 47 | emit error(errorStrings); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | void TrimProcess::start() |
| 52 | { |
| 53 | QStringList arguments; |
| 54 | |
| 55 | QString outputFormat = QLatin1String("--output=%1"); |
| 56 | QString outputArgument = outputFormat |
| 57 | .arg(m_trimPath); |
| 58 | |
| 59 | QString callSetFormat = QLatin1String("--calls=0-%1"); |
| 60 | QString callSetArgument = callSetFormat |
| 61 | .arg(m_trimIndex); |
| 62 | |
Jose Fonseca | f99bf0d | 2017-04-11 13:51:04 +0100 | [diff] [blame] | 63 | arguments << QLatin1String("trim"); |
Dan McCabe | 1c3ddde | 2012-03-21 09:53:45 -0700 | [diff] [blame] | 64 | arguments << outputArgument; |
| 65 | arguments << callSetArgument; |
| 66 | arguments << m_tracePath; |
| 67 | |
| 68 | m_process->start(QLatin1String("apitrace"), arguments); |
| 69 | } |
| 70 | |
| 71 | int TrimProcess::trimIndex() |
| 72 | { |
| 73 | return m_trimIndex; |
| 74 | } |
| 75 | |
| 76 | void TrimProcess::setTrimIndex(int trimIndex) |
| 77 | { |
| 78 | m_trimIndex = trimIndex; |
| 79 | |
| 80 | updateTrimPath(); |
| 81 | } |
| 82 | |
| 83 | void TrimProcess::setTracePath(const QString &str) |
| 84 | { |
| 85 | m_tracePath = str; |
| 86 | |
| 87 | updateTrimPath(); |
| 88 | } |
| 89 | |
| 90 | QString TrimProcess::tracePath() const |
| 91 | { |
| 92 | return m_tracePath; |
| 93 | } |
| 94 | |
| 95 | void TrimProcess::updateTrimPath() |
| 96 | { |
| 97 | |
| 98 | QFileInfo fi(m_tracePath); |
| 99 | QString baseName = fi.baseName(); |
| 100 | QString path = fi.path(); |
| 101 | |
| 102 | QString format = QString::fromLatin1("%1/%2.%3.trim.trace"); |
| 103 | |
| 104 | m_trimPath = format |
| 105 | .arg(path) |
| 106 | .arg(baseName) |
| 107 | .arg(m_trimIndex); |
| 108 | } |
| 109 | |
| 110 | #include "trimprocess.moc" |