Changeset 964


Ignore:
Timestamp:
Feb 24, 2014, 4:36:44 PM (5 years ago)
Author:
s10k
Message:

XmlTools
More speedup, about 3 times faster now than the current AEI build

Location:
XmlTools2/trunk
Files:
2 added
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • XmlTools2/trunk/XmlTools.pro

    r953 r964  
    88QMAKE_CXXFLAGS+= -fopenmp
    99QMAKE_LFLAGS +=  -fopenmp #OpenMP (multithreading) support
     10
     11# More optimization
     12QMAKE_CFLAGS_RELEASE += -O3
     13QMAKE_CXXFLAGS_RELEASE += -O3
     14
     15
    1016
    1117
     
    2531    utilxmltools.cpp \
    2632    xmlfilter.cpp \
    27     optionsparser.cpp
     33    optionsparser.cpp \
     34    xmlcustomcode.cpp
    2835
    2936HEADERS += main.h \
     
    3643    utilxmltools.h \
    3744    xmlfilter.h \
    38     optionsparser.h
     45    optionsparser.h \
     46    xmlcustomcode.h
    3947
    4048OTHER_FILES +=
  • XmlTools2/trunk/optionsparser.h

    r953 r964  
    33
    44#include "xmlpatch.h"
     5
     6#include <QCommandLineOption>
     7#include <QCommandLineParser>
    58
    69class OptionsParser
  • XmlTools2/trunk/resources.qrc

    r906 r964  
    22    <qresource prefix="/resources">
    33        <file>libs/jsxml.js</file>
    4         <file>libs/rexml.js</file>
    54    </qresource>
    65</RCC>
  • XmlTools2/trunk/util.h

    r942 r964  
    66#include <QString>
    77#include <QStringList>
     8#include <QVector>
    89#include <iostream> // cout, cin etc.
    910
  • XmlTools2/trunk/utilxmltools.cpp

    r955 r964  
    33namespace UtilXmlTools{
    44
    5 QStringList getAllXmlFilesByWildcard(const QString &wildcard){
     5// As this will not likely be modified we use QVector instead of QList since it is more cache friendly
     6QVector<QString> getAllXmlFilesByWildcard(const QString &wildcard){
    67    QStringList validFilesMatching;
    78    QStringList filesMatching;
     
    1920    }
    2021
    21     return validFilesMatching;
     22    return validFilesMatching.toVector();
    2223
    2324}
    2425
    25 QStringList getAllPatchFilesByWildcard(const QString &wildcard){
     26QVector<QString> getAllPatchFilesByWildcard(const QString &wildcard){
    2627    QStringList validFilesMatching;
    2728    QStringList filesMatching;
     
    3940    }
    4041
    41     return validFilesMatching;
     42    return validFilesMatching.toVector();
    4243
    4344}
  • XmlTools2/trunk/utilxmltools.h

    r935 r964  
    1010namespace UtilXmlTools{
    1111
    12 QStringList getAllXmlFilesByWildcard(const QString &wildcard);
    13 QStringList getAllPatchFilesByWildcard(const QString &wildcard);
     12QVector<QString> getAllXmlFilesByWildcard(const QString &wildcard);
     13QVector<QString> getAllPatchFilesByWildcard(const QString &wildcard);
    1414void backupFile(const QString &file, bool verboseEnabled);
    1515void getAllNamedElements(pugi::xml_node &node, QList<pugi::xml_node> &result, XmlFilter &filters);
  • XmlTools2/trunk/xmlpatch.cpp

    r960 r964  
    4747void XmlPatch::insertNodesOperation(const QString &xmlString, XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard){
    4848
    49     QStringList filesToProcess;
     49    QVector<QString> filesToProcess;
    5050    QList<pugi::xml_node> nodesToInsertion;
    5151    pugi::xml_document newNode;
     
    115115void XmlPatch::removeNodesOperation(XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard){
    116116
    117     QStringList filesToProcess;
     117    QVector<QString> filesToProcess;
    118118
    119119    QList<pugi::xml_node> nodesToDeletion;
     
    212212}
    213213
    214 QScriptValue echo(QScriptContext *context, QScriptEngine *engine)
    215 {
    216     std::cout << context->argument(0).toString().toUtf8().constData() << std::endl;
    217 
    218     return "";
    219 }
    220 
    221214void XmlPatch::executeCustomCommandOperation(const QString &jsString, const QString &filesWildcard){
    222215
    223     QString rexmlString, jsxmlString;
    224     QStringList filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard);
     216    QVector<QString> filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard);
    225217
    226218    if(filesToProcess.isEmpty()){
     
    228220    }
    229221
    230     QFile rexmlfile(":/resources/libs/rexml.js");
    231     QFile jsxmlfile(":/resources/libs/jsxml.js");
    232 
    233     rexmlfile.open(QFile::ReadOnly | QFile::Text);
    234     jsxmlfile.open(QFile::ReadOnly | QFile::Text);
    235 
    236     rexmlString=QTextStream(&rexmlfile).readAll();
    237     jsxmlString=QTextStream(&jsxmlfile).readAll();
    238 
    239     // Process all XmlFiles
    240 #pragma omp parallel for
    241     for(int i=0; i<filesToProcess.size(); i++){
    242 
    243         QString currXmlFileString;
    244 
    245         QScriptEngine engine;
    246         QScriptValue engineResult; // variable to check for js_errors
    247         double elapsed_secs; // elapsed seconds that a user script took
    248         clock_t begin; // seconds that a script started
    249 
    250         // Add echo function so user can debug the code
    251         QScriptValue echoFunction = engine.newFunction(echo);
    252         engine.globalObject().setProperty("echo", echoFunction);
    253 
    254         engine.evaluate(rexmlString); // load js libraries
    255         engine.evaluate(jsxmlString);
    256 
    257         if(this->backupsEnabled){
    258             UtilXmlTools::backupFile(filesToProcess[i], this->verboseEnabled);
    259         }
    260 
    261         QFile currXmlFile(filesToProcess[i]);
    262 
    263         if(!currXmlFile.open(QFile::ReadOnly | QFile::Text)){
    264             UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Error loading '" + filesToProcess[i] + "' file for read operation.");
    265         }
    266 
    267         currXmlFileString=QTextStream(&currXmlFile).readAll();
    268 
    269         currXmlFile.close(); // close reading
    270 
    271         engine.globalObject().setProperty("$xmlData",currXmlFileString);
    272 
    273         begin = clock();
    274 
    275         // main needs to be called so the user code is evaluated
    276         // alternatively you can do: myFunc=engine.evaluate('(function main(){})'); myFunc.call();
    277         // Note the () around the function
    278         engineResult=engine.evaluate("main(); function main() {"+jsString+"}"); // main funtion allows to use return to exit prematurely from user code
    279 
    280         if(this->verboseEnabled){
    281             elapsed_secs = double(clock() - begin) / CLOCKS_PER_SEC;
    282 
    283             // Warn the user if the script took much time
    284             if(elapsed_secs>SLOW_SCRIPT_TIME){
    285                 std::cout << "Warning: Slow javascript code detected.\n" <<
    286                              "Warning: Script execution seconds: " << elapsed_secs
    287                           << std::endl;
    288             }
    289         }
    290 
    291         if (engine.hasUncaughtException()) {
    292             displayJsException(engine,engineResult);
    293         }
    294 
    295         if(!currXmlFile.open(QFile::WriteOnly | QFile::Text | QIODevice::Truncate)){
    296             UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Error loading '" + filesToProcess[i] + "' file for @CUSTOM_CODE write operation.");
    297         }
    298 
    299         engineResult=engine.globalObject().property("$xmlData");
    300 
    301         if (engine.hasUncaughtException()) {
    302             displayJsException(engine,engineResult);
    303         }
    304 
    305         QTextStream(&currXmlFile) << engineResult.toString(); // retreive the modified xml by javascript and save it to the file
    306     }
     222    this->customCodeOperation.executeCustomCode(jsString,filesToProcess,this->backupsEnabled,this->verboseEnabled);
     223
    307224
    308225    UtilXmlTools::displaySuccessMessage(filesToProcess.size(), "@CUSTOM_CODE");
     
    515432    return line.mid(startValueIdx,endValueIdx-startValueIdx); // return the value of the parameter (is in the middle of the mandatory quotes)
    516433}
    517 
    518 void XmlPatch::displayJsException(QScriptEngine &engine, QScriptValue &engineResult){
    519     if (engine.hasUncaughtException()) {
    520         UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Uncaught js exception (user code) at line " +QString::number(engine.uncaughtExceptionLineNumber()) + ":\n" + engineResult.toString());
    521     }
    522 }
  • XmlTools2/trunk/xmlpatch.h

    r958 r964  
    33
    44#include "xmltools.h"
     5#include "xmlcustomcode.h"
    56#include "optionsparser.h"
    6 #include <omp.h> // OpenMP support
    7 #include <ctime> // script execution time calculation
    8 
    9 #define SLOW_SCRIPT_TIME 0.1 // if a user script takes more than 0.1 seconds to execute give a warning.
    107
    118class XmlPatch
     
    1512    void readAndProcessPatchFile();
    1613private:
    17     QStringList patchFilesToProcess;
     14    QVector<QString> patchFilesToProcess;
    1815    QString forceTargetFilesWildcard;
    1916    pugi::xml_document document;
    2017    pugi::xml_node rootNode;
    2118    bool backupsEnabled, verboseEnabled;
     19    XmlCustomCode customCodeOperation;
    2220    QString getPatchParameterValue(const QString& line, QString parameter);
    2321    void insertNodesOperation(const QString &xmlString, XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard="");
     
    2725    void checkPatchVersion(const QString &file, QTextStream &fileStream);
    2826    void checkAndProcessValidCommands(QTextStream &fileStream);
    29     void displayJsException(QScriptEngine &engine, QScriptValue &engineResult);
    3027};
    3128
  • XmlTools2/trunk/xmltools.h

    r956 r964  
    44
    55#include <string>
    6 #include <QtCore>
    76#include <stdio.h>
    8 #include <QScriptEngine>
    97
    108#include "utilxmltools.h"
     
    3230    pugi::xml_document document;
    3331    pugi::xml_node rootNode;
    34     QStringList filesToProcess;
     32    QVector<QString> filesToProcess;
    3533    QString xPathExpression;
    3634    XmlFilter filters;
Note: See TracChangeset for help on using the changeset viewer.