1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
17 #define LOK_USE_UNSTABLE_API
19 #include <LibreOfficeKit/LibreOfficeKitInit.h>
20 #include <LibreOfficeKit/LibreOfficeKit.hxx>
26 fprintf( stderr
, "Usage: tilebench <absolute-path-to-libreoffice-install> [path to document]\n" );
27 fprintf( stderr
, "renders a selection of small tiles from the document, checksums them and times the process\n" );
31 static double getTimeNow()
34 osl_getSystemTime(&aValue
);
35 return (double)aValue
.Seconds
+
36 (double)aValue
.Nanosec
/ (1000*1000*1000);
39 int main( int argc
, char* argv
[] )
45 TimeRecord() : mpName(NULL
), mfTime(getTimeNow()) { }
46 explicit TimeRecord(const char *pName
) :
47 mpName(pName
), mfTime(getTimeNow()) { }
49 std::vector
< TimeRecord
> aTimes
;
51 ( argc
> 1 && ( !strcmp( argv
[1], "--help" ) || !strcmp( argv
[1], "-h" ) ) ) )
54 if ( argv
[1][0] != '/' )
56 fprintf(stderr
, "Absolute path required to libreoffice install\n");
60 aTimes
.push_back(TimeRecord("initialization"));
61 // coverity[tainted_string] - build time test tool
62 Office
*pOffice
= lok_cpp_init(argv
[1]);
63 aTimes
.push_back(TimeRecord());
67 aTimes
.push_back(TimeRecord("load document"));
68 Document
*pDocument(pOffice
->documentLoad(argv
[2]));
69 aTimes
.push_back(TimeRecord());
71 aTimes
.push_back(TimeRecord("getparts"));
72 int nParts
= pDocument
->getParts();
73 aTimes
.push_back(TimeRecord());
75 aTimes
.push_back(TimeRecord("get size of parts"));
76 for (int nPart
= 0; nPart
< nParts
; nPart
++)
78 char* pName
= pDocument
->getPartName(nPart
);
79 pDocument
->setPart(nPart
);
80 long nWidth
= 0, nHeight
= 0;
81 pDocument
->getDocumentSize(&nWidth
, &nHeight
);
82 fprintf (stderr
, " '%s' -> %ld, %ld\n", pName
, nWidth
, nHeight
);
85 aTimes
.push_back(TimeRecord());
87 unsigned char pPixels
[256*256*4];
88 for (int nPart
= 0; nPart
< nParts
; nPart
++)
91 char* pName
= pDocument
->getPartName(nPart
);
92 fprintf (stderr
, "render '%s'\n", pName
);
95 pDocument
->setPart(nPart
);
96 long nWidth
= 0, nHeight
= 0;
97 pDocument
->getDocumentSize(&nWidth
, &nHeight
);
100 aTimes
.push_back(TimeRecord("render whole document"));
101 pDocument
->paintTile(pPixels
, 256, 256,
102 0, 0, nWidth
, nHeight
); // not square
103 aTimes
.push_back(TimeRecord());
107 aTimes
.push_back(TimeRecord("render sub-region at 1:1"));
109 int nSplit
= nWidth
/ 4;
110 for (int nX
= 0; nX
< 4; nX
++)
112 for (int nY
= 0; nY
< nHeight
/ nSplit
; nY
++)
114 int nTilePosX
= nX
* nSplit
;
115 int nTilePosY
= nY
* nSplit
;
116 pDocument
->paintTile(pPixels
, 256, 256,
117 nTilePosX
, nTilePosY
, 256, 256);
119 fprintf (stderr
, " rendered tile %d at %d, %d\n",
120 nTiles
, nTilePosX
, nTilePosY
);
123 aTimes
.push_back(TimeRecord());
127 aTimes
.push_back(TimeRecord("render sub-regions at scale"));
129 int nSplit
= nWidth
/ 4;
130 for (int nX
= 0; nX
< 4; nX
++)
132 for (int nY
= 0; nY
< nHeight
/ nSplit
; nY
++)
134 int nTilePosX
= nX
* nSplit
;
135 int nTilePosY
= nY
* nSplit
;
136 pDocument
->paintTile(pPixels
, 256, 256,
137 nTilePosX
, nTilePosY
, nSplit
, nSplit
);
139 fprintf (stderr
, " rendered tile %d at %d, %d\n",
140 nTiles
, nTilePosX
, nTilePosY
);
143 aTimes
.push_back(TimeRecord());
147 aTimes
.push_back(TimeRecord("destroy document"));
149 aTimes
.push_back(TimeRecord());
155 fprintf (stderr
, "profile run:\n");
156 for (size_t i
= 0; i
< aTimes
.size() - 1; i
++)
158 double nDelta
= aTimes
[i
+1].mfTime
- aTimes
[i
].mfTime
;
159 fprintf (stderr
, " %s - %2.4f(ms)\n", aTimes
[i
].mpName
, nDelta
* 1000.0);
160 if (aTimes
[i
+1].mpName
== NULL
)
164 fprintf (stderr
, "Total: %2.4f(s)\n", nTotal
);
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */