summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2018-06-28 20:48:01 +0100
committerMichael Meeks <michael.meeks@collabora.com>2018-07-09 10:14:37 +0200
commita8ebc12eabe2e49e7d1564027c7128898279944e (patch)
tree3e20d797c7a32e49e6d5e18adfe7e252e1f4e2dc /libreofficekit
parent8a2414e4691ceb61559233570dd9df1221d164ea (diff)
tilebench: add dialog profiling mode.
Change-Id: I4661664d1206aacdaf22a4a8f05d7962547faf45 Reviewed-on: https://gerrit.libreoffice.org/56765 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/Executable_tilebench.mk4
-rw-r--r--libreofficekit/qa/tilebench/tilebench.cxx96
2 files changed, 92 insertions, 8 deletions
diff --git a/libreofficekit/Executable_tilebench.mk b/libreofficekit/Executable_tilebench.mk
index 9d8b2a134f99..9977a93351ed 100644
--- a/libreofficekit/Executable_tilebench.mk
+++ b/libreofficekit/Executable_tilebench.mk
@@ -14,6 +14,10 @@ $(eval $(call gb_Executable_set_include,tilebench,\
-I$(SRCDIR)/desktop/inc \
))
+$(eval $(call gb_Executable_use_externals,tilebench,\
+ boost_headers \
+))
+
$(eval $(call gb_Executable_use_libraries,tilebench,\
sal \
))
diff --git a/libreofficekit/qa/tilebench/tilebench.cxx b/libreofficekit/qa/tilebench/tilebench.cxx
index bb9201851612..0984a3feee5c 100644
--- a/libreofficekit/qa/tilebench/tilebench.cxx
+++ b/libreofficekit/qa/tilebench/tilebench.cxx
@@ -13,6 +13,8 @@
#include <cmath>
#include <vector>
+#include <atomic>
+#include <iostream>
#include <fstream>
#include <osl/time.h>
@@ -20,6 +22,9 @@
#include <LibreOfficeKit/LibreOfficeKitInit.h>
#include <LibreOfficeKit/LibreOfficeKit.hxx>
+#include <boost/property_tree/json_parser.hpp>
+#include <boost/optional.hpp>
+
using namespace lok;
static int help( const char *error = nullptr )
@@ -56,8 +61,9 @@ struct TimeRecord {
static std::vector< TimeRecord > aTimes;
/// Dump an array of RGBA or BGRA to an RGB PPM file.
-static void dumpTile(const int nWidth, const int nHeight, const int mode, const char* pBuffer)
+static void dumpTile(const int nWidth, const int nHeight, const int mode, const unsigned char* pBufferU)
{
+ auto pBuffer = reinterpret_cast<const char *>(pBufferU);
std::ofstream ofs("/tmp/dump_tile.ppm");
ofs << "P6\n"
<< nWidth << " "
@@ -154,7 +160,7 @@ void testTile( Document *pDocument, int max_parts,
nWidth/2, 2000, 1000, 1000); // not square
aTimes.emplace_back();
if (dump)
- dumpTile(nTilePixelWidth, nTilePixelHeight, mode, reinterpret_cast<char*>(pPixels));
+ dumpTile(nTilePixelWidth, nTilePixelHeight, mode, pPixels);
}
{ // 1:1
@@ -210,10 +216,72 @@ void testTile( Document *pDocument, int max_parts,
}
}
+static std::atomic<bool> bDialogRendered(false);
+static std::atomic<int> nDialogId(-1);
+
+void kitCallback(int nType, const char* pPayload, void* pData)
+{
+ Document *pDocument = static_cast<Document *>(pData);
+
+ if (nType != LOK_CALLBACK_WINDOW)
+ return;
+
+ std::stringstream aStream(pPayload);
+ boost::property_tree::ptree aRoot;
+ boost::property_tree::read_json(aStream, aRoot);
+ nDialogId = aRoot.get<unsigned>("id");
+ const std::string aAction = aRoot.get<std::string>("action");
+
+ if (aAction == "created")
+ {
+ const std::string aType = aRoot.get<std::string>("type");
+ const std::string aSize = aRoot.get<std::string>("size");
+ int nWidth = atoi(aSize.c_str());
+ int nHeight = 400;
+ const char *pComma = strstr(aSize.c_str(), ", ");
+ if (pComma)
+ nHeight = atoi(pComma + 2);
+ std::cerr << "Size " << aSize << " is " << nWidth << ", " << nHeight << "\n";
+
+ if (aType == "dialog")
+ {
+ aTimes.emplace_back(); // complete wait for dialog
+
+ unsigned char *pBuffer = new unsigned char[nWidth * nHeight * 4];
+
+ aTimes.emplace_back("render dialog");
+ pDocument->paintWindow(nDialogId, pBuffer, 0, 0, nWidth, nHeight);
+ dumpTile(nWidth, nHeight, pDocument->getTileMode(), pBuffer);
+ aTimes.emplace_back();
+
+ delete[] pBuffer;
+
+ bDialogRendered = true;
+ }
+ }
+}
+
void testDialog( Document *pDocument, const char *uno_cmd )
{
- fprintf (stderr, "Stress test a dialog...\n");
- (void)pDocument; (void)uno_cmd;
+ int view = pDocument->createView();
+ pDocument->setView(view);
+ pDocument->registerCallback(kitCallback, pDocument);
+
+ aTimes.emplace_back("open dialog");
+ pDocument->postUnoCommand(uno_cmd, nullptr, true);
+ aTimes.emplace_back();
+
+ aTimes.emplace_back("wait for dialog");
+ while (!bDialogRendered)
+ {
+ usleep (1000);
+ }
+
+ aTimes.emplace_back("post close dialog");
+ pDocument->postWindow(nDialogId, LOK_WINDOW_CLOSE);
+ aTimes.emplace_back();
+
+ pDocument->destroyView(view);
}
int main( int argc, char* argv[] )
@@ -261,10 +329,22 @@ int main( int argc, char* argv[] )
}
else if (!strcmp (mode, "--dialog"))
{
- if (argc > 4)
- testDialog (pDocument, argv[4]);
- else
- return help("missing argument to --dialog");
+ const char *uno_cmd = argc > 4 ? argv[4] : nullptr;
+ if (!uno_cmd)
+ {
+ switch (pDocument->getDocumentType())
+ {
+ case LOK_DOCTYPE_SPREADSHEET:
+ uno_cmd = ".uno:FormatCellDialog";
+ break;
+ case LOK_DOCTYPE_TEXT:
+ case LOK_DOCTYPE_PRESENTATION:
+ case LOK_DOCTYPE_DRAWING:
+ case LOK_DOCTYPE_OTHER:
+ return help("missing argument to --dialog and no default");
+ }
+ }
+ testDialog (pDocument, uno_cmd);
} else
return help ("unknown parameter");
}