Kaydet (Commit) e4e7f9d8 authored tarafından Matúš Kukan's avatar Matúš Kukan

Improve framework for callgrind performance unit tests

Do not abort in tests which take longer then before.
Since 4f5f6d24 we have nice tool to
collect callgrind results, store them..

Also, make it not necessary to duplicate anything. Any test can be turned
into a performance test by using callgrindStart/callgrindDump. You only
need to duplicate the makefile name in gb_Module_add_perfcheck_targets.

So, if the test is run as part of 'perfcheck', it runs under callgrind,
otherwise it behaves like a regular unit test.

Change-Id: I7acbb855b1823c9a32ba126abb57dccc767ca239
üst d8bc093d
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_TEST_CALLGRIND_HXX
#define INCLUDED_TEST_CALLGRIND_HXX
#include <sal/config.h>
#include <test/testdllapi.hxx>
void OOO_DLLPUBLIC_TEST callgrindStart();
void OOO_DLLPUBLIC_TEST callgrindDump(const char* name);
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -34,6 +34,11 @@ GLIBCXX_FORCE_NEW := 1
endif
endif
ifneq (,$(filter perfcheck,$(MAKECMDGOALS)))
$(if $(ENABLE_VALGRIND),,$(call gb_Output_error,Running performance tests with empty $$(ENABLE_VALGRIND) does not make sense))
gb_CppunitTest_VALGRINDTOOL := valgrind --tool=callgrind --dump-instr=yes --instr-atstart=no
endif
# defined by platform
# gb_CppunitTest_TARGETTYPE
# gb_CppunitTest_get_filename
......@@ -94,10 +99,7 @@ $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_CPPTESTDEPS)
|| ($(if $(value gb_CppunitTest_postprocess), \
RET=$$?; \
$(call gb_CppunitTest_postprocess,$(gb_CppunitTest_CPPTESTCOMMAND),$@.core,$$RET) >> $@.log 2>&1;) \
cat $@.log; $(SRCDIR)/solenv/bin/unittest-failed.sh Cppunit $*))) \
$(if $(PERFTEST), && VAL=$$(grep '^==.*== Collected : ' $@.log | sed "s/==.*== Collected : //") && \
$(if $(filter 0,$(PERFTEST)), expr "$$VAL" "*" "101" "/" "100", test $$VAL -le $(PERFTEST) || (echo "Unit test is slow! $$VAL instructions detected (expected $(PERFTEST))." && false))) \
)
cat $@.log; $(SRCDIR)/solenv/bin/unittest-failed.sh Cppunit $*))))
define gb_CppunitTest_CppunitTest
$(call gb_CppunitTest__CppunitTest_impl,$(1),$(call gb_CppunitTest_get_linktarget,$(1)))
......@@ -147,21 +149,6 @@ $(call gb_CppunitTest_get_target,$(1)) : ARGS += $(2)
endef
# Run this unit test with callgrind tool to measure performance. If you are
# creating a new test, first set the number to 0, run the test, and it will
# print an number for you to use as a second parameter here. The test will
# fail if reported number of instructions will be bigger than this parameter.
#
# call gb_CppunitTest_set_performance_test,name,instructions_number
define gb_CppunitTest_set_performance_test
$(if $(ENABLE_VALGRIND),,$(call gb_Output_error,gb_CppunitTest_set_performance_test used with empty $$(ENABLE_VALGRIND)))
$(call gb_CppunitTest_get_target,$(1)) : PERFTEST := $(2)
$(call gb_CppunitTest_get_target,$(1)) : gb_CppunitTest_VALGRINDTOOL := valgrind --tool=callgrind --dump-instr=yes --instr-atstart=no
$(call gb_CppunitTest_use_external,$(1),valgrind)
endef
define gb_CppunitTest_use_ure
$(call gb_CppunitTest_use_rdb,$(1),ure/services)
$(call gb_CppunitTest_get_target,$(1)) : URE := $(true)
......
......@@ -22,6 +22,8 @@ endif
ifeq (,$(filter perfcheck,$(MAKECMDGOALS)))
gb_Module_SKIPTARGETS += perfcheck
else
gb_Module_SKIPTARGETS += check slowcheck subsequentcheck
endif
ifneq ($(strip $(MAKECMDGOALS)),)
......
......@@ -19,6 +19,7 @@ $(eval $(call gb_Library_use_externals,test,\
boost_headers \
cppunit \
libxml2 \
valgrind \
))
$(eval $(call gb_Library_use_libraries,test,\
......@@ -40,6 +41,7 @@ $(eval $(call gb_Library_use_libraries,test,\
$(eval $(call gb_Library_add_exception_objects,test,\
test/source/bootstrapfixture \
test/source/diff/diff \
test/source/callgrind \
test/source/xmltesttools \
test/source/htmltesttools \
test/source/mtfxmldump \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <test/callgrind.hxx>
#ifdef HAVE_VALGRIND_HEADERS
#include <valgrind/callgrind.h>
#else
#define CALLGRIND_START_INSTRUMENTATION
#define CALLGRIND_ZERO_STATS
#define CALLGRIND_STOP_INSTRUMENTATION
#define CALLGRIND_DUMP_STATS_AT(name) (void)name;
#endif
void callgrindStart()
{
CALLGRIND_ZERO_STATS;
CALLGRIND_START_INSTRUMENTATION;
};
void callgrindDump(const char* name)
{
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS_AT(name);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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