tdf#107038 Poco::Timestamp replacement with std::chrono

Change-Id: I55ba23fb104a90c882bc2af068b835e30877bc1e
Reviewed-on: https://gerrit.libreoffice.org/78925
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index b201e4d..1f4ea15 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -46,7 +46,6 @@
using Poco::JSON::Object;
using Poco::JSON::Parser;
using Poco::StringTokenizer;
using Poco::Timestamp;
using Poco::URI;

using namespace LOOLProtocol;
@@ -662,7 +661,7 @@
    output.resize(response.size());
    std::memcpy(output.data(), response.data(), response.size());

    Timestamp timestamp;
    const auto start = std::chrono::system_clock::now();
    // renderFont use a default font size (25) when width and height are 0
    int width = 0, height = 0;
    unsigned char* ptrFont = nullptr;
@@ -671,7 +670,9 @@

    ptrFont = getLOKitDocument()->renderFont(decodedFont.c_str(), decodedChar.c_str(), &width, &height);

    LOG_TRC("renderFont [" << font << "] rendered in " << (timestamp.elapsed()/1000.) << "ms");
    const auto duration = std::chrono::system_clock::now() - start;
    const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
    LOG_TRC("renderFont [" << font << "] rendered in " << elapsed << "ms");

    if (!ptrFont)
    {
@@ -1457,14 +1458,18 @@
    std::vector<unsigned char> pixmap(pixmapDataSize);
    int width = bufferWidth, height = bufferHeight;
    std::string response;
    Timestamp timestamp;
    const auto start = std::chrono::system_clock::now();
    getLOKitDocument()->paintWindow(winId, pixmap.data(), startX, startY, width, height, dpiScale);
    const double area = width * height;

    const auto duration = std::chrono::system_clock::now() - start;
    const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
    const double totalTime = elapsed/1000.;
    LOG_TRC("paintWindow for " << winId << " returned " << width << "X" << height
            << "@(" << startX << "," << startY << ")"
            << " with dpi scale: " << dpiScale
            << " and rendered in " << (timestamp.elapsed()/1000.)
            << "ms (" << area / (timestamp.elapsed()) << " MP/s).");
            << " and rendered in " << totalTime
            << "ms (" << area / elapsed << " MP/s).");

    response = "windowpaint: id=" + tokens[1] +
        " width=" + std::to_string(width) + " height=" + std::to_string(height);
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index b2a4a8b..0dd75ff 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -97,7 +97,6 @@
using Poco::JSON::Parser;
using Poco::StringTokenizer;
using Poco::Thread;
using Poco::Timestamp;
using Poco::URI;
using Poco::Util::Application;

@@ -1119,17 +1118,19 @@

        // Render the whole area
        const double area = pixmapWidth * pixmapHeight;
        Timestamp timestamp;
        auto start = std::chrono::system_clock::now();
        LOG_TRC("Calling paintPartTile(" << (void*)pixmap.data() << ")");
        _loKitDocument->paintPartTile(pixmap.data(),
                                      tileCombined.getPart(),
                                      pixmapWidth, pixmapHeight,
                                      renderArea.getLeft(), renderArea.getTop(),
                                      renderArea.getWidth(), renderArea.getHeight());
        Timestamp::TimeDiff elapsed = timestamp.elapsed();
        auto duration = std::chrono::system_clock::now() - start;
        auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
        double totalTime = elapsed/1000.;
        LOG_DBG("paintTile (combined) at (" << renderArea.getLeft() << ", " << renderArea.getTop() << "), (" <<
                renderArea.getWidth() << ", " << renderArea.getHeight() << ") " <<
                " rendered in " << (elapsed/1000.) << " ms (" << area / elapsed << " MP/s).");
                " rendered in " << totalTime << " ms (" << area / elapsed << " MP/s).");
        const auto mode = static_cast<LibreOfficeKitTileMode>(_loKitDocument->getTileMode());

        std::vector<char> output;
@@ -1267,10 +1268,12 @@

        _pngCache.balanceCache();

        elapsed = timestamp.elapsed();
        duration = std::chrono::system_clock::now() - start;
        elapsed = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
        totalTime = elapsed/1000.;
        LOG_DBG("renderCombinedTiles at (" << renderArea.getLeft() << ", " << renderArea.getTop() << "), (" <<
                renderArea.getWidth() << ", " << renderArea.getHeight() << ") " <<
                " took " << (elapsed/1000.) << " ms (including the paintTile).");
                " took " << totalTime << " ms (including the paintTile).");

        if (tileIndex == 0)
        {
@@ -1766,9 +1769,12 @@
            _isDocPasswordProtected = false;

            LOG_DBG("Calling lokit::documentLoad(" << uriAnonym << ", \"" << options << "\").");
            Timestamp timestamp;
            const auto start = std::chrono::system_clock::now();
            _loKitDocument.reset(_loKit->documentLoad(docTemplate.empty() ? uri.c_str() : docTemplate.c_str(), options.c_str()));
            LOG_DBG("Returned lokit::documentLoad(" << uriAnonym << ") in " << (timestamp.elapsed() / 1000.) << "ms.");
            const auto duration = std::chrono::system_clock::now() - start;
            const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
            const double totalTime = elapsed/1000.;
            LOG_DBG("Returned lokit::documentLoad(" << uriAnonym << ") in " << totalTime << "ms.");
#ifdef IOS
            // The iOS app (and the Android one) has max one document open at a time, so we can keep
            // a pointer to it in a global.
diff --git a/test/UnitPrefork.cpp b/test/UnitPrefork.cpp
index 827e1c0..4f22ffb 100644
--- a/test/UnitPrefork.cpp
+++ b/test/UnitPrefork.cpp
@@ -17,7 +17,7 @@
// Inside the WSD process
class UnitPrefork : public UnitWSD
{
    Poco::Timestamp _startTime;
    std::chrono::system_clock::time_point _startTime = std::chrono::system_clock::now();
    std::atomic< int > _childSockets;

public:
@@ -40,9 +40,10 @@

        if (_childSockets >= NumToPrefork)
        {
            Poco::Timestamp::TimeDiff elapsed = _startTime.elapsed();
            const auto duration = std::chrono::system_clock::now() - _startTime;
            const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
            const double totalTime = elapsed/1000.;

            const double totalTime = (1000. * elapsed)/Poco::Timestamp::resolution();
            LOG_INF("Launched " << _childSockets << " in " << totalTime);
            std::cerr << "Launch time total   " << totalTime << " ms" << std::endl;
            std::cerr << "Launch time average " << (totalTime / _childSockets) << " ms" << std::endl;