LCOV - code coverage report
Current view: top level - libreofficekit/qa/tilebench - tilebench.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 84 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <assert.h>
      11             : #include <stdio.h>
      12             : #include <string.h>
      13             : 
      14             : #include <vector>
      15             : #include <osl/time.h>
      16             : 
      17             : #define LOK_USE_UNSTABLE_API
      18             : 
      19             : #include <LibreOfficeKit/LibreOfficeKitInit.h>
      20             : #include <LibreOfficeKit/LibreOfficeKit.hxx>
      21             : 
      22             : using namespace lok;
      23             : 
      24           0 : static int help()
      25             : {
      26           0 :     fprintf( stderr, "Usage: tilebench <absolute-path-to-libreoffice-install> [path to document]\n" );
      27           0 :     fprintf( stderr, "renders a selection of small tiles from the document, checksums them and times the process\n" );
      28           0 :     return 1;
      29             : }
      30             : 
      31           0 : static double getTimeNow()
      32             : {
      33             :     TimeValue aValue;
      34           0 :     osl_getSystemTime(&aValue);
      35           0 :     return (double)aValue.Seconds +
      36           0 :            (double)aValue.Nanosec / (1000*1000*1000);
      37             : }
      38             : 
      39           0 : int main( int argc, char* argv[] )
      40             : {
      41             :     struct TimeRecord {
      42             :         const char *mpName;
      43             :         double mfTime;
      44             : 
      45           0 :         TimeRecord() : mpName(NULL), mfTime(getTimeNow()) { }
      46           0 :         explicit TimeRecord(const char *pName) :
      47           0 :                        mpName(pName ), mfTime(getTimeNow()) { }
      48             :     };
      49           0 :     std::vector< TimeRecord > aTimes;
      50           0 :     if( argc < 2 ||
      51           0 :         ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
      52           0 :         return help();
      53             : 
      54           0 :     if ( argv[1][0] != '/' )
      55             :     {
      56           0 :         fprintf(stderr, "Absolute path required to libreoffice install\n");
      57           0 :         return 1;
      58             :     }
      59             : 
      60           0 :     aTimes.push_back(TimeRecord("initialization"));
      61             :     // coverity[tainted_string] - build time test tool
      62           0 :     Office *pOffice = lok_cpp_init(argv[1]);
      63           0 :     aTimes.push_back(TimeRecord());
      64             : 
      65           0 :     if (argv[2] != NULL)
      66             :     {
      67           0 :         aTimes.push_back(TimeRecord("load document"));
      68           0 :         Document *pDocument(pOffice->documentLoad(argv[2]));
      69           0 :         aTimes.push_back(TimeRecord());
      70             : 
      71           0 :         aTimes.push_back(TimeRecord("getparts"));
      72           0 :         int nParts = pDocument->getParts();
      73           0 :         aTimes.push_back(TimeRecord());
      74             : 
      75           0 :         aTimes.push_back(TimeRecord("get size of parts"));
      76           0 :         for (int nPart = 0; nPart < nParts; nPart++)
      77             :         {
      78           0 :             char* pName = pDocument->getPartName(nPart);
      79           0 :             pDocument->setPart(nPart);
      80           0 :             long nWidth = 0, nHeight = 0;
      81           0 :             pDocument->getDocumentSize(&nWidth, &nHeight);
      82           0 :             fprintf (stderr, "  '%s' -> %ld, %ld\n", pName, nWidth, nHeight);
      83           0 :             free (pName);
      84             :         }
      85           0 :         aTimes.push_back(TimeRecord());
      86             : 
      87             :         unsigned char pPixels[256*256*4];
      88           0 :         for (int nPart = 0; nPart < nParts; nPart++)
      89             :         {
      90             :             {
      91           0 :                 char* pName = pDocument->getPartName(nPart);
      92           0 :                 fprintf (stderr, "render '%s'\n", pName);
      93           0 :                 free (pName);
      94             :             }
      95           0 :             pDocument->setPart(nPart);
      96           0 :             long nWidth = 0, nHeight = 0;
      97           0 :             pDocument->getDocumentSize(&nWidth, &nHeight);
      98             : 
      99             :             { // whole document
     100           0 :                 aTimes.push_back(TimeRecord("render whole document"));
     101             :                 pDocument->paintTile(pPixels, 256, 256,
     102           0 :                                      0, 0, nWidth, nHeight); // not square
     103           0 :                 aTimes.push_back(TimeRecord());
     104             :             }
     105             : 
     106             :             { // 1:1
     107           0 :                 aTimes.push_back(TimeRecord("render sub-region at 1:1"));
     108           0 :                 int nTiles = 0;
     109           0 :                 int nSplit = nWidth / 4;
     110           0 :                 for (int nX = 0; nX < 4; nX++)
     111             :                 {
     112           0 :                     for (int nY = 0; nY < nHeight / nSplit; nY++)
     113             :                     {
     114           0 :                         int nTilePosX = nX * nSplit;
     115           0 :                         int nTilePosY = nY * nSplit;
     116             :                         pDocument->paintTile(pPixels, 256, 256,
     117           0 :                                              nTilePosX, nTilePosY, 256, 256);
     118           0 :                         nTiles++;
     119             :                         fprintf (stderr, "   rendered tile %d at %d, %d\n",
     120           0 :                                  nTiles, nTilePosX, nTilePosY);
     121             :                     }
     122             :                 }
     123           0 :                 aTimes.push_back(TimeRecord());
     124             :             }
     125             : 
     126             :             { // scaled
     127           0 :                 aTimes.push_back(TimeRecord("render sub-regions at scale"));
     128           0 :                 int nTiles = 0;
     129           0 :                 int nSplit = nWidth / 4;
     130           0 :                 for (int nX = 0; nX < 4; nX++)
     131             :                 {
     132           0 :                     for (int nY = 0; nY < nHeight / nSplit; nY++)
     133             :                     {
     134           0 :                         int nTilePosX = nX * nSplit;
     135           0 :                         int nTilePosY = nY * nSplit;
     136             :                         pDocument->paintTile(pPixels, 256, 256,
     137           0 :                                              nTilePosX, nTilePosY, nSplit, nSplit);
     138           0 :                         nTiles++;
     139             :                         fprintf (stderr, "   rendered tile %d at %d, %d\n",
     140           0 :                                  nTiles, nTilePosX, nTilePosY);
     141             :                     }
     142             :                 }
     143           0 :                 aTimes.push_back(TimeRecord());
     144             :             }
     145             :         }
     146             : 
     147           0 :         aTimes.push_back(TimeRecord("destroy document"));
     148           0 :         delete pDocument;
     149           0 :         aTimes.push_back(TimeRecord());
     150             :     }
     151             : 
     152           0 :     delete pOffice;
     153             : 
     154           0 :     double nTotal = 0.0;
     155           0 :     fprintf (stderr, "profile run:\n");
     156           0 :     for (size_t i = 0; i < aTimes.size() - 1; i++)
     157             :     {
     158           0 :         double nDelta = aTimes[i+1].mfTime - aTimes[i].mfTime;
     159           0 :         fprintf (stderr, "  %s - %2.4f(ms)\n", aTimes[i].mpName, nDelta * 1000.0);
     160           0 :         if (aTimes[i+1].mpName == NULL)
     161           0 :             i++; // skip it.
     162           0 :         nTotal += nDelta;
     163             :     }
     164           0 :     fprintf (stderr, "Total: %2.4f(s)\n", nTotal);
     165           0 :     return 0;
     166             : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11