kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0098-log-resource-usage-of-unit-tests-on-UNX-platforms.patch

135360
From a105e5ba1e92f91b34e7f25cc4b307900248881a Mon Sep 17 00:00:00 2001
135360
From: Markus Mohrhard <markus.mohrhard@googlemail.com>
135360
Date: Mon, 31 Aug 2015 01:36:02 +0200
135360
Subject: [PATCH 098/398] log resource usage of unit tests on UNX platforms
135360
135360
Change-Id: I3788eae60f73bc42488bf2e4961922962f7e505b
135360
Reviewed-on: https://gerrit.libreoffice.org/18155
135360
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
135360
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
135360
(cherry picked from commit 87514b0907dfbb479e2646b5ff951c68babf3417)
135360
---
135360
 sal/cppunittester/cppunittester.cxx | 50 +++++++++++++++++++++++++++++++++++++
135360
 solenv/gbuild/CppunitTest.mk        |  2 +-
135360
 2 files changed, 51 insertions(+), 1 deletion(-)
135360
135360
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
135360
index b637fb62cb2d..ef9212d6a2fa 100644
135360
--- a/sal/cppunittester/cppunittester.cxx
135360
+++ b/sal/cppunittester/cppunittester.cxx
135360
@@ -21,6 +21,11 @@
135360
 #include <windows.h>
135360
 #endif
135360
 
135360
+#ifdef UNX
135360
+#include <sys/time.h>
135360
+#include <sys/resource.h>
135360
+#endif
135360
+
135360
 #include <cstdlib>
135360
 #include <iostream>
135360
 #include <string>
135360
@@ -292,11 +297,48 @@ public:
135360
     }
135360
 };
135360
 
135360
+#ifdef UNX
135360
+
135360
+double get_time(timeval* time)
135360
+{
135360
+    double nTime = (double)time->tv_sec;
135360
+    nTime += ((double)time->tv_usec)/1000000.0;
135360
+    return nTime;
135360
+}
135360
+
135360
+OString generateTestName(const OUString& rPath)
135360
+{
135360
+    sal_Int32 nPathSep = rPath.lastIndexOf("/");
135360
+    OUString aTestName = rPath.copy(nPathSep+1);
135360
+    return OUStringToOString(aTestName, RTL_TEXTENCODING_UTF8);
135360
+}
135360
+
135360
+void reportResourceUsage(const OUString& rPath)
135360
+{
135360
+    OUString aFullPath = rPath + OUString(".resource.log");
135360
+    rusage resource_usage;
135360
+    getrusage(RUSAGE_SELF, &resource_usage);
135360
+
135360
+    OString aPath = OUStringToOString(aFullPath, RTL_TEXTENCODING_UTF8);
135360
+    std::ofstream resource_file(aPath.getStr());
135360
+    resource_file << "Name = " << generateTestName(rPath) << std::endl;
135360
+    double nUserSpace = get_time(&resource_usage.ru_utime);
135360
+    double nKernelSpace = get_time(&resource_usage.ru_stime);
135360
+    resource_file << "UserSpace = " << nUserSpace << std::endl;
135360
+    resource_file << "KernelSpace = " << nKernelSpace << std::endl;
135360
+}
135360
+#else
135360
+void reportResourceUsage(const OUString& /*rPath*/)
135360
+{
135360
+}
135360
+#endif
135360
+
135360
 }
135360
 
135360
 SAL_IMPLEMENT_MAIN()
135360
 {
135360
     bool ok = false;
135360
+    OUString path;
135360
     try
135360
     {
135360
 #ifdef WNT
135360
@@ -322,6 +364,12 @@ SAL_IMPLEMENT_MAIN()
135360
         while (index < rtl_getAppCommandArgCount())
135360
         {
135360
             rtl::OUString arg = getArgument(index);
135360
+            if (arg == "--target")
135360
+            {
135360
+                path = getArgument(++index);
135360
+                ++index;
135360
+                continue;
135360
+            }
135360
             if ( arg != "--protector" )
135360
             {
135360
                 if (testlib.empty())
135360
@@ -383,6 +431,8 @@ SAL_IMPLEMENT_MAIN()
135360
         SAL_WARN("vcl.app", "Fatal exception: " << e.what());
135360
     }
135360
 
135360
+    reportResourceUsage(path);
135360
+
135360
     return ok ? EXIT_SUCCESS : EXIT_FAILURE;
135360
 }
135360
 
135360
diff --git a/solenv/gbuild/CppunitTest.mk b/solenv/gbuild/CppunitTest.mk
135360
index 021ecc8c37aa..944a87ab612d 100644
135360
--- a/solenv/gbuild/CppunitTest.mk
135360
+++ b/solenv/gbuild/CppunitTest.mk
135360
@@ -101,7 +101,7 @@ $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_RUNTIMEDEPS)
135360
 			PYTHONDONTWRITEBYTECODE=1) \
135360
 		$(ICECREAM_RUN) $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) $(gb_CppunitTest_CPPTESTCOMMAND) \
135360
 		$(call gb_LinkTarget_get_target,$(call gb_CppunitTest_get_linktarget,$*)) \
135360
-		$(call gb_CppunitTest__make_args) \
135360
+		$(call gb_CppunitTest__make_args) --target $@ \
135360
 		$(if $(gb_CppunitTest__interactive),, \
135360
 			> $@.log 2>&1 \
135360
 			|| ($(if $(value gb_CppunitTest_postprocess), \
135360
-- 
135360
2.12.0
135360