Kaydet (Commit) 87514b09 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

log resource usage of unit tests on UNX platforms

Change-Id: I3788eae60f73bc42488bf2e4961922962f7e505b
Reviewed-on: https://gerrit.libreoffice.org/18155Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst c511b279
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
#include <windows.h> #include <windows.h>
#endif #endif
#ifdef UNX
#include <sys/time.h>
#include <sys/resource.h>
#endif
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <string> #include <string>
...@@ -292,11 +297,48 @@ public: ...@@ -292,11 +297,48 @@ public:
} }
}; };
#ifdef UNX
double get_time(timeval* time)
{
double nTime = (double)time->tv_sec;
nTime += ((double)time->tv_usec)/1000000.0;
return nTime;
}
OString generateTestName(const OUString& rPath)
{
sal_Int32 nPathSep = rPath.lastIndexOf("/");
OUString aTestName = rPath.copy(nPathSep+1);
return OUStringToOString(aTestName, RTL_TEXTENCODING_UTF8);
}
void reportResourceUsage(const OUString& rPath)
{
OUString aFullPath = rPath + OUString(".resource.log");
rusage resource_usage;
getrusage(RUSAGE_SELF, &resource_usage);
OString aPath = OUStringToOString(aFullPath, RTL_TEXTENCODING_UTF8);
std::ofstream resource_file(aPath.getStr());
resource_file << "Name = " << generateTestName(rPath) << std::endl;
double nUserSpace = get_time(&resource_usage.ru_utime);
double nKernelSpace = get_time(&resource_usage.ru_stime);
resource_file << "UserSpace = " << nUserSpace << std::endl;
resource_file << "KernelSpace = " << nKernelSpace << std::endl;
}
#else
void reportResourceUsage(const OUString& /*rPath*/)
{
}
#endif
} }
SAL_IMPLEMENT_MAIN() SAL_IMPLEMENT_MAIN()
{ {
bool ok = false; bool ok = false;
OUString path;
try try
{ {
#ifdef WNT #ifdef WNT
...@@ -322,6 +364,12 @@ SAL_IMPLEMENT_MAIN() ...@@ -322,6 +364,12 @@ SAL_IMPLEMENT_MAIN()
while (index < rtl_getAppCommandArgCount()) while (index < rtl_getAppCommandArgCount())
{ {
rtl::OUString arg = getArgument(index); rtl::OUString arg = getArgument(index);
if (arg == "--target")
{
path = getArgument(++index);
++index;
continue;
}
if ( arg != "--protector" ) if ( arg != "--protector" )
{ {
if (testlib.empty()) if (testlib.empty())
...@@ -383,6 +431,8 @@ SAL_IMPLEMENT_MAIN() ...@@ -383,6 +431,8 @@ SAL_IMPLEMENT_MAIN()
SAL_WARN("vcl.app", "Fatal exception: " << e.what()); SAL_WARN("vcl.app", "Fatal exception: " << e.what());
} }
reportResourceUsage(path);
return ok ? EXIT_SUCCESS : EXIT_FAILURE; return ok ? EXIT_SUCCESS : EXIT_FAILURE;
} }
......
...@@ -102,7 +102,7 @@ $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_RUNTIMEDEPS) ...@@ -102,7 +102,7 @@ $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_RUNTIMEDEPS)
PYTHONDONTWRITEBYTECODE=1) \ PYTHONDONTWRITEBYTECODE=1) \
$(ICECREAM_RUN) $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) $(gb_CppunitTest_CPPTESTCOMMAND) \ $(ICECREAM_RUN) $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) $(gb_CppunitTest_CPPTESTCOMMAND) \
$(call gb_LinkTarget_get_target,$(call gb_CppunitTest_get_linktarget,$*)) \ $(call gb_LinkTarget_get_target,$(call gb_CppunitTest_get_linktarget,$*)) \
$(call gb_CppunitTest__make_args) \ $(call gb_CppunitTest__make_args) --target $@ \
$(if $(gb_CppunitTest__interactive),, \ $(if $(gb_CppunitTest__interactive),, \
> $@.log 2>&1 \ > $@.log 2>&1 \
|| ($(if $(value gb_CppunitTest_postprocess), \ || ($(if $(value gb_CppunitTest_postprocess), \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment