ThreadWeaver library (helper for multithreaded programming) use in heaptrack_gui...
authorAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Fri, 30 Mar 2018 18:07:35 +0000 (21:07 +0300)
committerAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Fri, 30 Mar 2018 18:07:35 +0000 (21:07 +0300)
src/ThreadWeaver.pro [new file with mode: 0644]
src/ThreadWeaver/threadweaver_export.h [new file with mode: 0644]
src/analyze/gui/flamegraph.cpp
src/analyze/gui/parser.cpp
src/heaptrack_gui.pro

diff --git a/src/ThreadWeaver.pro b/src/ThreadWeaver.pro
new file mode 100644 (file)
index 0000000..7334638
--- /dev/null
@@ -0,0 +1,117 @@
+QT       -= gui
+
+TEMPLATE = lib
+
+TARGET = threadweaver
+
+# change the variable if ThreadWeaver sources are located in another directory
+SRC_PATH = ../../kf5/threadweaver/src/
+
+win32 {
+    CONFIG(debug, debug|release) {
+        TARGET = $${TARGET}d
+        DESTDIR = ../bin/debug
+    }
+    else {
+        DESTDIR = ../bin/release
+    }
+}
+
+# Probably you don't need to build the library on Linux - check whether it's available
+# in your Linux distribution's repositories.
+unix {
+    target.path = /usr/lib
+    INSTALLS += target
+}
+
+DEFINES += THREADWEAVER_LIBRARY
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+INCLUDEPATH += ThreadWeaver
+
+SOURCES += \
+    $${SRC_PATH}collection.cpp \
+    $${SRC_PATH}collection_p.cpp \
+    $${SRC_PATH}debuggingaids.cpp \
+    $${SRC_PATH}dependency.cpp \
+    $${SRC_PATH}dependencypolicy.cpp \
+    $${SRC_PATH}destructedstate.cpp \
+    $${SRC_PATH}exception.cpp \
+    $${SRC_PATH}executewrapper.cpp \
+    $${SRC_PATH}executor.cpp \
+    $${SRC_PATH}iddecorator.cpp \
+    $${SRC_PATH}inconstructionstate.cpp \
+    $${SRC_PATH}job.cpp \
+    $${SRC_PATH}job_p.cpp \
+    $${SRC_PATH}qobjectdecorator.cpp \
+    $${SRC_PATH}queue.cpp \
+    $${SRC_PATH}queueapi.cpp \
+    $${SRC_PATH}queuesignals.cpp \
+    $${SRC_PATH}queuesignals_p.cpp \
+    $${SRC_PATH}queuestream.cpp \
+    $${SRC_PATH}resourcerestrictionpolicy.cpp \
+    $${SRC_PATH}sequence.cpp \
+    $${SRC_PATH}sequence_p.cpp \
+    $${SRC_PATH}shuttingdownstate.cpp \
+    $${SRC_PATH}state.cpp \
+    $${SRC_PATH}suspendedstate.cpp \
+    $${SRC_PATH}suspendingstate.cpp \
+    $${SRC_PATH}thread.cpp \
+    $${SRC_PATH}threadweaver.cpp \
+    $${SRC_PATH}weaver.cpp \
+    $${SRC_PATH}weaver_p.cpp \
+    $${SRC_PATH}weaverimplstate.cpp \
+    $${SRC_PATH}workinghardstate.cpp
+
+HEADERS += \
+    ThreadWeaver/threadweaver_export.h \
+    $${SRC_PATH}collection.h \
+    $${SRC_PATH}collection_p.h \
+    $${SRC_PATH}debuggingaids.h \
+    $${SRC_PATH}dependency.h \
+    $${SRC_PATH}dependencypolicy.h \
+    $${SRC_PATH}destructedstate.h \
+    $${SRC_PATH}exception.h \
+    $${SRC_PATH}executewrapper_p.h \
+    $${SRC_PATH}executor_p.h \
+    $${SRC_PATH}iddecorator.h \
+    $${SRC_PATH}inconstructionstate.h \
+    $${SRC_PATH}job.h \
+    $${SRC_PATH}job_p.h \
+    $${SRC_PATH}jobinterface.h \
+    $${SRC_PATH}jobpointer.h \
+    $${SRC_PATH}lambda.h \
+    $${SRC_PATH}managedjobpointer.h \
+    $${SRC_PATH}qobjectdecorator.h \
+    $${SRC_PATH}queue.h \
+    $${SRC_PATH}queueapi.h \
+    $${SRC_PATH}queueing.h \
+    $${SRC_PATH}queueinterface.h \
+    $${SRC_PATH}queuepolicy.h \
+    $${SRC_PATH}queuesignals.h \
+    $${SRC_PATH}queuesignals_p.h \
+    $${SRC_PATH}queuestream.h \
+    $${SRC_PATH}resourcerestrictionpolicy.h \
+    $${SRC_PATH}sequence.h \
+    $${SRC_PATH}sequence_p.h \
+    $${SRC_PATH}shuttingdownstate.h \
+    $${SRC_PATH}state.h \
+    $${SRC_PATH}suspendedstate.h \
+    $${SRC_PATH}suspendingstate.h \
+    $${SRC_PATH}thread.h \
+    $${SRC_PATH}threadweaver.h \
+    $${SRC_PATH}weaver.h \
+    $${SRC_PATH}weaver_p.h \
+    $${SRC_PATH}weaverimplstate.h \
+    $${SRC_PATH}weaverinterface.h \
+    $${SRC_PATH}workinghardstate.h
diff --git a/src/ThreadWeaver/threadweaver_export.h b/src/ThreadWeaver/threadweaver_export.h
new file mode 100644 (file)
index 0000000..4a45c49
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef THREADWEAVER_GLOBAL_H
+#define THREADWEAVER_GLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(THREADWEAVER_LIBRARY)
+#  define THREADWEAVER_EXPORT Q_DECL_EXPORT
+#else
+#  define THREADWEAVER_EXPORT Q_DECL_IMPORT
+#endif
+
+#endif // THREADWEAVER_GLOBAL_H
index d250c6126f30518115a90c02b55123b604bee256..b9ebfc6e2a2cadb87d85f33c69eb5b01fc66567c 100644 (file)
 
 #ifdef NO_K_LIB
 #include "noklib.h"
+#ifdef THREAD_WEAVER
+#include <threadweaver.h>
+#endif // THREAD_WEAVER
 #else
 #include <KColorScheme>
 #include <KLocalizedString>
 #include <KStandardAction>
 #include <ThreadWeaver/ThreadWeaver>
-#endif
+#endif // NO_K_LIB
 
 #include "util.h"
 
@@ -746,7 +749,7 @@ void FlameGraph::showData()
     bool collapseRecursion = m_collapseRecursion;
     auto source = m_costSource->currentData().value<CostType>();
     auto threshold = m_costThreshold;
-#ifdef NO_K_LIB
+#ifndef THREAD_WEAVER
     setData(parseData(data, source, threshold, collapseRecursion));
 #else
     using namespace ThreadWeaver;
index 82bcb4867b36589d3d5da8675c48c844d39f0e11..940ba9a153364c899b84a4d55b07d09b02b61322 100644 (file)
 
 #ifdef NO_K_LIB
 #include "noklib.h"
+#ifdef THREAD_WEAVER
+#include <threadweaver.h>
+#endif // THREAD_WEAVER
 #else
 #include <KLocalizedString>
 #include <ThreadWeaver/ThreadWeaver>
-#endif
+#endif // NO_K_LIB
 
 #include <QDebug>
 
@@ -855,7 +858,7 @@ Parser::~Parser() = default;
 
 void Parser::parse(const QString& path, const QString& diffBase)
 {
-#ifdef NO_K_LIB
+#ifndef THREAD_WEAVER
     parseJob(path, diffBase);
 #else
     ThreadWeaver::stream() << ThreadWeaver::make_job([this, path, diffBase]() {
@@ -940,7 +943,7 @@ void Parser::parseJob(const QString& path, const QString& diffBase)
 
     const auto diffMode = data->stringCache.diffMode;
     emit progressMessageAvailable(i18n("building charts..."));
-#ifndef NO_K_LIB
+#ifdef THREAD_WEAVER
     using namespace ThreadWeaver;
     auto parallel = new Collection;
     *parallel << make_job([this, mergedAllocations]()
@@ -949,19 +952,19 @@ void Parser::parseJob(const QString& path, const QString& diffBase)
         const auto topDownData = toTopDownData(mergedAllocations);
         emit topDownDataAvailable(topDownData);
     }
-#ifndef NO_K_LIB
+#ifdef THREAD_WEAVER
     ) << make_job([this, mergedAllocations, diffMode]()
 #endif
     {
         const auto callerCalleeData = toCallerCalleeData(mergedAllocations, diffMode);
         emit callerCalleeDataAvailable(callerCalleeData);
     }
-#ifndef NO_K_LIB
+#ifdef THREAD_WEAVER
     );
 #endif
     if (!data->stringCache.diffMode) {
         // only build charts when we are not diffing
-#ifndef NO_K_LIB
+#ifdef THREAD_WEAVER
         *parallel << make_job([this, data, stdPath]()
 #endif
         {
@@ -975,12 +978,12 @@ void Parser::parseJob(const QString& path, const QString& diffBase)
             emit allocatedChartDataAvailable(data->allocatedChartData);
             emit temporaryChartDataAvailable(data->temporaryChartData);
         }
-#ifndef NO_K_LIB
+#ifdef THREAD_WEAVER
         );
 #endif
     }
 
-#ifdef NO_K_LIB
+#ifndef THREAD_WEAVER
     emit finished();
 #else
     auto sequential = new Sequence;
index 13c7e4744b1671f95eef69d5fbac83a1965d747b..abc669984b9fd11ff82dcb119625a0c2d4d23161 100644 (file)
@@ -18,23 +18,59 @@ SAMSUNG_TIZEN_BRANCH {
 }
 
 win32 {
-    CONFIG += NO_K_LIB NO_K_CHART
+    # Third-party libraries used:
+    # QWT: http://qwt.sourceforge.net (SVN: https://svn.code.sf.net/p/qwt/code/trunk)
+    # ThreadWeaver: https://cgit.kde.org/threadweaver.git (git://anongit.kde.org/threadweaver.git)
 
-#   comment the next line to not use QWT (i.e. don't show charts)
+    # comment the next line to not use QWT library (charts will not be displayed in this case)
     CONFIG += QWT_CHART
 
+    # comment the next line to not use ThreadWeaver library (used to parse data files faster)
+    CONFIG += THREAD_WEAVER
+
+    CONFIG += NO_K_LIB NO_K_CHART
+
     DEFINES += NO_K_LIB NO_K_CHART WINDOWS
     INCLUDEPATH += $$(BOOST_LIB)
     LIBS += -L$$(BOOST_LIB)/stage/lib
 
     RC_ICONS += analyze/gui/icons/if_diagram_v2-14_37134.ico
+
+    CONFIG(debug, debug|release) {
+        TARGET = $${TARGET}Dbg
+        DESTDIR = ../bin/debug
+    }
+    else {
+        DESTDIR = ../bin/release
+    }
+}
+
+THREAD_WEAVER {
+    DEFINES += THREAD_WEAVER
+    win32 {
+        # ThreadWeaver shall be built beforehand (load ThreadWeaver.pro, edit it if necessary, and build)
+
+        # change the variable if ThreadWeaver headers are located in another directory
+        THREAD_WEAVE_HEADER_PATH = ../../kf5/threadweaver/src/
+
+        INCLUDEPATH += $$THREAD_WEAVE_HEADER_PATH ThreadWeaver
+        CONFIG(debug, debug|release) {
+            win32-msvc:LIBS += $${DESTDIR}/threadweaverd.lib
+        }
+        else {
+            win32-msvc:LIBS += $${DESTDIR}/threadweaver.lib
+        }
+    }
+    unix {
+        QT += ThreadWeaver
+    }
 }
 
 unix {
     CONFIG *= USE_CHART
     DEFINES *= USE_CHART
 
-#   uncomment the next line to use QWT instead of KChart
+    # uncomment the next line to use QWT instead of KChart
 #   CONFIG += QWT_CHART
 
     QWT_CHART {
@@ -47,6 +83,15 @@ unix {
     LIBS += -lboost_program_options -lboost_iostreams -lpthread
 }
 
+QWT_CHART {
+    # QMAKEFEATURES and QWT_ROOT environment variables must be set (e.g. to d:\Qwt\Qwt-6.2).
+    # This is the directory where qwt.prf and qwt*.pri files reside.
+    # Windows: file qwt.dll must exist in $${DESTDIR}\release and qwtd.dll in $${DESTDIR}\debug
+    # to be able to run the application.
+    CONFIG *= USE_CHART QWT
+    DEFINES *= USE_CHART QWT
+}
+
 #Test only!
 #CONFIG *= NO_K_LIB NO_K_CHART
 #DEFINES *= NO_K_LIB NO_K_CHART
@@ -91,11 +136,6 @@ HEADERS += \
     util/config.h
 
 QWT_CHART {
-    # QMAKEFEATURES and QWT_ROOT environment variables must be set (e.g. to d:\Qwt\Qwt-6.2).
-    # This is the directory where qwt.prf and qwt*.pri files reside.
-    CONFIG *= USE_CHART QWT
-    DEFINES *= USE_CHART QWT
-
     SOURCES += \
         analyze/gui/chartmodel2qwtseriesdata.cpp \
         analyze/gui/chartwidgetqwtplot.cpp \
@@ -137,7 +177,8 @@ USE_CHART {
 
     QT += KItemModels
 
-    QT += ThreadWeaver
+    QT *= ThreadWeaver
+    DEFINES *= THREAD_WEAVER
 }
 
 !NO_K_CHART {