[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - libreofficekit/Executable_tilebench.mk libreofficekit/Module_libreofficekit.mk libreofficekit/qa Repository.mk

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue Nov 28 20:45:03 UTC 2017


 Repository.mk                             |    2 
 libreofficekit/Executable_tilebench.mk    |    1 
 libreofficekit/Module_libreofficekit.mk   |    5 +
 libreofficekit/qa/tilebench/tilebench.cxx |  102 ++++++++++++++++++++----------
 4 files changed, 74 insertions(+), 36 deletions(-)

New commits:
commit 7db98521548de9eab955ee25a5aacaaef42df323
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Nov 19 20:38:43 2017 -0500

    LOK: tilebench improvements
    
    * Arguments for max number of parts and tiles to render (optional).
      + Automatic estimation of maximum tiles to render based on max parts
        for Writer docs, since there is only 1 part, this caps the number
        of pages to render, similar to other doc types.
    * Fixed rendering of Writer documents over and over (as many times as pages).
      + Writer has a single part, unlike other doc types.
      + No point in rendering the whole document in writer to a single tile,
        since that's completely unrealistic and impractical (it takes
        forever for large docs and artificially spikes the memory).
    * Rendering starts at the current part and not the first.
      + This gives the spreadsheet of interest priority (if saved as visible).
    * The tile size is now more realistic as we use the same dimensions
      as the Online client does.
    * When rendering tiles at scale, we use the same dimensions as the
      Online client rather than splitting the width by 4, for realism.
    * Rendering of tiles is done rows-first, rather than columns-first,
      which is similar to what the Online client does, which is more
      cache friendly, therefore more realistic.
    * Enabled compiling of tilebench when GTK3 is disabled, which
      was erroneous, since tilebench doesn't have any dependency on GTK.
      + Now it's possible to compile with local Cairo/Pixman libs.
    
    Change-Id: Ib78d030ead387748914119f95fe49ddc1ce64498
    Reviewed-on: https://gerrit.libreoffice.org/44936
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/Repository.mk b/Repository.mk
index 3635ccfadada..1c72fc1abb61 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -70,7 +70,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
         svptest \
         svpclient \
         pixelctl ) \
-	$(if $(and $(ENABLE_GTK3), $(filter LINUX %BSD SOLARIS,$(OS))), tilebench) \
+	$(if $(filter LINUX %BSD SOLARIS,$(OS)), tilebench) \
 	$(if $(filter LINUX MACOSX SOLARIS WNT %BSD,$(OS)),icontest \
 	    outdevgrind) \
 	vcldemo \
diff --git a/libreofficekit/Executable_tilebench.mk b/libreofficekit/Executable_tilebench.mk
index 4da51d3ca686..9d8b2a134f99 100644
--- a/libreofficekit/Executable_tilebench.mk
+++ b/libreofficekit/Executable_tilebench.mk
@@ -15,7 +15,6 @@ $(eval $(call gb_Executable_set_include,tilebench,\
 ))
 
 $(eval $(call gb_Executable_use_libraries,tilebench,\
-    libreofficekitgtk \
 	sal \
 ))
 
diff --git a/libreofficekit/Module_libreofficekit.mk b/libreofficekit/Module_libreofficekit.mk
index cc842b2f3f2c..079e4e15e5b4 100644
--- a/libreofficekit/Module_libreofficekit.mk
+++ b/libreofficekit/Module_libreofficekit.mk
@@ -23,10 +23,13 @@ ifneq ($(ENABLE_GTK3),)
 $(eval $(call gb_Module_add_targets,libreofficekit,\
     Library_libreofficekitgtk \
     Executable_gtktiledviewer \
+))
+endif # ($(ENABLE_GTK3),)
+
+$(eval $(call gb_Module_add_targets,libreofficekit,\
     Executable_tilebench \
     Package_selectionhandles \
 ))
-endif # ($(ENABLE_GTK3),)
 
 endif
 
diff --git a/libreofficekit/qa/tilebench/tilebench.cxx b/libreofficekit/qa/tilebench/tilebench.cxx
index b4912b1611ef..08cf8abff6ab 100644
--- a/libreofficekit/qa/tilebench/tilebench.cxx
+++ b/libreofficekit/qa/tilebench/tilebench.cxx
@@ -10,10 +10,12 @@
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
+#include <cmath>
 
 #include <vector>
 #include <osl/time.h>
 
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <LibreOfficeKit/LibreOfficeKitInit.h>
 #include <LibreOfficeKit/LibreOfficeKit.hxx>
 
@@ -21,7 +23,7 @@ using namespace lok;
 
 static int help()
 {
-    fprintf( stderr, "Usage: tilebench <absolute-path-to-libreoffice-install> [path to document]\n" );
+    fprintf( stderr, "Usage: tilebench <absolute-path-to-libreoffice-install> [path to document] [max parts|-1] [max tiles|-1]\n" );
     fprintf( stderr, "renders a selection of small tiles from the document, checksums them and times the process\n" );
     return 1;
 }
@@ -36,13 +38,17 @@ static double getTimeNow()
 
 int main( int argc, char* argv[] )
 {
+    static const double origin = getTimeNow();
     struct TimeRecord {
         const char *mpName;
         double mfTime;
 
         TimeRecord() : mpName(nullptr), mfTime(getTimeNow()) { }
         explicit TimeRecord(const char *pName) :
-                       mpName(pName ), mfTime(getTimeNow()) { }
+                       mpName(pName), mfTime(getTimeNow())
+        {
+            fprintf(stderr, "%3.3fs - %s\n", (mfTime - origin), mpName);
+        }
     };
     std::vector< TimeRecord > aTimes;
     if( argc < 2 ||
@@ -55,11 +61,20 @@ int main( int argc, char* argv[] )
         return 1;
     }
 
+    // Use realistic dimensions, similar to the Online client.
+    long nTilePixelWidth = 512;
+    long nTilePixelHeight = 512;
+    long nTileTwipWidth = 3840;
+    long nTileTwipHeight = 3840;
+
     aTimes.push_back(TimeRecord("initialization"));
     // coverity[tainted_string] - build time test tool
     Office *pOffice = lok_cpp_init(argv[1]);
     aTimes.push_back(TimeRecord());
 
+    const int max_parts = (argc > 3 ? atoi(argv[3]) : -1);
+    const int max_tiles = (argc > 4 ? atoi(argv[4]) : -1);
+
     if (argv[2] != nullptr)
     {
         aTimes.push_back(TimeRecord("load document"));
@@ -67,12 +82,17 @@ int main( int argc, char* argv[] )
         aTimes.push_back(TimeRecord());
 
         aTimes.push_back(TimeRecord("getparts"));
-        int nParts = pDocument->getParts();
+        const int nOriginalPart = pDocument->getPart();
+        // Writer really has 1 part (the full doc).
+        const int nTotalParts = (pDocument->getDocumentType() == LOK_DOCTYPE_TEXT ? 1 : pDocument->getParts());
+        const int nParts = (max_parts < 0 ? nTotalParts : std::min(max_parts, nTotalParts));
+        fprintf(stderr, "Parts to render: %d, Total Parts: %d, Max parts: %d, Max tiles: %d\n", nParts, nTotalParts, max_parts, max_tiles);
         aTimes.push_back(TimeRecord());
 
         aTimes.push_back(TimeRecord("get size of parts"));
-        for (int nPart = 0; nPart < nParts; nPart++)
+        for (int n = 0; n < nParts; ++n)
         {
+            const int nPart = (nOriginalPart + n) % nTotalParts;
             char* pName = pDocument->getPartName(nPart);
             pDocument->setPart(nPart);
             long nWidth = 0, nHeight = 0;
@@ -82,40 +102,49 @@ int main( int argc, char* argv[] )
         }
         aTimes.push_back(TimeRecord());
 
-        unsigned char pPixels[256*256*4];
-        for (int nPart = 0; nPart < nParts; nPart++)
+        std::vector<unsigned char> vBuffer(nTilePixelWidth * nTilePixelHeight * 4);
+        unsigned char* pPixels = &vBuffer[0];
+
+        for (int n = 0; n < nParts; ++n)
         {
-            {
-                char* pName = pDocument->getPartName(nPart);
-                fprintf (stderr, "render '%s'\n", pName);
-                free (pName);
-            }
+            const int nPart = (nOriginalPart + n) % nTotalParts;
+            char* pName = pDocument->getPartName(nPart);
             pDocument->setPart(nPart);
             long nWidth = 0, nHeight = 0;
             pDocument->getDocumentSize(&nWidth, &nHeight);
+            fprintf (stderr, "render '%s' -> %ld, %ld\n", pName, nWidth, nHeight);
+            free (pName);
 
-            { // whole document
-                aTimes.push_back(TimeRecord("render whole document"));
-                pDocument->paintTile(pPixels, 256, 256,
+            if (pDocument->getDocumentType() != LOK_DOCTYPE_TEXT)
+            { // whole part; meaningful only for non-writer documents.
+                aTimes.push_back(TimeRecord("render whole part"));
+                pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
                                      0, 0, nWidth, nHeight); // not square
                 aTimes.push_back(TimeRecord());
             }
 
             { // 1:1
                 aTimes.push_back(TimeRecord("render sub-region at 1:1"));
+                // Estimate the maximum tiles based on the number of parts requested, if Writer.
+                int nMaxTiles = max_tiles;
+                if (pDocument->getDocumentType() == LOK_DOCTYPE_TEXT && nMaxTiles < 0)
+                    nMaxTiles = (int)ceil(max_parts * 16128. / nTilePixelHeight) * ceil((double)nWidth / nTilePixelWidth);
                 int nTiles = 0;
-                int nSplit = nWidth / 4;
-                for (int nX = 0; nX < 4; nX++)
+                for (int nY = 0; nY < nHeight - 1; nY += nTilePixelHeight)
                 {
-                    for (int nY = 0; nY < nHeight / nSplit; nY++)
+                    for (int nX = 0; nX < nWidth - 1; nX += nTilePixelWidth)
                     {
-                        int nTilePosX = nX * nSplit;
-                        int nTilePosY = nY * nSplit;
-                        pDocument->paintTile(pPixels, 256, 256,
-                                             nTilePosX, nTilePosY, 256, 256);
+                        if (nMaxTiles >= 0 && nTiles >= nMaxTiles)
+                        {
+                            nY = nHeight;
+                            break;
+                        }
+
+                        pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
+                                             nX, nY, nTilePixelWidth, nTilePixelHeight);
                         nTiles++;
-                        fprintf (stderr, "   rendered tile %d at %d, %d\n",
-                                 nTiles, nTilePosX, nTilePosY);
+                        fprintf (stderr, "   rendered 1:1 tile %d at %d, %d\n",
+                                 nTiles, nX, nY);
                     }
                 }
                 aTimes.push_back(TimeRecord());
@@ -123,19 +152,26 @@ int main( int argc, char* argv[] )
 
             { // scaled
                 aTimes.push_back(TimeRecord("render sub-regions at scale"));
+                // Estimate the maximum tiles based on the number of parts requested, if Writer.
+                int nMaxTiles = max_tiles;
+                if (pDocument->getDocumentType() == LOK_DOCTYPE_TEXT && nMaxTiles < 0)
+                    nMaxTiles = (int)ceil(max_parts * 16128. / nTileTwipHeight) * ceil((double)nWidth / nTileTwipWidth);
                 int nTiles = 0;
-                int nSplit = nWidth / 4;
-                for (int nX = 0; nX < 4; nX++)
+                for (int nY = 0; nY < nHeight - 1; nY += nTileTwipHeight)
                 {
-                    for (int nY = 0; nY < nHeight / nSplit; nY++)
+                    for (int nX = 0; nX < nWidth - 1; nX += nTileTwipWidth)
                     {
-                        int nTilePosX = nX * nSplit;
-                        int nTilePosY = nY * nSplit;
-                        pDocument->paintTile(pPixels, 256, 256,
-                                             nTilePosX, nTilePosY, nSplit, nSplit);
+                        if (nMaxTiles >= 0 && nTiles >= nMaxTiles)
+                        {
+                            nY = nHeight;
+                            break;
+                        }
+
+                        pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
+                                             nX, nY, nTileTwipWidth, nTileTwipHeight);
                         nTiles++;
-                        fprintf (stderr, "   rendered tile %d at %d, %d\n",
-                                 nTiles, nTilePosX, nTilePosY);
+                        fprintf (stderr, "   rendered scaled tile %d at %d, %d\n",
+                                 nTiles, nX, nY);
                     }
                 }
                 aTimes.push_back(TimeRecord());
@@ -153,7 +189,7 @@ int main( int argc, char* argv[] )
     fprintf (stderr, "profile run:\n");
     for (size_t i = 0; i < aTimes.size() - 1; i++)
     {
-        double nDelta = aTimes[i+1].mfTime - aTimes[i].mfTime;
+        const double nDelta = aTimes[i+1].mfTime - aTimes[i].mfTime;
         fprintf (stderr, "  %s - %2.4f(ms)\n", aTimes[i].mpName, nDelta * 1000.0);
         if (aTimes[i+1].mpName == nullptr)
             i++; // skip it.


More information about the Libreoffice-commits mailing list