diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 11:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 11:36:04 +0000 |
commit | 040eee1aa49b49df4698d83a05af57c220127fd1 (patch) | |
tree | f635435954e6ccde5eee9893889e24f30ca68346 /src/lib/stats | |
parent | Initial commit. (diff) | |
download | isc-kea-upstream.tar.xz isc-kea-upstream.zip |
Adding upstream version 2.2.0.upstream/2.2.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/lib/stats/Makefile.am | 28 | ||||
-rw-r--r-- | src/lib/stats/Makefile.in | 954 | ||||
-rw-r--r-- | src/lib/stats/context.cc | 99 | ||||
-rw-r--r-- | src/lib/stats/context.h | 90 | ||||
-rw-r--r-- | src/lib/stats/observation.cc | 506 | ||||
-rw-r--r-- | src/lib/stats/observation.h | 445 | ||||
-rw-r--r-- | src/lib/stats/stats.dox | 16 | ||||
-rw-r--r-- | src/lib/stats/stats_mgr.cc | 645 | ||||
-rw-r--r-- | src/lib/stats/stats_mgr.h | 789 | ||||
-rw-r--r-- | src/lib/stats/tests/Makefile.am | 35 | ||||
-rw-r--r-- | src/lib/stats/tests/Makefile.in | 1017 | ||||
-rw-r--r-- | src/lib/stats/tests/context_unittest.cc | 126 | ||||
-rw-r--r-- | src/lib/stats/tests/observation_unittest.cc | 619 | ||||
-rw-r--r-- | src/lib/stats/tests/run_unittests.cc | 18 | ||||
-rw-r--r-- | src/lib/stats/tests/stats_mgr_unittest.cc | 1117 | ||||
-rw-r--r-- | src/lib/stats/testutils/Makefile.am | 1 | ||||
-rw-r--r-- | src/lib/stats/testutils/Makefile.in | 524 | ||||
-rw-r--r-- | src/lib/stats/testutils/stats_test_utils.h | 64 |
18 files changed, 7093 insertions, 0 deletions
diff --git a/src/lib/stats/Makefile.am b/src/lib/stats/Makefile.am new file mode 100644 index 0000000..37f3e41 --- /dev/null +++ b/src/lib/stats/Makefile.am @@ -0,0 +1,28 @@ +SUBDIRS = . tests testutils + +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib +AM_CPPFLAGS += $(BOOST_INCLUDES) +AM_CXXFLAGS = $(KEA_CXXFLAGS) + +lib_LTLIBRARIES = libkea-stats.la +libkea_stats_la_SOURCES = observation.h observation.cc +libkea_stats_la_SOURCES += context.h context.cc +libkea_stats_la_SOURCES += stats_mgr.h stats_mgr.cc + +libkea_stats_la_CPPFLAGS = $(AM_CPPFLAGS) +libkea_stats_la_LDFLAGS = -no-undefined -version-info 18:0:0 + +libkea_stats_la_LIBADD = $(top_builddir)/src/lib/cc/libkea-cc.la +libkea_stats_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +libkea_stats_la_LIBADD += $(top_builddir)/src/lib/util/libkea-util.la +libkea_stats_la_LIBADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +libkea_stats_la_LIBADD += $(BOOST_LIBS) + +EXTRA_DIST = stats.dox + +libkea_stats_includedir = $(pkgincludedir)/stats +libkea_stats_include_HEADERS = \ + context.h \ + observation.h \ + stats_mgr.h + diff --git a/src/lib/stats/Makefile.in b/src/lib/stats/Makefile.in new file mode 100644 index 0000000..79d5d4f --- /dev/null +++ b/src/lib/stats/Makefile.in @@ -0,0 +1,954 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/lib/stats +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4macros/ax_boost_for_kea.m4 \ + $(top_srcdir)/m4macros/ax_cpp11.m4 \ + $(top_srcdir)/m4macros/ax_crypto.m4 \ + $(top_srcdir)/m4macros/ax_find_library.m4 \ + $(top_srcdir)/m4macros/ax_gssapi.m4 \ + $(top_srcdir)/m4macros/ax_gtest.m4 \ + $(top_srcdir)/m4macros/ax_isc_rpath.m4 \ + $(top_srcdir)/m4macros/ax_sysrepo.m4 \ + $(top_srcdir)/m4macros/libtool.m4 \ + $(top_srcdir)/m4macros/ltoptions.m4 \ + $(top_srcdir)/m4macros/ltsugar.m4 \ + $(top_srcdir)/m4macros/ltversion.m4 \ + $(top_srcdir)/m4macros/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(libkea_stats_include_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(libdir)" \ + "$(DESTDIR)$(libkea_stats_includedir)" +LTLIBRARIES = $(lib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libkea_stats_la_DEPENDENCIES = \ + $(top_builddir)/src/lib/cc/libkea-cc.la \ + $(top_builddir)/src/lib/asiolink/libkea-asiolink.la \ + $(top_builddir)/src/lib/util/libkea-util.la \ + $(top_builddir)/src/lib/exceptions/libkea-exceptions.la \ + $(am__DEPENDENCIES_1) +am_libkea_stats_la_OBJECTS = libkea_stats_la-observation.lo \ + libkea_stats_la-context.lo libkea_stats_la-stats_mgr.lo +libkea_stats_la_OBJECTS = $(am_libkea_stats_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +libkea_stats_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ + $(AM_CXXFLAGS) $(CXXFLAGS) $(libkea_stats_la_LDFLAGS) \ + $(LDFLAGS) -o $@ +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/libkea_stats_la-context.Plo \ + ./$(DEPDIR)/libkea_stats_la-observation.Plo \ + ./$(DEPDIR)/libkea_stats_la-stats_mgr.Plo +am__mv = mv -f +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +AM_V_CXX = $(am__v_CXX_@AM_V@) +am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@) +am__v_CXX_0 = @echo " CXX " $@; +am__v_CXX_1 = +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CXXLD = $(am__v_CXXLD_@AM_V@) +am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) +am__v_CXXLD_0 = @echo " CXXLD " $@; +am__v_CXXLD_1 = +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libkea_stats_la_SOURCES) +DIST_SOURCES = $(libkea_stats_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(libkea_stats_include_HEADERS) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + distdir distdir-am +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +ASCIIDOC = @ASCIIDOC@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BOOST_INCLUDES = @BOOST_INCLUDES@ +BOOST_LIBS = @BOOST_LIBS@ +BOTAN_TOOL = @BOTAN_TOOL@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CONTRIB_DIR = @CONTRIB_DIR@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPTO_CFLAGS = @CRYPTO_CFLAGS@ +CRYPTO_INCLUDES = @CRYPTO_INCLUDES@ +CRYPTO_LDFLAGS = @CRYPTO_LDFLAGS@ +CRYPTO_LIBS = @CRYPTO_LIBS@ +CRYPTO_PACKAGE = @CRYPTO_PACKAGE@ +CRYPTO_RPATH = @CRYPTO_RPATH@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DISTCHECK_BOOST_CONFIGURE_FLAG = @DISTCHECK_BOOST_CONFIGURE_FLAG@ +DISTCHECK_CONTRIB_CONFIGURE_FLAG = @DISTCHECK_CONTRIB_CONFIGURE_FLAG@ +DISTCHECK_CRYPTO_CONFIGURE_FLAG = @DISTCHECK_CRYPTO_CONFIGURE_FLAG@ +DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@ +DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@ +DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@ +DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@ +DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GENHTML = @GENHTML@ +GREP = @GREP@ +GSSAPI_CFLAGS = @GSSAPI_CFLAGS@ +GSSAPI_LIBS = @GSSAPI_LIBS@ +GTEST_CONFIG = @GTEST_CONFIG@ +GTEST_INCLUDES = @GTEST_INCLUDES@ +GTEST_LDADD = @GTEST_LDADD@ +GTEST_LDFLAGS = @GTEST_LDFLAGS@ +GTEST_SOURCE = @GTEST_SOURCE@ +HAVE_SYSREPO = @HAVE_SYSREPO@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KEA_CXXFLAGS = @KEA_CXXFLAGS@ +KEA_SRCID = @KEA_SRCID@ +KRB5_CONFIG = @KRB5_CONFIG@ +LCOV = @LCOV@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LOG4CPLUS_INCLUDES = @LOG4CPLUS_INCLUDES@ +LOG4CPLUS_LIBS = @LOG4CPLUS_LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PACKAGE_VERSION_TYPE = @PACKAGE_VERSION_TYPE@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PDFLATEX = @PDFLATEX@ +PERL = @PERL@ +PGSQL_CPPFLAGS = @PGSQL_CPPFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PKGPYTHONDIR = @PKGPYTHONDIR@ +PKG_CONFIG = @PKG_CONFIG@ +PLANTUML = @PLANTUML@ +PREMIUM_DIR = @PREMIUM_DIR@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +RANLIB = @RANLIB@ +SED = @SED@ +SEP = @SEP@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SPHINXBUILD = @SPHINXBUILD@ +SRPD_PLUGINS_PATH = @SRPD_PLUGINS_PATH@ +SR_REPO_PATH = @SR_REPO_PATH@ +STRIP = @STRIP@ +SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@ +SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@ +SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@ +SYSREPO_LIBS = @SYSREPO_LIBS@ +SYSREPO_VERSION = @SYSREPO_VERSION@ +USE_LCOV = @USE_LCOV@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +WARNING_GCC_44_STRICT_ALIASING_CFLAG = @WARNING_GCC_44_STRICT_ALIASING_CFLAG@ +YACC = @YACC@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +SUBDIRS = . tests testutils +AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib \ + $(BOOST_INCLUDES) +AM_CXXFLAGS = $(KEA_CXXFLAGS) +lib_LTLIBRARIES = libkea-stats.la +libkea_stats_la_SOURCES = observation.h observation.cc context.h \ + context.cc stats_mgr.h stats_mgr.cc +libkea_stats_la_CPPFLAGS = $(AM_CPPFLAGS) +libkea_stats_la_LDFLAGS = -no-undefined -version-info 18:0:0 +libkea_stats_la_LIBADD = $(top_builddir)/src/lib/cc/libkea-cc.la \ + $(top_builddir)/src/lib/asiolink/libkea-asiolink.la \ + $(top_builddir)/src/lib/util/libkea-util.la \ + $(top_builddir)/src/lib/exceptions/libkea-exceptions.la \ + $(BOOST_LIBS) +EXTRA_DIST = stats.dox +libkea_stats_includedir = $(pkgincludedir)/stats +libkea_stats_include_HEADERS = \ + context.h \ + observation.h \ + stats_mgr.h + +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .cc .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib/stats/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/lib/stats/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +libkea-stats.la: $(libkea_stats_la_OBJECTS) $(libkea_stats_la_DEPENDENCIES) $(EXTRA_libkea_stats_la_DEPENDENCIES) + $(AM_V_CXXLD)$(libkea_stats_la_LINK) -rpath $(libdir) $(libkea_stats_la_OBJECTS) $(libkea_stats_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libkea_stats_la-context.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libkea_stats_la-observation.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libkea_stats_la-stats_mgr.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.cc.o: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $< + +.cc.obj: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cc.lo: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $< + +libkea_stats_la-observation.lo: observation.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libkea_stats_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libkea_stats_la-observation.lo -MD -MP -MF $(DEPDIR)/libkea_stats_la-observation.Tpo -c -o libkea_stats_la-observation.lo `test -f 'observation.cc' || echo '$(srcdir)/'`observation.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libkea_stats_la-observation.Tpo $(DEPDIR)/libkea_stats_la-observation.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='observation.cc' object='libkea_stats_la-observation.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libkea_stats_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libkea_stats_la-observation.lo `test -f 'observation.cc' || echo '$(srcdir)/'`observation.cc + +libkea_stats_la-context.lo: context.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libkea_stats_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libkea_stats_la-context.lo -MD -MP -MF $(DEPDIR)/libkea_stats_la-context.Tpo -c -o libkea_stats_la-context.lo `test -f 'context.cc' || echo '$(srcdir)/'`context.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libkea_stats_la-context.Tpo $(DEPDIR)/libkea_stats_la-context.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='context.cc' object='libkea_stats_la-context.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libkea_stats_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libkea_stats_la-context.lo `test -f 'context.cc' || echo '$(srcdir)/'`context.cc + +libkea_stats_la-stats_mgr.lo: stats_mgr.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libkea_stats_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libkea_stats_la-stats_mgr.lo -MD -MP -MF $(DEPDIR)/libkea_stats_la-stats_mgr.Tpo -c -o libkea_stats_la-stats_mgr.lo `test -f 'stats_mgr.cc' || echo '$(srcdir)/'`stats_mgr.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libkea_stats_la-stats_mgr.Tpo $(DEPDIR)/libkea_stats_la-stats_mgr.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='stats_mgr.cc' object='libkea_stats_la-stats_mgr.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libkea_stats_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libkea_stats_la-stats_mgr.lo `test -f 'stats_mgr.cc' || echo '$(srcdir)/'`stats_mgr.cc + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-libkea_stats_includeHEADERS: $(libkea_stats_include_HEADERS) + @$(NORMAL_INSTALL) + @list='$(libkea_stats_include_HEADERS)'; test -n "$(libkea_stats_includedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(libkea_stats_includedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(libkea_stats_includedir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libkea_stats_includedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(libkea_stats_includedir)" || exit $$?; \ + done + +uninstall-libkea_stats_includeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(libkea_stats_include_HEADERS)'; test -n "$(libkea_stats_includedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(libkea_stats_includedir)'; $(am__uninstall_files_from_dir) + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libkea_stats_includedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-recursive + -rm -f ./$(DEPDIR)/libkea_stats_la-context.Plo + -rm -f ./$(DEPDIR)/libkea_stats_la-observation.Plo + -rm -f ./$(DEPDIR)/libkea_stats_la-stats_mgr.Plo + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: install-libkea_stats_includeHEADERS + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f ./$(DEPDIR)/libkea_stats_la-context.Plo + -rm -f ./$(DEPDIR)/libkea_stats_la-observation.Plo + -rm -f ./$(DEPDIR)/libkea_stats_la-stats_mgr.Plo + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-libLTLIBRARIES \ + uninstall-libkea_stats_includeHEADERS + +.MAKE: $(am__recursive_targets) install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--depfiles check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool cscopelist-am ctags \ + ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-libLTLIBRARIES \ + install-libkea_stats_includeHEADERS install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs installdirs-am \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-libLTLIBRARIES uninstall-libkea_stats_includeHEADERS + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/lib/stats/context.cc b/src/lib/stats/context.cc new file mode 100644 index 0000000..697b3de --- /dev/null +++ b/src/lib/stats/context.cc @@ -0,0 +1,99 @@ +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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 <config.h> + +#include <stats/context.h> +#include <util/multi_threading_mgr.h> +#include <map> + +using namespace std; +using namespace isc::data; +using namespace isc::util; + +namespace isc { +namespace stats { + +ObservationPtr +StatContext::get(const std::string& name) const { + auto obs = stats_.find(name); + if (obs != stats_.end()) { + return (obs->second); + } + return (ObservationPtr()); +} + +void +StatContext::add(const ObservationPtr& obs) { + auto existing = stats_.find(obs->getName()); + if (existing == stats_.end()) { + stats_.insert(make_pair(obs->getName() ,obs)); + } else { + isc_throw(DuplicateStat, "Statistic named " << obs->getName() + << " already exists."); + } +} + +bool +StatContext::del(const std::string& name) { + auto obs = stats_.find(name); + if (obs != stats_.end()) { + stats_.erase(obs); + return (true); + } + return (false); +} + +size_t +StatContext::size() { + return (stats_.size()); +} + +void +StatContext::clear() { + stats_.clear(); +} + +void +StatContext::resetAll() { + // Let's iterate over all stored statistics... + for (auto s : stats_) { + // ... and reset each statistic. + s.second->reset(); + } +} + +ConstElementPtr +StatContext::getAll() const { + ElementPtr map = Element::createMap(); // a map + // Let's iterate over all stored statistics... + for (auto s : stats_) { + // ... and add each of them to the map. + map->set(s.first, s.second->getJSON()); + } + return (map); +} + +void +StatContext::setMaxSampleCountAll(uint32_t max_samples) { + // Let's iterate over all stored statistics... + for (auto s : stats_) { + // ... and set count limit for each statistic. + s.second->setMaxSampleCount(max_samples); + } +} + +void +StatContext::setMaxSampleAgeAll(const StatsDuration& duration) { + // Let's iterate over all stored statistics... + for (auto s : stats_) { + // ... and set duration limit for each statistic. + s.second->setMaxSampleAge(duration); + } +} + +} // namespace stats +} // namespace isc diff --git a/src/lib/stats/context.h b/src/lib/stats/context.h new file mode 100644 index 0000000..117872f --- /dev/null +++ b/src/lib/stats/context.h @@ -0,0 +1,90 @@ +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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 CONTEXT_H +#define CONTEXT_H + +#include <stats/observation.h> +#include <boost/shared_ptr.hpp> +#include <mutex> +#include <string> + +namespace isc { +namespace stats { + +/// @brief Exception indicating that a given statistic is duplicated. +class DuplicateStat : public Exception { +public: + DuplicateStat(const char* file, size_t line, const char* what) : + isc::Exception(file, line, what) {} +}; + +/// @brief Statistics context +/// +/// Statistics context is essentially a container used to group statistics +/// related to a given context together. Two examples of such contexts are +/// all statistics related to a given subnet or all statistics related to a +/// given network interface. +struct StatContext { +public: + + /// @brief Attempts to get an observation + /// + /// @param name name of the statistic + /// @return appropriate Observation object (or NULL) + ObservationPtr get(const std::string& name) const; + + /// @brief Adds a new observation + /// + /// @param obs observation to be added + /// @throw DuplicateStat if an observation with the same name exists already + void add(const ObservationPtr& obs); + + /// @brief Attempts to delete an observation + /// + /// @param name name of the observation to be deleted + /// @return true if successful, false if no such statistic was found + bool del(const std::string& name); + + /// @brief Returns the number of observations + /// + /// @return the number of observations + size_t size(); + + /// @brief Removes all observations + void clear(); + + /// @brief Resets all observations + void resetAll(); + + /// @brief Sets max sample count for all observations + /// + /// @param max_samples value to be set for all observations + void setMaxSampleCountAll(uint32_t max_samples); + + /// @brief Sets duration for all observations + /// + /// @param duration value to be set for all observations + void setMaxSampleAgeAll(const StatsDuration& duration); + + /// @brief Returns a map with all observations + /// + /// @return map with all observations + isc::data::ConstElementPtr getAll() const; + +private: + + /// @brief Statistics container + std::map<std::string, ObservationPtr> stats_; +}; + +/// @brief Pointer to the statistics context +typedef boost::shared_ptr<StatContext> StatContextPtr; + +}; +}; + +#endif // CONTEXT_H diff --git a/src/lib/stats/observation.cc b/src/lib/stats/observation.cc new file mode 100644 index 0000000..2128f53 --- /dev/null +++ b/src/lib/stats/observation.cc @@ -0,0 +1,506 @@ +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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 <config.h> + +#include <stats/observation.h> +#include <util/chrono_time_utils.h> +#include <cc/data.h> +#include <chrono> +#include <utility> + +using namespace std; +using namespace std::chrono; +using namespace isc::data; + +namespace isc { +namespace stats { + +std::pair<bool, uint32_t> +Observation::default_max_sample_count_ = std::make_pair(true, 20); + +std::pair<bool, StatsDuration> +Observation::default_max_sample_age_ = + std::make_pair(false, StatsDuration::zero()); + +Observation::Observation(const std::string& name, const int64_t value) : + name_(name), type_(STAT_INTEGER), + max_sample_count_(default_max_sample_count_), + max_sample_age_(default_max_sample_age_) { + setValue(value); +} + +Observation::Observation(const std::string& name, const double value) : + name_(name), type_(STAT_FLOAT), + max_sample_count_(default_max_sample_count_), + max_sample_age_(default_max_sample_age_) { + setValue(value); +} + +Observation::Observation(const std::string& name, const StatsDuration& value) : + name_(name), type_(STAT_DURATION), + max_sample_count_(default_max_sample_count_), + max_sample_age_(default_max_sample_age_) { + setValue(value); +} + +Observation::Observation(const std::string& name, const std::string& value) : + name_(name), type_(STAT_STRING), + max_sample_count_(default_max_sample_count_), + max_sample_age_(default_max_sample_age_) { + setValue(value); +} + +void Observation::setMaxSampleAge(const StatsDuration& duration) { + switch(type_) { + case STAT_INTEGER: { + setMaxSampleAgeInternal(integer_samples_, duration, STAT_INTEGER); + return; + } + case STAT_FLOAT: { + setMaxSampleAgeInternal(float_samples_, duration, STAT_FLOAT); + return; + } + case STAT_DURATION: { + setMaxSampleAgeInternal(duration_samples_, duration, STAT_DURATION); + return; + } + case STAT_STRING: { + setMaxSampleAgeInternal(string_samples_, duration, STAT_STRING); + return; + } + default: + isc_throw(InvalidStatType, "Unknown statistic type: " + << typeToText(type_)); + }; +} + +void Observation::setMaxSampleCount(uint32_t max_samples) { + switch(type_) { + case STAT_INTEGER: { + setMaxSampleCountInternal(integer_samples_, max_samples, STAT_INTEGER); + return; + } + case STAT_FLOAT: { + setMaxSampleCountInternal(float_samples_, max_samples, STAT_FLOAT); + return; + } + case STAT_DURATION: { + setMaxSampleCountInternal(duration_samples_, max_samples, STAT_DURATION); + return; + } + case STAT_STRING: { + setMaxSampleCountInternal(string_samples_, max_samples, STAT_STRING); + return; + } + default: + isc_throw(InvalidStatType, "Unknown statistic type: " + << typeToText(type_)); + }; +} + +void Observation::addValue(const int64_t value) { + IntegerSample current = getInteger(); + setValue(current.first + value); +} + +void Observation::addValue(const double value) { + FloatSample current = getFloat(); + setValue(current.first + value); +} + +void Observation::addValue(const StatsDuration& value) { + DurationSample current = getDuration(); + setValue(current.first + value); +} + +void Observation::addValue(const std::string& value) { + StringSample current = getString(); + setValue(current.first + value); +} + +void Observation::setValue(const int64_t value) { + setValueInternal(value, integer_samples_, STAT_INTEGER); +} + +void Observation::setValue(const double value) { + setValueInternal(value, float_samples_, STAT_FLOAT); +} + +void Observation::setValue(const StatsDuration& value) { + setValueInternal(value, duration_samples_, STAT_DURATION); +} + +void Observation::setValue(const std::string& value) { + setValueInternal(value, string_samples_, STAT_STRING); +} + +size_t Observation::getSize() const { + size_t size = 0; + switch(type_) { + case STAT_INTEGER: { + size = getSizeInternal(integer_samples_, STAT_INTEGER); + return (size); + } + case STAT_FLOAT: { + size = getSizeInternal(float_samples_, STAT_FLOAT); + return (size); + } + case STAT_DURATION: { + size = getSizeInternal(duration_samples_, STAT_DURATION); + return (size); + } + case STAT_STRING: { + size = getSizeInternal(string_samples_, STAT_STRING); + return (size); + } + default: + isc_throw(InvalidStatType, "Unknown statistic type: " + << typeToText(type_)); + }; + return (size); +} + +std::pair<bool, StatsDuration> Observation::getMaxSampleAge() const { + return (max_sample_age_); +} + +std::pair<bool, uint32_t> Observation::getMaxSampleCount() const { + return (max_sample_count_); +} + +template<typename StorageType> +size_t Observation::getSizeInternal(StorageType& storage, Type exp_type) const { + if (type_ != exp_type) { + isc_throw(InvalidStatType, "Invalid statistic type requested: " + << typeToText(exp_type) << ", but the actual type is " + << typeToText(type_)); + } else { + return (storage.size()); + } + return (0); // to avoid compilation error +} + +template<typename SampleType, typename StorageType> +void Observation::setValueInternal(SampleType value, StorageType& storage, + Type exp_type) { + if (type_ != exp_type) { + isc_throw(InvalidStatType, "Invalid statistic type requested: " + << typeToText(exp_type) << ", but the actual type is " + << typeToText(type_)); + } + + if (storage.empty()) { + storage.push_back(make_pair(value, SampleClock::now())); + } else { + // Storing of more than one sample + storage.push_front(make_pair(value, SampleClock::now())); + + if (max_sample_count_.first) { + // if max_sample_count_ is set to true + // and size of storage is equal to max_sample_count_ + if (storage.size() > max_sample_count_.second) { + storage.pop_back(); // removing the last element + } + } else { + StatsDuration range_of_storage = + storage.front().second - storage.back().second; + // removing samples until the range_of_storage + // stops exceeding the duration limit + while (range_of_storage > max_sample_age_.second) { + storage.pop_back(); + range_of_storage = + storage.front().second - storage.back().second; + } + } + } +} + +IntegerSample Observation::getInteger() const { + return (getValueInternal<IntegerSample>(integer_samples_, STAT_INTEGER)); +} + +FloatSample Observation::getFloat() const { + return (getValueInternal<FloatSample>(float_samples_, STAT_FLOAT)); +} + +DurationSample Observation::getDuration() const { + return (getValueInternal<DurationSample>(duration_samples_, STAT_DURATION)); +} + +StringSample Observation::getString() const { + return (getValueInternal<StringSample>(string_samples_, STAT_STRING)); +} + +template<typename SampleType, typename Storage> +SampleType Observation::getValueInternal(Storage& storage, Type exp_type) const { + if (type_ != exp_type) { + isc_throw(InvalidStatType, "Invalid statistic type requested: " + << typeToText(exp_type) << ", but the actual type is " + << typeToText(type_)); + } + + if (storage.empty()) { + // That should never happen. The first element is always initialized in + // the constructor. reset() sets its value to zero, but the element should + // still be there. + isc_throw(Unexpected, "Observation storage container empty"); + } + return (*storage.begin()); +} + +std::list<IntegerSample> Observation::getIntegers() const { + return (getValuesInternal<IntegerSample>(integer_samples_, STAT_INTEGER)); +} + +std::list<FloatSample> Observation::getFloats() const { + return (getValuesInternal<FloatSample>(float_samples_, STAT_FLOAT)); +} + +std::list<DurationSample> Observation::getDurations() const { + return (getValuesInternal<DurationSample>(duration_samples_, STAT_DURATION)); +} + +std::list<StringSample> Observation::getStrings() const { + return (getValuesInternal<StringSample>(string_samples_, STAT_STRING)); +} + +template<typename SampleType, typename Storage> +std::list<SampleType> Observation::getValuesInternal(Storage& storage, + Type exp_type) const { + if (type_ != exp_type) { + isc_throw(InvalidStatType, "Invalid statistic type requested: " + << typeToText(exp_type) << ", but the actual type is " + << typeToText(type_)); + } + + if (storage.empty()) { + // That should never happen. The first element is always initialized in + // the constructor. reset() sets its value to zero, but the element should + // still be there. + isc_throw(Unexpected, "Observation storage container empty"); + } + return (storage); +} + +template<typename StorageType> +void Observation::setMaxSampleAgeInternal(StorageType& storage, + const StatsDuration& duration, + Type exp_type) { + if (type_ != exp_type) { + isc_throw(InvalidStatType, "Invalid statistic type requested: " + << typeToText(exp_type) << ", but the actual type is " + << typeToText(type_)); + } + // setting new value of max_sample_age_ + max_sample_age_.first = true; + max_sample_age_.second = duration; + // deactivating the max_sample_count_ limit + max_sample_count_.first = false; + + StatsDuration range_of_storage = + storage.front().second - storage.back().second; + + while (range_of_storage > duration) { + // deleting elements which are exceeding the duration limit + storage.pop_back(); + range_of_storage = storage.front().second - storage.back().second; + } +} + +template<typename StorageType> +void Observation::setMaxSampleCountInternal(StorageType& storage, + uint32_t max_samples, + Type exp_type) { + if (type_ != exp_type) { + isc_throw(InvalidStatType, "Invalid statistic type requested: " + << typeToText(exp_type) << ", but the actual type is " + << typeToText(type_)); + } + // Should we refuse the max_samples = 0 value here? + // setting new value of max_sample_count_ + max_sample_count_.first = true; + max_sample_count_.second = max_samples; + // deactivating the max_sample_age_ limit + max_sample_age_.first = false; + + while (storage.size() > max_samples) { + // deleting elements which are exceeding the max_samples limit + storage.pop_back(); + } +} + +void Observation::setMaxSampleAgeDefault(const StatsDuration& duration) { + // setting new value of default_max_sample_age_ + default_max_sample_age_.second = duration; +} + +void Observation::setMaxSampleCountDefault(uint32_t max_samples) { + if (max_samples == 0) { + // deactivating the default_max_sample_count_ limit + default_max_sample_count_.first = false; + default_max_sample_age_.first = true; + } else { + // setting new value of default_max_sample_count_ + default_max_sample_count_.second = max_samples; + // deactivating the default_max_sample_age_ limit + default_max_sample_age_.first = false; + default_max_sample_count_.first = true; + } +} + +const StatsDuration& Observation::getMaxSampleAgeDefault() { + return (default_max_sample_age_.second); +} + +uint32_t Observation::getMaxSampleCountDefault() { + if (default_max_sample_count_.first) { + return (default_max_sample_count_.second); + } else { + return (0); + } +} + +std::string Observation::typeToText(Type type) { + std::stringstream tmp; + switch (type) { + case STAT_INTEGER: + tmp << "integer"; + break; + case STAT_FLOAT: + tmp << "float"; + break; + case STAT_DURATION: + tmp << "duration"; + break; + case STAT_STRING: + tmp << "string"; + break; + default: + tmp << "unknown"; + break; + } + tmp << "(" << type << ")"; + return (tmp.str()); +} + +isc::data::ConstElementPtr +Observation::getJSON() const { + + ElementPtr list = isc::data::Element::createList(); // multiple observations + ElementPtr entry; + ElementPtr value; + ElementPtr timestamp; + + // Support for retrieving more than one sample + // retrieving all samples of indicated observation + switch (type_) { + case STAT_INTEGER: { + std::list<IntegerSample> s = getIntegers(); // List of all integer samples + + // Iteration over all elements in the list + // and adding alternately value and timestamp to the entry + for (std::list<IntegerSample>::iterator it = s.begin(); it != s.end(); ++it) { + entry = isc::data::Element::createList(); + value = isc::data::Element::create(static_cast<int64_t>((*it).first)); + timestamp = isc::data::Element::create(isc::util::clockToText((*it).second)); + + entry->add(value); + entry->add(timestamp); + + list->add(entry); + } + break; + } + case STAT_FLOAT: { + std::list<FloatSample> s = getFloats(); + + // Iteration over all elements in the list + // and adding alternately value and timestamp to the entry + for (std::list<FloatSample>::iterator it = s.begin(); it != s.end(); ++it) { + entry = isc::data::Element::createList(); + value = isc::data::Element::create((*it).first); + timestamp = isc::data::Element::create(isc::util::clockToText((*it).second)); + + entry->add(value); + entry->add(timestamp); + + list->add(entry); + } + break; + } + case STAT_DURATION: { + std::list<DurationSample> s = getDurations(); + + // Iteration over all elements in the list + // and adding alternately value and timestamp to the entry + for (std::list<DurationSample>::iterator it = s.begin(); it != s.end(); ++it) { + entry = isc::data::Element::createList(); + value = isc::data::Element::create(isc::util::durationToText((*it).first)); + timestamp = isc::data::Element::create(isc::util::clockToText((*it).second)); + + entry->add(value); + entry->add(timestamp); + + list->add(entry); + } + break; + } + case STAT_STRING: { + std::list<StringSample> s = getStrings(); + + // Iteration over all elements in the list + // and adding alternately value and timestamp to the entry + for (std::list<StringSample>::iterator it = s.begin(); it != s.end(); ++it) { + entry = isc::data::Element::createList(); + value = isc::data::Element::create((*it).first); + timestamp = isc::data::Element::create(isc::util::clockToText((*it).second)); + + entry->add(value); + entry->add(timestamp); + + list->add(entry); + } + break; + } + default: + isc_throw(InvalidStatType, "Unknown statistic type: " + << typeToText(type_)); + }; + + return (list); +} + +void Observation::reset() { + switch(type_) { + case STAT_INTEGER: { + integer_samples_.clear(); + setValue(static_cast<int64_t>(0)); + return; + } + case STAT_FLOAT: { + float_samples_.clear(); + setValue(0.0); + return; + } + case STAT_DURATION: { + duration_samples_.clear(); + setValue(StatsDuration::zero()); + return; + } + case STAT_STRING: { + string_samples_.clear(); + setValue(string("")); + return; + } + default: + isc_throw(InvalidStatType, "Unknown statistic type: " + << typeToText(type_)); + }; +} + +} // end of namespace stats +} // end of namespace isc diff --git a/src/lib/stats/observation.h b/src/lib/stats/observation.h new file mode 100644 index 0000000..f1e0117 --- /dev/null +++ b/src/lib/stats/observation.h @@ -0,0 +1,445 @@ +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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 OBSERVATION_H +#define OBSERVATION_H + +#include <cc/data.h> +#include <exceptions/exceptions.h> +#include <boost/shared_ptr.hpp> +#include <chrono> +#include <list> +#include <stdint.h> + +namespace isc { +namespace stats { + +/// @brief Exception thrown if invalid statistic type is used +/// +/// For example statistic is of type duration, but methods using +/// it as integer are called. +class InvalidStatType : public Exception { +public: + InvalidStatType(const char* file, size_t line, const char* what) : + isc::Exception(file, line, what) {} +}; + +/// @brief Define clock type. +/// +/// @note: we use the system clock i.e. the wall clock because this +/// clock can be converted from and to standard Unix time (time_t). +typedef std::chrono::system_clock SampleClock; + +/// @brief Defines duration type. +/// +/// @note: the precision depends on the system, +typedef std::chrono::system_clock::duration StatsDuration; + +/// @brief Returns the number of seconds in a duration. +/// +/// @param dur The duration. +/// @return The number of seconds in the given duration. +inline long toSeconds(const StatsDuration& dur) { + return ((std::chrono::duration_cast<std::chrono::seconds>(dur)).count()); +} + +/// @defgroup stat_samples Specifies supported observation types. +/// +/// @brief The list covers all supported types of observations. +/// +/// @{ + +/// @brief Integer (implemented as signed 64-bit integer) +typedef std::pair<int64_t, SampleClock::time_point> IntegerSample; + +/// @brief Float (implemented as double precision) +typedef std::pair<double, SampleClock::time_point> FloatSample; + +/// @brief Time Duration +typedef std::pair<StatsDuration, SampleClock::time_point> DurationSample; + +/// @brief String +typedef std::pair<std::string, SampleClock::time_point> StringSample; + +/// @} + +/// @brief Represents a single observable characteristic (a 'statistic') +/// +/// Currently it supports one of four types: integer (implemented as signed 64 +/// bit integer), float (implemented as double), time duration (implemented with +/// millisecond precision) and string. Absolute (setValue) and +/// incremental (addValue) modes are supported. Statistic type is determined +/// during its first use. Once type is set, any additional observations recorded +/// must be of the same type. Attempting to set or extract information about +/// other types will result in InvalidStateType exception. +/// +/// Observation can be retrieved in one of @ref getInteger, @ref getFloat, +/// @ref getDuration, @ref getString (appropriate type must be used) or +/// @ref getJSON, which is generic and can be used for all types. +/// +/// Since Kea 1.6 multiple samples are stored for the same observation. +class Observation { +public: + + /// @brief Type of available statistics + /// + /// Note that those will later be exposed using control socket. Therefore + /// an easy to understand names were chosen (integer instead of uint64). + /// To avoid confusion, we will support only one type of integer and only + /// one type of floating points. Initially, these are represented by + /// int64_t and double. If convincing use cases appear to change them + /// to something else, we may change the underlying type. + enum Type { + STAT_INTEGER, ///< this statistic is unsigned 64-bit integer value + STAT_FLOAT, ///< this statistic is a floating point value + STAT_DURATION,///< this statistic represents time duration + STAT_STRING ///< this statistic represents a string + }; + + /// @brief Constructor for integer observations + /// + /// @param name observation name + /// @param value integer value observed. + Observation(const std::string& name, const int64_t value); + + /// @brief Constructor for floating point observations + /// + /// @param name observation name + /// @param value floating point value observed. + Observation(const std::string& name, const double value); + + /// @brief Constructor for duration observations + /// + /// @param name observation name + /// @param value duration observed. + Observation(const std::string& name, const StatsDuration& value); + + /// @brief Constructor for string observations + /// + /// @param name observation name + /// @param value string observed. + Observation(const std::string& name, const std::string& value); + + /// @brief Determines maximum age of samples. + /// + /// Specifies that statistic name should be stored not as a single value, + /// but rather as a set of values. The duration determines the timespan. + /// Samples older than duration will be discarded. This is time-constrained + /// approach. For sample count constrained approach, see @ref + /// setMaxSampleCount() below. + /// + /// + /// @param duration determines maximum age of samples + /// Example: + /// To set a statistic to keep observations for the last 5 minutes, call: + /// setMaxSampleAge(std::chrono::minutes(5)); + /// To revert statistic to a single value, call: + /// setMaxSampleAge(StatsDuration::zero()); + void setMaxSampleAge(const StatsDuration& duration); + + /// @brief Determines how many samples of a given statistic should be kept. + /// + /// Specifies that statistic name should be stored not as a single value, + /// but rather as a set of values. In this form, at most max_samples will + /// be kept. When adding max_samples + 1 sample, the oldest sample will be + /// discarded. + /// + /// + /// @param max_samples how many samples of a given statistic should be kept + /// Example: + /// To set a statistic to keep the last 100 observations, call: + /// setMaxSampleCount(100); + void setMaxSampleCount(uint32_t max_samples); + + /// @brief Determines default maximum age of samples. + /// + /// @param duration default maximum age of samples to keep. + static void setMaxSampleAgeDefault(const StatsDuration& duration); + + /// @brief Determines default maximum count of samples. + /// + /// @param max_samples default maximum count of samples to keep. + /// (0 means to disable count limit and enable age limit) + static void setMaxSampleCountDefault(uint32_t max_samples); + + /// @brief Get default maximum age of samples. + /// + /// @return default maximum age of samples to keep. + static const StatsDuration& getMaxSampleAgeDefault(); + + /// @brief Get default maximum count of samples. + /// + /// @return max_samples default maximum count of samples to keep. + /// (0 means that count limit was disabled) + static uint32_t getMaxSampleCountDefault(); + + /// @ + + /// @brief Records absolute integer observation + /// + /// @param value integer value observed + /// @throw InvalidStatType if statistic is not integer + void setValue(const int64_t value); + + /// @brief Records absolute floating point observation + /// + /// @param value floating point value observed + /// @throw InvalidStatType if statistic is not fp + void setValue(const double value); + + /// @brief Records absolute duration observation + /// + /// @param value duration value observed + /// @throw InvalidStatType if statistic is not time duration + void setValue(const StatsDuration& value); + + /// @brief Records absolute string observation + /// + /// @param value string value observed + /// @throw InvalidStatType if statistic is not a string + void setValue(const std::string& value); + + /// @brief Records incremental integer observation + /// + /// @param value integer value observed + /// @throw InvalidStatType if statistic is not integer + void addValue(const int64_t value); + + /// @brief Records incremental floating point observation + /// + /// @param value floating point value observed + /// @throw InvalidStatType if statistic is not fp + void addValue(const double value); + + /// @brief Records incremental duration observation + /// + /// @param value duration value observed + /// @throw InvalidStatType if statistic is not time duration + void addValue(const StatsDuration& value); + + /// @brief Records incremental string observation. + /// + /// @param value string value observed + /// @throw InvalidStatType if statistic is not a string + void addValue(const std::string& value); + + /// @brief Returns size of observed storage + /// + /// @return size of storage + size_t getSize() const; + + /// @brief Returns both values of max_sample_age_ of statistic. + /// + /// @return max_sample_age_. + std::pair<bool, StatsDuration> getMaxSampleAge() const; + + /// @brief Returns both values of max_sample_count_ of statistic. + /// + /// @return max_sample_count_. + std::pair<bool, uint32_t> getMaxSampleCount() const; + + /// @brief Resets statistic. + /// + /// Sets statistic to a neutral (0, 0.0 or "") value and + /// clears the underlying storage. + void reset(); + + /// @brief Returns statistic type + /// @return statistic type + Type getType() const { + return (type_); + } + + /// @brief Returns observed integer sample + /// @return observed sample (value + timestamp) + /// @throw InvalidStatType if statistic is not integer + IntegerSample getInteger() const; + + /// @brief Returns observed float sample + /// @return observed sample (value + timestamp) + /// @throw InvalidStatType if statistic is not fp + FloatSample getFloat() const; + + /// @brief Returns observed duration sample + /// @return observed sample (value + timestamp) + /// @throw InvalidStatType if statistic is not time duration + DurationSample getDuration() const; + + /// @brief Returns observed string sample + /// @return observed sample (value + timestamp) + /// @throw InvalidStatType if statistic is not a string + StringSample getString() const; + + /// @brief Returns observed integer samples + /// @return list of observed samples (value + timestamp) + /// @throw InvalidStatType if statistic is not integer + std::list<IntegerSample> getIntegers() const; + + /// @brief Returns observed float samples + /// @return list of observed samples (value + timestamp) + /// @throw InvalidStatType if statistic is not fp + std::list<FloatSample> getFloats() const; + + /// @brief Returns observed duration samples + /// @return list of observed samples (value + timestamp) + /// @throw InvalidStatType if statistic is not time duration + std::list<DurationSample> getDurations() const; + + /// @brief Returns observed string samples + /// @return list of observed samples (value + timestamp) + /// @throw InvalidStatType if statistic is not a string + std::list<StringSample> getStrings() const; + + /// @brief Returns as a JSON structure + /// @return JSON structures representing all observations + isc::data::ConstElementPtr getJSON() const; + + /// @brief Converts statistic type to string + /// @return textual name of statistic type + static std::string typeToText(Type type); + + /// @brief Returns observation name + std::string getName() const { + return (name_); + } + +private: + + /// @brief Returns size of observed storage + /// + /// This method returns size of observed storage. + /// It is used by public methods to return size of + /// available storages. + /// @tparam Storage type of storage (e.g. list<IntegerSample>) + /// @param storage storage which size will be returned + /// @param exp_type expected observation type (used for sanity checking) + /// @return size of storage + template<typename StorageType> + size_t getSizeInternal(StorageType& storage, Type exp_type) const; + + /// @brief Records absolute sample (internal version) + /// + /// This method records an absolute value of an observation. + /// It is used by public methods to add sample to one of + /// available storages. + /// + /// @tparam SampleType type of sample (e.g. IntegerSample) + /// @tparam StorageType type of storage (e.g. list<IntegerSample>) + /// @param value observation to be recorded + /// @param storage observation will be stored here + /// @param exp_type expected observation type (used for sanity checking) + /// @throw InvalidStatType if observation type mismatches + template<typename SampleType, typename StorageType> + void setValueInternal(SampleType value, StorageType& storage, + Type exp_type); + + /// @brief Returns a sample (internal version) + /// + /// @tparam SampleType type of sample (e.g. IntegerSample) + /// @tparam StorageType type of storage (e.g. list<IntegerSample>) + /// @param observation storage + /// @param exp_type expected observation type (used for sanity checking) + /// @throw InvalidStatType if observation type mismatches + /// @return Observed sample + template<typename SampleType, typename Storage> + SampleType getValueInternal(Storage& storage, Type exp_type) const; + + /// @brief Returns samples (internal version) + /// + /// @tparam SampleType type of samples (e.g. IntegerSample) + /// @tparam Storage type of storage (e.g. list<IntegerSample>) + /// @param observation storage + /// @param exp_type expected observation type (used for sanity checking) + /// @throw InvalidStatType if observation type mismatches + /// @return list of observed samples + template<typename SampleType, typename Storage> + std::list<SampleType> getValuesInternal(Storage& storage, + Type exp_type) const; + + /// @brief Determines maximum age of samples. + /// + /// @tparam Storage type of storage (e.g. list<IntegerSample>) + /// @param storage storage on which limit will be set + /// @param duration determines maximum age of samples + /// @param exp_type expected observation type (used for sanity checking) + template<typename StorageType> + void setMaxSampleAgeInternal(StorageType& storage, + const StatsDuration& duration, Type exp_type); + + /// @brief Determines how many samples of a given statistic should be kept. + /// + /// @tparam Storage type of storage (e.g. list<IntegerSample>) + /// @param storage storage on which limit will be set + /// @param max_samples determines maximum number of samples + /// @param exp_type expected observation type (used for sanity checking) + template<typename StorageType> + void setMaxSampleCountInternal(StorageType& storage, + uint32_t max_samples, Type exp_type); + + /// @brief Observation (statistic) name + std::string name_; + + /// @brief Observation (statistic) type) + Type type_; + + /// @brief Maximum number of samples + /// The limit is represented as a pair + /// of bool value and uint32_t + /// Only one kind of limit can be active + /// The bool value informs which limit + /// is available + /// True means active limit, false means inactive limit + std::pair<bool, uint32_t> max_sample_count_; + + /// @brief Default maximum number of samples + /// + /// By default the MaxSampleCount is set to 20 + /// and MaxSampleAge is disabled + static std::pair<bool, uint32_t> default_max_sample_count_; + + /// @brief Maximum timespan of samples + /// The limit is represented as a pair + /// of bool value and StatsDuration + /// Only one kind of limit can be active + /// The bool value informs which limit + /// is available + /// True means active limit, false means inactive limit + std::pair<bool, StatsDuration> max_sample_age_; + + /// @brief Default maximum timespan of samples + /// + /// By default the MaxSampleCount is set to 20 + /// and MaxSampleAge is disabled + static std::pair<bool, StatsDuration> default_max_sample_age_; + + /// @defgroup samples_storage Storage for supported observations + /// + /// @brief The following containers serve as a storage for all supported + /// observation types. + /// + /// @{ + + /// @brief Storage for integer samples + std::list<IntegerSample> integer_samples_; + + /// @brief Storage for floating point samples + std::list<FloatSample> float_samples_; + + /// @brief Storage for time duration samples + std::list<DurationSample> duration_samples_; + + /// @brief Storage for string samples + std::list<StringSample> string_samples_; + /// @} +}; + +/// @brief Observation pointer +typedef boost::shared_ptr<Observation> ObservationPtr; + +} +} + +#endif // OBSERVATION_H diff --git a/src/lib/stats/stats.dox b/src/lib/stats/stats.dox new file mode 100644 index 0000000..7d4d3b5 --- /dev/null +++ b/src/lib/stats/stats.dox @@ -0,0 +1,16 @@ +// Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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/. + +/** + @page libstats libkea-stats - Kea Statistics Library + +@section statsMTConsiderations Multi-Threading Consideration for Statistics + +The statistic manager (@c isc::stats::StatsMgr singleton) is Kea thread safe +i.e. it is thread safe when the multi-threading mode is true (when the +multi-threading mode is false Kea main thread processes packets). + +*/ diff --git a/src/lib/stats/stats_mgr.cc b/src/lib/stats/stats_mgr.cc new file mode 100644 index 0000000..58b36ab --- /dev/null +++ b/src/lib/stats/stats_mgr.cc @@ -0,0 +1,645 @@ +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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 <config.h> + +#include <exceptions/exceptions.h> +#include <stats/stats_mgr.h> +#include <cc/data.h> +#include <cc/command_interpreter.h> +#include <util/multi_threading_mgr.h> +#include <boost/make_shared.hpp> +#include <chrono> + +using namespace std; +using namespace std::chrono; +using namespace isc::data; +using namespace isc::config; +using namespace isc::util; + +namespace isc { +namespace stats { + +StatsMgr& +StatsMgr::instance() { + static StatsMgr stats_mgr; + return (stats_mgr); +} + +StatsMgr::StatsMgr() : + global_(boost::make_shared<StatContext>()), mutex_(new mutex) { +} + +void +StatsMgr::setValue(const string& name, const int64_t value) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + setValueInternal(name, value); + } else { + setValueInternal(name, value); + } +} + +void +StatsMgr::setValue(const string& name, const double value) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + setValueInternal(name, value); + } else { + setValueInternal(name, value); + } +} + +void +StatsMgr::setValue(const string& name, const StatsDuration& value) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + setValueInternal(name, value); + } else { + setValueInternal(name, value); + } +} + +void +StatsMgr::setValue(const string& name, const string& value) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + setValueInternal(name, value); + } else { + setValueInternal(name, value); + } +} + +void +StatsMgr::addValue(const string& name, const int64_t value) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + addValueInternal(name, value); + } else { + addValueInternal(name, value); + } +} + +void +StatsMgr::addValue(const string& name, const double value) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + addValueInternal(name, value); + } else { + addValueInternal(name, value); + } +} + +void +StatsMgr::addValue(const string& name, const StatsDuration& value) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + addValueInternal(name, value); + } else { + addValueInternal(name, value); + } +} + +void +StatsMgr::addValue(const string& name, const string& value) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + addValueInternal(name, value); + } else { + addValueInternal(name, value); + } +} + +ObservationPtr +StatsMgr::getObservation(const string& name) const { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (getObservationInternal(name)); + } else { + return (getObservationInternal(name)); + } +} + +ObservationPtr +StatsMgr::getObservationInternal(const string& name) const { + /// @todo: Implement contexts. + // Currently we keep everything in a global context. + return (global_->get(name)); +} + +void +StatsMgr::addObservation(const ObservationPtr& stat) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + addObservationInternal(stat); + } else { + addObservationInternal(stat); + } +} + +void +StatsMgr::addObservationInternal(const ObservationPtr& stat) { + /// @todo: Implement contexts. + // Currently we keep everything in a global context. + global_->add(stat); +} + +bool +StatsMgr::deleteObservation(const string& name) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (deleteObservationInternal(name)); + } else { + return (deleteObservationInternal(name)); + } +} + +bool +StatsMgr::deleteObservationInternal(const string& name) { + /// @todo: Implement contexts. + // Currently we keep everything in a global context. + return (global_->del(name)); +} + +bool +StatsMgr::setMaxSampleAge(const string& name, const StatsDuration& duration) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (setMaxSampleAgeInternal(name, duration)); + } else { + return (setMaxSampleAgeInternal(name, duration)); + } +} + +bool +StatsMgr::setMaxSampleAgeInternal(const string& name, + const StatsDuration& duration) { + ObservationPtr obs = getObservationInternal(name); + if (obs) { + obs->setMaxSampleAge(duration); + return (true); + } + return (false); +} + +bool +StatsMgr::setMaxSampleCount(const string& name, uint32_t max_samples) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (setMaxSampleCountInternal(name, max_samples)); + } else { + return (setMaxSampleCountInternal(name, max_samples)); + } +} + +bool +StatsMgr::setMaxSampleCountInternal(const string& name, + uint32_t max_samples) { + ObservationPtr obs = getObservationInternal(name); + if (obs) { + obs->setMaxSampleCount(max_samples); + return (true); + } + return (false); +} + +void +StatsMgr::setMaxSampleAgeAll(const StatsDuration& duration) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + setMaxSampleAgeAllInternal(duration); + } else { + setMaxSampleAgeAllInternal(duration); + } +} + +void +StatsMgr::setMaxSampleAgeAllInternal(const StatsDuration& duration) { + global_->setMaxSampleAgeAll(duration); +} + +void +StatsMgr::setMaxSampleCountAll(uint32_t max_samples) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + setMaxSampleCountAllInternal(max_samples); + } else { + setMaxSampleCountAllInternal(max_samples); + } +} + +void +StatsMgr::setMaxSampleCountAllInternal(uint32_t max_samples) { + global_->setMaxSampleCountAll(max_samples); +} + +void +StatsMgr::setMaxSampleAgeDefault(const StatsDuration& duration) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + setMaxSampleAgeDefaultInternal(duration); + } else { + setMaxSampleAgeDefaultInternal(duration); + } +} + +void +StatsMgr::setMaxSampleAgeDefaultInternal(const StatsDuration& duration) { + Observation::setMaxSampleAgeDefault(duration); +} + +void +StatsMgr::setMaxSampleCountDefault(uint32_t max_samples) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + setMaxSampleCountDefaultInternal(max_samples); + } else { + setMaxSampleCountDefaultInternal(max_samples); + } +} + +void +StatsMgr::setMaxSampleCountDefaultInternal(uint32_t max_samples) { + Observation::setMaxSampleCountDefault(max_samples); +} + +const StatsDuration& +StatsMgr::getMaxSampleAgeDefault() const { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (getMaxSampleAgeDefaultInternal()); + } else { + return (getMaxSampleAgeDefaultInternal()); + } +} + +const StatsDuration& +StatsMgr::getMaxSampleAgeDefaultInternal() const { + return (Observation::getMaxSampleAgeDefault()); +} + +uint32_t +StatsMgr::getMaxSampleCountDefault() const { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (getMaxSampleCountDefaultInternal()); + } else { + return (getMaxSampleCountDefaultInternal()); + } +} + +uint32_t +StatsMgr::getMaxSampleCountDefaultInternal() const { + return (Observation::getMaxSampleCountDefault()); +} + +bool +StatsMgr::reset(const string& name) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (resetInternal(name)); + } else { + return (resetInternal(name)); + } +} + +bool +StatsMgr::resetInternal(const string& name) { + ObservationPtr obs = getObservationInternal(name); + if (obs) { + obs->reset(); + return (true); + } + return (false); +} + +bool +StatsMgr::del(const string& name) { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (delInternal(name)); + } else { + return (delInternal(name)); + } +} + +bool +StatsMgr::delInternal(const string& name) { + return (global_->del(name)); +} + +void +StatsMgr::removeAll() { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + removeAllInternal(); + } else { + removeAllInternal(); + } +} + +void +StatsMgr::removeAllInternal() { + global_->clear(); +} + +ConstElementPtr +StatsMgr::get(const string& name) const { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (getInternal(name)); + } else { + return (getInternal(name)); + } +} + +ConstElementPtr +StatsMgr::getInternal(const string& name) const { + ElementPtr map = Element::createMap(); // a map + ObservationPtr obs = getObservationInternal(name); + if (obs) { + map->set(name, obs->getJSON()); // that contains observations + } + return (map); +} + +ConstElementPtr +StatsMgr::getAll() const { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (getAllInternal()); + } else { + return (getAllInternal()); + } +} + +ConstElementPtr +StatsMgr::getAllInternal() const { + return (global_->getAll()); +} + +void +StatsMgr::resetAll() { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + resetAllInternal(); + } else { + resetAllInternal(); + } +} + +void +StatsMgr::resetAllInternal() { + global_->resetAll(); +} + +size_t +StatsMgr::getSize(const string& name) const { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (getSizeInternal(name)); + } else { + return (getSizeInternal(name)); + } +} + +size_t +StatsMgr::getSizeInternal(const string& name) const { + ObservationPtr obs = getObservationInternal(name); + if (obs) { + return (obs->getSize()); + } + return (0); +} + +size_t +StatsMgr::count() const { + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + return (countInternal()); + } else { + return (countInternal()); + } +} + +size_t +StatsMgr::countInternal() const { + return (global_->size()); +} + +ConstElementPtr +StatsMgr::statisticSetMaxSampleAgeHandler(const string& /*name*/, + const ConstElementPtr& params) { + string name, error; + StatsDuration duration; + if (!StatsMgr::getStatName(params, name, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (!StatsMgr::getStatDuration(params, duration, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (StatsMgr::instance().setMaxSampleAge(name, duration)) { + return (createAnswer(CONTROL_RESULT_SUCCESS, + "Statistic '" + name + "' duration limit is set.")); + } else { + return (createAnswer(CONTROL_RESULT_ERROR, + "No '" + name + "' statistic found")); + } +} + +ConstElementPtr +StatsMgr::statisticSetMaxSampleCountHandler(const string& /*name*/, + const ConstElementPtr& params) { + string name, error; + uint32_t max_samples; + if (!StatsMgr::getStatName(params, name, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (!StatsMgr::getStatMaxSamples(params, max_samples, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (StatsMgr::instance().setMaxSampleCount(name, max_samples)) { + return (createAnswer(CONTROL_RESULT_SUCCESS, + "Statistic '" + name + "' count limit is set.")); + } else { + return (createAnswer(CONTROL_RESULT_ERROR, + "No '" + name + "' statistic found")); + } +} + +ConstElementPtr +StatsMgr::statisticGetHandler(const string& /*name*/, + const ConstElementPtr& params) { + string name, error; + if (!StatsMgr::getStatName(params, name, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + return (createAnswer(CONTROL_RESULT_SUCCESS, + StatsMgr::instance().get(name))); +} + +ConstElementPtr +StatsMgr::statisticResetHandler(const string& /*name*/, + const ConstElementPtr& params) { + string name, error; + if (!StatsMgr::getStatName(params, name, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (StatsMgr::instance().reset(name)) { + return (createAnswer(CONTROL_RESULT_SUCCESS, + "Statistic '" + name + "' reset.")); + } else { + return (createAnswer(CONTROL_RESULT_ERROR, + "No '" + name + "' statistic found")); + } +} + +ConstElementPtr +StatsMgr::statisticRemoveHandler(const string& /*name*/, + const ConstElementPtr& params) { + string name, error; + if (!StatsMgr::getStatName(params, name, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (StatsMgr::instance().del(name)) { + return (createAnswer(CONTROL_RESULT_SUCCESS, + "Statistic '" + name + "' removed.")); + } else { + return (createAnswer(CONTROL_RESULT_ERROR, + "No '" + name + "' statistic found")); + } + +} + +ConstElementPtr +StatsMgr::statisticRemoveAllHandler(const string& /*name*/, + const ConstElementPtr& /*params*/) { + StatsMgr::instance().removeAll(); + return (createAnswer(CONTROL_RESULT_SUCCESS, + "Warning: statistic-remove-all command is deprecated." + " All statistics removed.")); +} + +ConstElementPtr +StatsMgr::statisticGetAllHandler(const string& /*name*/, + const ConstElementPtr& /*params*/) { + ConstElementPtr all_stats = StatsMgr::instance().getAll(); + return (createAnswer(CONTROL_RESULT_SUCCESS, all_stats)); +} + +ConstElementPtr +StatsMgr::statisticResetAllHandler(const string& /*name*/, + const ConstElementPtr& /*params*/) { + StatsMgr::instance().resetAll(); + return (createAnswer(CONTROL_RESULT_SUCCESS, + "All statistics reset to neutral values.")); +} + +ConstElementPtr +StatsMgr::statisticSetMaxSampleAgeAllHandler(const ConstElementPtr& params) { + string error; + StatsDuration duration; + if (!StatsMgr::getStatDuration(params, duration, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + StatsMgr::instance().setMaxSampleCountDefaultInternal(0); + StatsMgr::instance().setMaxSampleAgeDefaultInternal(duration); + StatsMgr::instance().setMaxSampleAgeAllInternal(duration); + } else { + StatsMgr::instance().setMaxSampleCountDefaultInternal(0); + StatsMgr::instance().setMaxSampleAgeDefaultInternal(duration); + StatsMgr::instance().setMaxSampleAgeAllInternal(duration); + } + return (createAnswer(CONTROL_RESULT_SUCCESS, + "All statistics duration limit are set.")); +} + +ConstElementPtr +StatsMgr::statisticSetMaxSampleCountAllHandler(const ConstElementPtr& params) { + string error; + uint32_t max_samples; + if (!StatsMgr::getStatMaxSamples(params, max_samples, error)) { + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (max_samples == 0) { + error = "'max-samples' parameter must not be zero"; + return (createAnswer(CONTROL_RESULT_ERROR, error)); + } + if (MultiThreadingMgr::instance().getMode()) { + lock_guard<mutex> lock(*mutex_); + StatsMgr::instance().setMaxSampleCountDefaultInternal(max_samples); + StatsMgr::instance().setMaxSampleCountAllInternal(max_samples); + } else { + StatsMgr::instance().setMaxSampleCountDefaultInternal(max_samples); + StatsMgr::instance().setMaxSampleCountAllInternal(max_samples); + } + return (createAnswer(CONTROL_RESULT_SUCCESS, + "All statistics count limit are set.")); +} + +bool +StatsMgr::getStatName(const ConstElementPtr& params, + string& name, + string& reason) { + if (!params) { + reason = "Missing mandatory 'name' parameter."; + return (false); + } + ConstElementPtr stat_name = params->get("name"); + if (!stat_name) { + reason = "Missing mandatory 'name' parameter."; + return (false); + } + if (stat_name->getType() != Element::string) { + reason = "'name' parameter expected to be a string."; + return (false); + } + name = stat_name->stringValue(); + return (true); +} + +bool +StatsMgr::getStatDuration(const ConstElementPtr& params, + StatsDuration& duration, + string& reason) { + if (!params) { + reason = "Missing mandatory 'duration' parameter."; + return (false); + } + ConstElementPtr stat_duration = params->get("duration"); + if (!stat_duration) { + reason = "Missing mandatory 'duration' parameter."; + return (false); + } + duration = std::chrono::seconds(stat_duration->intValue()); + return (true); +} + +bool +StatsMgr::getStatMaxSamples(const ConstElementPtr& params, + uint32_t& max_samples, + string& reason) { + if (!params) { + reason = "Missing mandatory 'max-samples' parameter."; + return (false); + } + ConstElementPtr stat_max_samples = params->get("max-samples"); + if (!stat_max_samples) { + reason = "Missing mandatory 'max-samples' parameter."; + return (false); + } + if (stat_max_samples->getType() != Element::integer) { + reason = "'max-samples' parameter expected to be an integer."; + return (false); + } + max_samples = stat_max_samples->intValue(); + return (true); +} + +} // end of namespace stats +} // end of namespace isc diff --git a/src/lib/stats/stats_mgr.h b/src/lib/stats/stats_mgr.h new file mode 100644 index 0000000..564df43 --- /dev/null +++ b/src/lib/stats/stats_mgr.h @@ -0,0 +1,789 @@ +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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 STATSMGR_H +#define STATSMGR_H + +#include <stats/observation.h> +#include <stats/context.h> +#include <boost/noncopyable.hpp> +#include <boost/scoped_ptr.hpp> + +#include <map> +#include <mutex> +#include <string> +#include <vector> +#include <sstream> + +namespace isc { +namespace stats { + +/// @brief Statistics Manager class +/// +/// StatsMgr is a singleton class that represents a subsystem that manages +/// collection, storage and reporting of various types of statistics. +/// It is also the intended API for both core code and hooks. +/// +/// As of May 2015, Tomek ran performance benchmarks (see unit-tests in +/// stats_mgr_unittest.cc with performance in their names) and it seems +/// the code is able to register ~2.5-3 million observations per second, even +/// with 1000 different statistics recorded. That seems sufficient for now, +/// so there is no immediate need to develop any multi-threading solutions +/// for now. However, should this decision be revised in the future, the +/// best place for it would to be modify @ref addObservation method here. +/// It's the common code point that all new observations must pass through. +/// One possible way to enable multi-threading would be to run a separate +/// thread handling collection. The main thread would call @ref addValue and +/// @ref setValue methods that would end up calling @ref addObservation. +/// That method would pass the data to separate thread to be collected and +/// would immediately return. Further processing would be mostly as it +/// is today, except happening in a separate thread. One unsolved issue in +/// this approach is how to extract data, but that will remain unsolvable +/// until we get the control socket implementation. +/// +/// Statistics Manager does not use logging by design. The reasons are: +/// - performance impact (logging every observation would degrade performance +/// significantly. While it's possible to log on sufficiently high debug +/// level, such a log would be not that useful) +/// - dependency (statistics are intended to be a lightweight library, adding +/// dependency on libkea-log, which has its own dependencies, including +/// external log4cplus, is against 'lightweight' design) +/// - if logging of specific statistics is warranted, it is recommended to +/// add log entries in the code that calls StatsMgr. +/// - enabling logging in StatsMgr does not offer fine tuning. It would be +/// either all or nothing. Adding logging entries only when necessary +/// in the code that uses StatsMgr gives better granularity. +/// +/// If this decision is revisited in the future, the most universal places +/// for adding logging have been marked in @ref addValueInternal and +/// @ref setValueInternal. +class StatsMgr : public boost::noncopyable { +public: + + /// @brief Statistics Manager accessor method. + static StatsMgr& instance(); + + /// @defgroup producer_methods Methods are used by data producers. + /// + /// @brief The following methods are used by data producers: + /// + /// @{ + + /// @brief Records absolute integer observation. + /// + /// @param name name of the observation + /// @param value integer value observed + /// @throw InvalidStatType if statistic is not integer + void setValue(const std::string& name, const int64_t value); + + /// @brief Records absolute floating point observation. + /// + /// @param name name of the observation + /// @param value floating point value observed + /// @throw InvalidStatType if statistic is not fp + void setValue(const std::string& name, const double value); + + /// @brief Records absolute duration observation. + /// + /// @param name name of the observation + /// @param value duration value observed + /// @throw InvalidStatType if statistic is not time duration + void setValue(const std::string& name, const StatsDuration& value); + + /// @brief Records absolute string observation. + /// + /// @param name name of the observation + /// @param value string value observed + /// @throw InvalidStatType if statistic is not a string + void setValue(const std::string& name, const std::string& value); + + /// @brief Records incremental integer observation. + /// + /// @param name name of the observation + /// @param value integer value observed + /// @throw InvalidStatType if statistic is not integer + void addValue(const std::string& name, const int64_t value); + + /// @brief Records incremental floating point observation. + /// + /// @param name name of the observation + /// @param value floating point value observed + /// @throw InvalidStatType if statistic is not fp + void addValue(const std::string& name, const double value); + + /// @brief Records incremental duration observation. + /// + /// @param name name of the observation + /// @param value duration value observed + /// @throw InvalidStatType if statistic is not time duration + void addValue(const std::string& name, const StatsDuration& value); + + /// @brief Records incremental string observation. + /// + /// @param name name of the observation + /// @param value string value observed + /// @throw InvalidStatType if statistic is not a string + void addValue(const std::string& name, const std::string& value); + + /// @brief Determines maximum age of samples. + /// + /// Specifies that statistic name should be stored not as a single value, + /// but rather as a set of values. duration determines the timespan. + /// Samples older than duration will be discarded. This is time-constrained + /// approach. For sample count constrained approach, see @ref + /// setMaxSampleCount() below. + /// Example: + /// To set a statistic to keep observations for the last 5 minutes, call: + /// setMaxSampleAge("incoming-packets", StatsDuration::minutes(5)); + /// to revert statistic to a single value, call: + /// setMaxSampleAge("incoming-packets", StatsDuration:zero()); + /// + /// @param name name of the observation + /// @param duration determines maximum age of samples + /// @return true if successful, false if there's no such statistic + bool setMaxSampleAge(const std::string& name, const StatsDuration& duration); + + /// @brief Determines how many samples of a given statistic should be kept. + /// + /// Specifies that statistic name should be stored not as single value, but + /// rather as a set of values. In this form, at most max_samples will be kept. + /// When adding max_samples + 1 sample, the oldest sample will be discarded. + /// Example: + /// To set a statistic to keep the last 100 observations, call: + /// setMaxSampleCount("incoming-packets", 100); + /// + /// @param name name of the observation + /// @param max_samples how many samples of a given statistic should be kept + /// @return true if successful, false if there's no such statistic + bool setMaxSampleCount(const std::string& name, uint32_t max_samples); + + /// @brief Set duration limit for all collected statistics. + /// + /// @param duration determines maximum age of samples + void setMaxSampleAgeAll(const StatsDuration& duration); + + /// @brief Set count limit for all collected statistics. + /// + /// @param max_samples how many samples of a given statistic should be kept + void setMaxSampleCountAll(uint32_t max_samples); + + /// @brief Set default duration limit. + /// + /// @param duration default maximum age of samples to keep + void setMaxSampleAgeDefault(const StatsDuration& duration); + + /// @brief Set default count limit. + /// + /// @param max_samples default maximum number of samples to keep + /// (0 means to disable count limit and enable age limit) + void setMaxSampleCountDefault(uint32_t max_samples); + + /// @brief Get default duration limit. + /// + /// @return default maximum age of samples to keep. + const StatsDuration& getMaxSampleAgeDefault() const; + + /// @brief Get default count limit. + /// + /// @return default maximum number of samples to keep. + /// (0 means that count limit was disabled) + uint32_t getMaxSampleCountDefault() const; + + /// @} + + /// @defgroup consumer_methods Methods are used by data consumers. + /// + /// @brief The following methods are used by data consumers: + /// + /// @{ + + /// @brief Resets specified statistic. + /// + /// This is a convenience function and is equivalent to setValue(name, + /// neutral_value), where neutral_value is 0, 0.0 or "". + /// + /// @param name name of the statistic to be reset. + /// @return true if successful, false if there's no such statistic + bool reset(const std::string& name); + + /// @brief Removes specified statistic. + /// + /// @param name name of the statistic to be removed. + /// @return true if successful, false if there's no such statistic + bool del(const std::string& name); + + /// @brief Resets all collected statistics back to zero. + void resetAll(); + + /// @brief Removes all collected statistics. + /// @note This command was deprecated. + void removeAll(); + + /// @brief Returns size of specified statistic. + /// + /// @param name name of the statistic which size should be return. + /// @return size of specified statistic, 0 means lack of given statistic. + size_t getSize(const std::string& name) const; + + /// @brief Returns number of available statistics. + /// + /// @return number of recorded statistics. + size_t count() const; + + /// @brief Returns a single statistic as a JSON structure. + /// + /// @return JSON structures representing a single statistic + isc::data::ConstElementPtr get(const std::string& name) const; + + /// @brief Returns all statistics as a JSON structure. + /// + /// @return JSON structures representing all statistics + isc::data::ConstElementPtr getAll() const; + + /// @} + + /// @brief Returns an observation. + /// + /// Used in testing only. Production code should use @ref get() method + /// when the value is dereferenced. + /// Calls @ref getObservationInternal() method in a thread safe context. + /// + /// @param name name of the statistic + /// @return Pointer to the Observation object + ObservationPtr getObservation(const std::string& name) const; + + /// @brief Returns an observation in a thread safe context. + /// + /// Used in testing only. Production code should use @ref get() method + /// when the value is dereferenced. Should be called in a thread safe context. + /// + /// @param name name of the statistic + /// @return Pointer to the Observation object + ObservationPtr getObservationInternal(const std::string& name) const; + + /// @brief Generates statistic name in a given context + /// + /// Example: + /// @code + /// generateName("subnet", 123, "received-packets"); + /// @endcode + /// will return subnet[123].received-packets. Any printable type + /// can be used as index. + /// + /// @tparam Type any type that can be used to index contexts + /// @param context name of the context (e.g. 'subnet') + /// @param index value used for indexing contexts (e.g. subnet_id) + /// @param stat_name name of the statistic + /// @return returns full statistic name in form context[index].stat_name + template<typename Type> + static std::string generateName(const std::string& context, Type index, + const std::string& stat_name) { + std::stringstream name; + name << context << "[" << index << "]." << stat_name; + return (name.str()); + } + + /// @defgroup command_methods Methods are used to handle commands. + /// + /// @brief The following methods are used to handle commands: + /// + /// @{ + + /// @brief Handles statistic-get command + /// + /// This method handles statistic-get command, which returns value + /// of a given statistic). It expects one parameter stored in params map: + /// name: name of the statistic + /// + /// Example params structure: + /// { + /// "name": "packets-received" + /// } + /// + /// @param name name of the command (ignored, should be "statistic-get") + /// @param params structure containing a map that contains "name" + /// @return answer containing details of specified statistic + static isc::data::ConstElementPtr + statisticGetHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-reset command + /// + /// This method handles statistic-reset command, which resets value + /// of a given statistic. It expects one parameter stored in params map: + /// name: name of the statistic + /// + /// Example params structure: + /// { + /// "name": "packets-received" + /// } + /// + /// @param name name of the command (ignored, should be "statistic-reset") + /// @param params structure containing a map that contains "name" + /// @return answer containing confirmation + static isc::data::ConstElementPtr + statisticResetHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-remove command + /// + /// This method handles statistic-reset command, which removes a given + /// statistic completely. It expects one parameter stored in params map: + /// name: name of the statistic + /// + /// Example params structure: + /// { + /// "name": "packets-received" + /// } + /// + /// @param name name of the command (ignored, should be "statistic-remove") + /// @param params structure containing a map that contains "name" element + /// @return answer containing confirmation + static isc::data::ConstElementPtr + statisticRemoveHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-sample-age-set command + /// + /// This method handles statistic-sample-age-set command, + /// which sets max_sample_age_ limit of a given statistic + /// and leaves max_sample_count_ disabled. + /// It expects two parameters stored in params map: + /// name: name of the statistic + /// duration: time limit expressed as a number of seconds + /// + /// Example params structure: + /// { + /// "name": "packets-received", + /// "duration": 1245 + /// } + /// + /// @param name name of the command (ignored, should be "statistic-sample-age-set") + /// @param params structure containing a map that contains "name" and "duration" + /// @return answer containing information about successfully setup limit of statistic + static isc::data::ConstElementPtr + statisticSetMaxSampleAgeHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-sample-count-set command + /// + /// This method handles statistic-sample-count-set command, + /// which sets max_sample_count_ limit of a given statistic + /// and leaves max_sample_age_ disabled. + /// It expects two parameters stored in params map: + /// name: name of the statistic + /// max-samples: count limit + /// + /// Example params structure: + /// { + /// "name": "packets-received", + /// "max-samples": 15 + /// } + /// + /// @param name name of the command (ignored, should be "statistic-sample-count-set") + /// @param params structure containing a map that contains "name" and "max-samples" + /// @return answer containing information about successfully setup limit of statistic + static isc::data::ConstElementPtr + statisticSetMaxSampleCountHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-get-all command + /// + /// This method handles statistic-get-all command, which returns values + /// of all statistics. Params parameter is ignored. + /// + /// @param name name of the command (ignored, should be "statistic-get-all") + /// @param params ignored + /// @return answer containing values of all statistic + static isc::data::ConstElementPtr + statisticGetAllHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-reset-all command + /// + /// This method handles statistic-reset-all command, which sets values of + /// all statistics back to zero. Params parameter is ignored. + /// + /// @param name name of the command (ignored, should be "statistic-reset-all") + /// @param params ignored + /// @return answer confirming success of this operation + static isc::data::ConstElementPtr + statisticResetAllHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-remove-all command + /// + /// @note The statistic-remove-all command was deprecated. + /// + /// This method handles statistic-remove-all command, which removes all + /// statistics. Params parameter is ignored. + /// + /// @param name name of the command (ignored, should be "statistic-remove-all") + /// @param params ignored + /// @return answer confirming success of this operation + static isc::data::ConstElementPtr + statisticRemoveAllHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-sample-age-set-all command + /// + /// This method handles statistic-sample-age-set-all command, + /// which sets max_sample_age_ limit to all statistics and the default. + /// It expects one parameter stored in params map: + /// duration: limit expressed as a number of seconds + /// + /// Example params structure: + /// { + /// "duration": 1245 + /// } + /// + /// @param params structure containing a map that contains "duration" + /// @return answer confirming success of this operation + isc::data::ConstElementPtr + statisticSetMaxSampleAgeAllHandler(const isc::data::ConstElementPtr& params); + + /// @brief Handles statistic-sample-count-set-all command + /// + /// This method handles statistic-sample-count-set-all command, + /// which sets max_sample_count_ limit of all statistics and the default. + /// It expects one parameter stored in params map: + /// max-samples: count limit + /// The value 0 is out of range. + /// + /// Example params structure: + /// { + /// "max-samples": 15 + /// } + /// + /// @param params structure containing a map that contains "max-samples" + /// @return answer confirming success of this operation + isc::data::ConstElementPtr + statisticSetMaxSampleCountAllHandler(const isc::data::ConstElementPtr& params); + + /// @} + +private: + + /// @private + + /// @brief Private constructor. + /// + /// StatsMgr is a singleton. It should be accessed using @ref instance + /// method. + StatsMgr(); + + /// @public + + /// @brief Sets a given statistic to specified value (internal version). + /// + /// This template method sets statistic identified by name to a value + /// specified by value. This internal method is used by public @ref setValue + /// methods. + /// + /// @tparam DataType one of int64_t, double, StatsDuration or string + /// @param name name of the statistic + /// @param value specified statistic will be set to this value + /// @throw InvalidStatType is statistic exists and has a different type. + template<typename DataType> + void setValueInternal(const std::string& name, DataType value) { + // If we want to log each observation, here would be the best place for it. + ObservationPtr stat = getObservationInternal(name); + if (stat) { + stat->setValue(value); + } else { + stat.reset(new Observation(name, value)); + addObservationInternal(stat); + } + } + + /// @public + + /// @brief Adds specified value to a given statistic (internal version). + /// + /// This template method adds specified value to a given statistic (identified + /// by name to a value). This internal method is used by public @ref setValue + /// methods. + /// + /// @tparam DataType one of int64_t, double, StatsDuration or string + /// @param name name of the statistic + /// @param value specified statistic will be set to this value + /// @throw InvalidStatType is statistic exists and has a different type. + template<typename DataType> + void addValueInternal(const std::string& name, DataType value) { + // If we want to log each observation, here would be the best place for it. + ObservationPtr existing = getObservationInternal(name); + if (!existing) { + // We tried to add to a non-existing statistic. We can recover from + // that. Simply add the new incremental value as a new statistic and + // we're done. + setValueInternal(name, value); + return; + } else { + // Let's hope it is of correct type. If not, the underlying + // addValue() method will throw. + existing->addValue(value); + } + } + + /// @public + + /// @brief Adds a new observation. + /// + /// That's an utility method used by public @ref setValue() and + /// @ref addValue() methods. + /// Calls @ref addObservationInternal() method in a thread safe context. + /// + /// @param stat observation + void addObservation(const ObservationPtr& stat); + + /// @public + + /// @brief Adds a new observation in a thread safe context. + /// + /// That's an utility method used by public @ref setValue() and + /// @ref addValue() methods. + /// Should be called in a thread safe context. + /// + /// @param stat observation + void addObservationInternal(const ObservationPtr& stat); + + /// @private + + /// @brief Tries to delete an observation. + /// + /// Calls @ref deleteObservationInternal() method in a thread safe context. + /// + /// @param name of the statistic to be deleted + /// @return true if deleted, false if not found + bool deleteObservation(const std::string& name); + + /// @private + + /// @brief Tries to delete an observation in a thread safe context. + /// + /// Should be called in a thread safe context. + /// + /// @param name of the statistic to be deleted + /// @return true if deleted, false if not found + bool deleteObservationInternal(const std::string& name); + + /// @private + + /// @brief Determines maximum age of samples. + /// + /// Should be called in a thread safe context. + /// + /// @param name name of the observation + /// @param duration determines maximum age of samples + /// @return true if successful, false if there's no such statistic + bool setMaxSampleAgeInternal(const std::string& name, const StatsDuration& duration); + + /// @private + + /// @brief Determines how many samples of a given statistic should be kept. + /// + /// Should be called in a thread safe context. + /// + /// @param name name of the observation + /// @param max_samples how many samples of a given statistic should be kept + /// @return true if successful, false if there's no such statistic + bool setMaxSampleCountInternal(const std::string& name, uint32_t max_samples); + + /// @private + + /// @brief Set duration limit for all collected statistics. + /// + /// Should be called in a thread safe context. + /// + /// @param duration determines maximum age of samples + void setMaxSampleAgeAllInternal(const StatsDuration& duration); + + /// @private + + /// @brief Set count limit for all collected statistics. + /// + /// Should be called in a thread safe context. + /// + /// @param max_samples how many samples of a given statistic should be kept + void setMaxSampleCountAllInternal(uint32_t max_samples); + + /// @private + + /// @brief Set default duration limit. + /// + /// Should be called in a thread safe context. + /// + /// @param duration default maximum age of samples to keep. + void setMaxSampleAgeDefaultInternal(const StatsDuration& duration); + + /// @brief Set default count limit. + /// + /// Should be called in a thread safe context. + /// + /// @param max_samples default maximum number of samples to keep. + /// (0 means to disable count limit and enable age limit) + void setMaxSampleCountDefaultInternal(uint32_t max_samples); + + /// @private + + /// @brief Get default duration limit. + /// + /// Should be called in a thread safe context. + /// + /// @return default maximum age of samples to keep. + const StatsDuration& getMaxSampleAgeDefaultInternal() const; + + /// @brief Get default count limit. + /// + /// Should be called in a thread safe context. + /// + /// @return default maximum number of samples to keep. + /// (0 means that count limit was disabled) + uint32_t getMaxSampleCountDefaultInternal() const; + + /// @private + + /// @brief Resets specified statistic. + /// + /// Should be called in a thread safe context. + /// + /// @param name name of the statistic to be reset. + /// @return true if successful, false if there's no such statistic + bool resetInternal(const std::string& name); + + /// @private + + /// @brief Removes specified statistic. + /// + /// Should be called in a thread safe context. + /// + /// @param name name of the statistic to be removed. + /// @return true if successful, false if there's no such statistic + bool delInternal(const std::string& name); + + /// @private + + /// @brief Resets all collected statistics back to zero. + /// + /// Should be called in a thread safe context. + void resetAllInternal(); + + /// @private + + /// @brief Removes all collected statistics. + /// + /// Should be called in a thread safe context. + void removeAllInternal(); + + /// @private + + /// @brief Returns size of specified statistic. + /// + /// Should be called in a thread safe context. + /// + /// @param name name of the statistic which size should be return. + /// @return size of specified statistic, 0 means lack of given statistic. + size_t getSizeInternal(const std::string& name) const; + + /// @private + + /// @brief Returns number of available statistics. + /// + /// Should be called in a thread safe context. + /// + /// @return number of recorded statistics. + size_t countInternal() const; + + /// @private + + /// @brief Returns a single statistic as a JSON structure. + /// + /// Should be called in a thread safe context. + /// + /// @return JSON structures representing a single statistic + isc::data::ConstElementPtr getInternal(const std::string& name) const; + + /// @private + + /// @brief Returns all statistics as a JSON structure. + /// + /// Should be called in a thread safe context. + /// + /// @return JSON structures representing all statistics + isc::data::ConstElementPtr getAllInternal() const; + + /// @private + + /// @brief Utility method that attempts to extract statistic name + /// + /// This method attempts to extract statistic name from the params + /// structure. It is expected to be a map that contains 'name' element, + /// that is of type string. If present as expected, statistic name + /// set and true is returned. If missing or is of incorrect type, the reason + /// is specified in reason parameter and false is returned. + /// + /// @param params parameters structure received in command + /// @param name [out] name of the statistic (if no error detected) + /// @param reason [out] failure reason (if error is detected) + /// @return true (if everything is ok), false otherwise + static bool getStatName(const isc::data::ConstElementPtr& params, + std::string& name, + std::string& reason); + + /// @private + + /// @brief Utility method that attempts to extract duration limit for + /// a given statistic + /// + /// This method attempts to extract duration limit for a given statistic + /// from the params structure. + /// It is expected to be a map that contains four 'duration' elements: 'hours', + /// 'minutes', 'seconds' and 'milliseconds' + /// all are of type int. If present as expected, statistic duration + /// limit is set and true is returned. + /// If any of these four parameters is missing or is of incorrect type, + /// the reason is specified in reason parameter and false is returned. + /// + /// @param params parameters structure received in command + /// @param duration [out] duration limit for the statistic (if no error detected) + /// @param reason [out] failure reason (if error is detected) + /// @return true (if everything is ok), false otherwise + static bool getStatDuration(const isc::data::ConstElementPtr& params, + StatsDuration& duration, + std::string& reason); + + /// @private + + /// @brief Utility method that attempts to extract count limit for + /// a given statistic + /// + /// This method attempts to extract count limit for a given statistic + /// from the params structure. + /// It is expected to be a map that contains 'max-samples' element, + /// that is of type int. If present as expected, statistic count + /// limit (max_samples) is set and true is returned. + /// If missing or is of incorrect type, the reason is specified in reason + /// parameter and false is returned. + /// + /// @param params parameters structure received in command + /// @param max_samples [out] count limit for the statistic (if no error detected) + /// @param reason [out] failure reason (if error is detected) + /// @return true (if everything is ok), false otherwise + static bool getStatMaxSamples(const isc::data::ConstElementPtr& params, + uint32_t& max_samples, + std::string& reason); + + /// @brief This is a global context. All statistics will initially be stored here. + StatContextPtr global_; + + /// @brief The mutex used to protect internal state. + const boost::scoped_ptr<std::mutex> mutex_; +}; + +} // namespace stats +} // namespace isc + +#endif // STATS_MGR diff --git a/src/lib/stats/tests/Makefile.am b/src/lib/stats/tests/Makefile.am new file mode 100644 index 0000000..c8f53aa --- /dev/null +++ b/src/lib/stats/tests/Makefile.am @@ -0,0 +1,35 @@ +SUBDIRS = . + +AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib +AM_CPPFLAGS += $(BOOST_INCLUDES) + +AM_CXXFLAGS = $(KEA_CXXFLAGS) + +if USE_STATIC_LINK +AM_LDFLAGS = -static +endif + +if HAVE_GTEST + +TESTS = libstats_unittests + +libstats_unittests_SOURCES = run_unittests.cc +libstats_unittests_SOURCES += observation_unittest.cc +libstats_unittests_SOURCES += context_unittest.cc +libstats_unittests_SOURCES += stats_mgr_unittest.cc + +libstats_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) +libstats_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) +libstats_unittests_CXXFLAGS = $(AM_CXXFLAGS) + +libstats_unittests_LDADD = $(top_builddir)/src/lib/stats/libkea-stats.la +libstats_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la +libstats_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la +libstats_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la +libstats_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la +libstats_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la +libstats_unittests_LDADD += $(LOG4CPLUS_LIBS) $(GTEST_LDADD) $(BOOST_LIBS) + +endif + +noinst_PROGRAMS = $(TESTS) diff --git a/src/lib/stats/tests/Makefile.in b/src/lib/stats/tests/Makefile.in new file mode 100644 index 0000000..1c78036 --- /dev/null +++ b/src/lib/stats/tests/Makefile.in @@ -0,0 +1,1017 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +@HAVE_GTEST_TRUE@TESTS = libstats_unittests$(EXEEXT) +noinst_PROGRAMS = $(am__EXEEXT_1) +subdir = src/lib/stats/tests +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4macros/ax_boost_for_kea.m4 \ + $(top_srcdir)/m4macros/ax_cpp11.m4 \ + $(top_srcdir)/m4macros/ax_crypto.m4 \ + $(top_srcdir)/m4macros/ax_find_library.m4 \ + $(top_srcdir)/m4macros/ax_gssapi.m4 \ + $(top_srcdir)/m4macros/ax_gtest.m4 \ + $(top_srcdir)/m4macros/ax_isc_rpath.m4 \ + $(top_srcdir)/m4macros/ax_sysrepo.m4 \ + $(top_srcdir)/m4macros/libtool.m4 \ + $(top_srcdir)/m4macros/ltoptions.m4 \ + $(top_srcdir)/m4macros/ltsugar.m4 \ + $(top_srcdir)/m4macros/ltversion.m4 \ + $(top_srcdir)/m4macros/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +@HAVE_GTEST_TRUE@am__EXEEXT_1 = libstats_unittests$(EXEEXT) +PROGRAMS = $(noinst_PROGRAMS) +am__libstats_unittests_SOURCES_DIST = run_unittests.cc \ + observation_unittest.cc context_unittest.cc \ + stats_mgr_unittest.cc +@HAVE_GTEST_TRUE@am_libstats_unittests_OBJECTS = \ +@HAVE_GTEST_TRUE@ libstats_unittests-run_unittests.$(OBJEXT) \ +@HAVE_GTEST_TRUE@ libstats_unittests-observation_unittest.$(OBJEXT) \ +@HAVE_GTEST_TRUE@ libstats_unittests-context_unittest.$(OBJEXT) \ +@HAVE_GTEST_TRUE@ libstats_unittests-stats_mgr_unittest.$(OBJEXT) +libstats_unittests_OBJECTS = $(am_libstats_unittests_OBJECTS) +am__DEPENDENCIES_1 = +@HAVE_GTEST_TRUE@libstats_unittests_DEPENDENCIES = $(top_builddir)/src/lib/stats/libkea-stats.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/cc/libkea-cc.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/asiolink/libkea-asiolink.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/log/libkea-log.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/util/libkea-util.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/exceptions/libkea-exceptions.la \ +@HAVE_GTEST_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ +@HAVE_GTEST_TRUE@ $(am__DEPENDENCIES_1) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +libstats_unittests_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ + $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) \ + $(libstats_unittests_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = \ + ./$(DEPDIR)/libstats_unittests-context_unittest.Po \ + ./$(DEPDIR)/libstats_unittests-observation_unittest.Po \ + ./$(DEPDIR)/libstats_unittests-run_unittests.Po \ + ./$(DEPDIR)/libstats_unittests-stats_mgr_unittest.Po +am__mv = mv -f +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +AM_V_CXX = $(am__v_CXX_@AM_V@) +am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@) +am__v_CXX_0 = @echo " CXX " $@; +am__v_CXX_1 = +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CXXLD = $(am__v_CXXLD_@AM_V@) +am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) +am__v_CXXLD_0 = @echo " CXXLD " $@; +am__v_CXXLD_1 = +SOURCES = $(libstats_unittests_SOURCES) +DIST_SOURCES = $(am__libstats_unittests_SOURCES_DIST) +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + distdir distdir-am +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__tty_colors_dummy = \ + mgn= red= grn= lgn= blu= brg= std=; \ + am__color_tests=no +am__tty_colors = { \ + $(am__tty_colors_dummy); \ + if test "X$(AM_COLOR_TESTS)" = Xno; then \ + am__color_tests=no; \ + elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ + am__color_tests=yes; \ + elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ + am__color_tests=yes; \ + fi; \ + if test $$am__color_tests = yes; then \ + red='[0;31m'; \ + grn='[0;32m'; \ + lgn='[1;32m'; \ + blu='[1;34m'; \ + mgn='[0;35m'; \ + brg='[1m'; \ + std='[m'; \ + fi; \ +} +DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +ASCIIDOC = @ASCIIDOC@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BOOST_INCLUDES = @BOOST_INCLUDES@ +BOOST_LIBS = @BOOST_LIBS@ +BOTAN_TOOL = @BOTAN_TOOL@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CONTRIB_DIR = @CONTRIB_DIR@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPTO_CFLAGS = @CRYPTO_CFLAGS@ +CRYPTO_INCLUDES = @CRYPTO_INCLUDES@ +CRYPTO_LDFLAGS = @CRYPTO_LDFLAGS@ +CRYPTO_LIBS = @CRYPTO_LIBS@ +CRYPTO_PACKAGE = @CRYPTO_PACKAGE@ +CRYPTO_RPATH = @CRYPTO_RPATH@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DISTCHECK_BOOST_CONFIGURE_FLAG = @DISTCHECK_BOOST_CONFIGURE_FLAG@ +DISTCHECK_CONTRIB_CONFIGURE_FLAG = @DISTCHECK_CONTRIB_CONFIGURE_FLAG@ +DISTCHECK_CRYPTO_CONFIGURE_FLAG = @DISTCHECK_CRYPTO_CONFIGURE_FLAG@ +DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@ +DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@ +DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@ +DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@ +DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GENHTML = @GENHTML@ +GREP = @GREP@ +GSSAPI_CFLAGS = @GSSAPI_CFLAGS@ +GSSAPI_LIBS = @GSSAPI_LIBS@ +GTEST_CONFIG = @GTEST_CONFIG@ +GTEST_INCLUDES = @GTEST_INCLUDES@ +GTEST_LDADD = @GTEST_LDADD@ +GTEST_LDFLAGS = @GTEST_LDFLAGS@ +GTEST_SOURCE = @GTEST_SOURCE@ +HAVE_SYSREPO = @HAVE_SYSREPO@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KEA_CXXFLAGS = @KEA_CXXFLAGS@ +KEA_SRCID = @KEA_SRCID@ +KRB5_CONFIG = @KRB5_CONFIG@ +LCOV = @LCOV@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LOG4CPLUS_INCLUDES = @LOG4CPLUS_INCLUDES@ +LOG4CPLUS_LIBS = @LOG4CPLUS_LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PACKAGE_VERSION_TYPE = @PACKAGE_VERSION_TYPE@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PDFLATEX = @PDFLATEX@ +PERL = @PERL@ +PGSQL_CPPFLAGS = @PGSQL_CPPFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PKGPYTHONDIR = @PKGPYTHONDIR@ +PKG_CONFIG = @PKG_CONFIG@ +PLANTUML = @PLANTUML@ +PREMIUM_DIR = @PREMIUM_DIR@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +RANLIB = @RANLIB@ +SED = @SED@ +SEP = @SEP@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SPHINXBUILD = @SPHINXBUILD@ +SRPD_PLUGINS_PATH = @SRPD_PLUGINS_PATH@ +SR_REPO_PATH = @SR_REPO_PATH@ +STRIP = @STRIP@ +SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@ +SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@ +SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@ +SYSREPO_LIBS = @SYSREPO_LIBS@ +SYSREPO_VERSION = @SYSREPO_VERSION@ +USE_LCOV = @USE_LCOV@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +WARNING_GCC_44_STRICT_ALIASING_CFLAG = @WARNING_GCC_44_STRICT_ALIASING_CFLAG@ +YACC = @YACC@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +SUBDIRS = . +AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib \ + $(BOOST_INCLUDES) +AM_CXXFLAGS = $(KEA_CXXFLAGS) +@USE_STATIC_LINK_TRUE@AM_LDFLAGS = -static +@HAVE_GTEST_TRUE@libstats_unittests_SOURCES = run_unittests.cc \ +@HAVE_GTEST_TRUE@ observation_unittest.cc context_unittest.cc \ +@HAVE_GTEST_TRUE@ stats_mgr_unittest.cc +@HAVE_GTEST_TRUE@libstats_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) +@HAVE_GTEST_TRUE@libstats_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) +@HAVE_GTEST_TRUE@libstats_unittests_CXXFLAGS = $(AM_CXXFLAGS) +@HAVE_GTEST_TRUE@libstats_unittests_LDADD = $(top_builddir)/src/lib/stats/libkea-stats.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/cc/libkea-cc.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/asiolink/libkea-asiolink.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/log/libkea-log.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/util/libkea-util.la \ +@HAVE_GTEST_TRUE@ $(top_builddir)/src/lib/exceptions/libkea-exceptions.la \ +@HAVE_GTEST_TRUE@ $(LOG4CPLUS_LIBS) $(GTEST_LDADD) \ +@HAVE_GTEST_TRUE@ $(BOOST_LIBS) +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .cc .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib/stats/tests/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/lib/stats/tests/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +libstats_unittests$(EXEEXT): $(libstats_unittests_OBJECTS) $(libstats_unittests_DEPENDENCIES) $(EXTRA_libstats_unittests_DEPENDENCIES) + @rm -f libstats_unittests$(EXEEXT) + $(AM_V_CXXLD)$(libstats_unittests_LINK) $(libstats_unittests_OBJECTS) $(libstats_unittests_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstats_unittests-context_unittest.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstats_unittests-observation_unittest.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstats_unittests-run_unittests.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstats_unittests-stats_mgr_unittest.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.cc.o: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $< + +.cc.obj: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cc.lo: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $< + +libstats_unittests-run_unittests.o: run_unittests.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -MT libstats_unittests-run_unittests.o -MD -MP -MF $(DEPDIR)/libstats_unittests-run_unittests.Tpo -c -o libstats_unittests-run_unittests.o `test -f 'run_unittests.cc' || echo '$(srcdir)/'`run_unittests.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstats_unittests-run_unittests.Tpo $(DEPDIR)/libstats_unittests-run_unittests.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='run_unittests.cc' object='libstats_unittests-run_unittests.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -c -o libstats_unittests-run_unittests.o `test -f 'run_unittests.cc' || echo '$(srcdir)/'`run_unittests.cc + +libstats_unittests-run_unittests.obj: run_unittests.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -MT libstats_unittests-run_unittests.obj -MD -MP -MF $(DEPDIR)/libstats_unittests-run_unittests.Tpo -c -o libstats_unittests-run_unittests.obj `if test -f 'run_unittests.cc'; then $(CYGPATH_W) 'run_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/run_unittests.cc'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstats_unittests-run_unittests.Tpo $(DEPDIR)/libstats_unittests-run_unittests.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='run_unittests.cc' object='libstats_unittests-run_unittests.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -c -o libstats_unittests-run_unittests.obj `if test -f 'run_unittests.cc'; then $(CYGPATH_W) 'run_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/run_unittests.cc'; fi` + +libstats_unittests-observation_unittest.o: observation_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -MT libstats_unittests-observation_unittest.o -MD -MP -MF $(DEPDIR)/libstats_unittests-observation_unittest.Tpo -c -o libstats_unittests-observation_unittest.o `test -f 'observation_unittest.cc' || echo '$(srcdir)/'`observation_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstats_unittests-observation_unittest.Tpo $(DEPDIR)/libstats_unittests-observation_unittest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='observation_unittest.cc' object='libstats_unittests-observation_unittest.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -c -o libstats_unittests-observation_unittest.o `test -f 'observation_unittest.cc' || echo '$(srcdir)/'`observation_unittest.cc + +libstats_unittests-observation_unittest.obj: observation_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -MT libstats_unittests-observation_unittest.obj -MD -MP -MF $(DEPDIR)/libstats_unittests-observation_unittest.Tpo -c -o libstats_unittests-observation_unittest.obj `if test -f 'observation_unittest.cc'; then $(CYGPATH_W) 'observation_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/observation_unittest.cc'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstats_unittests-observation_unittest.Tpo $(DEPDIR)/libstats_unittests-observation_unittest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='observation_unittest.cc' object='libstats_unittests-observation_unittest.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -c -o libstats_unittests-observation_unittest.obj `if test -f 'observation_unittest.cc'; then $(CYGPATH_W) 'observation_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/observation_unittest.cc'; fi` + +libstats_unittests-context_unittest.o: context_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -MT libstats_unittests-context_unittest.o -MD -MP -MF $(DEPDIR)/libstats_unittests-context_unittest.Tpo -c -o libstats_unittests-context_unittest.o `test -f 'context_unittest.cc' || echo '$(srcdir)/'`context_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstats_unittests-context_unittest.Tpo $(DEPDIR)/libstats_unittests-context_unittest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='context_unittest.cc' object='libstats_unittests-context_unittest.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -c -o libstats_unittests-context_unittest.o `test -f 'context_unittest.cc' || echo '$(srcdir)/'`context_unittest.cc + +libstats_unittests-context_unittest.obj: context_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -MT libstats_unittests-context_unittest.obj -MD -MP -MF $(DEPDIR)/libstats_unittests-context_unittest.Tpo -c -o libstats_unittests-context_unittest.obj `if test -f 'context_unittest.cc'; then $(CYGPATH_W) 'context_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/context_unittest.cc'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstats_unittests-context_unittest.Tpo $(DEPDIR)/libstats_unittests-context_unittest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='context_unittest.cc' object='libstats_unittests-context_unittest.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -c -o libstats_unittests-context_unittest.obj `if test -f 'context_unittest.cc'; then $(CYGPATH_W) 'context_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/context_unittest.cc'; fi` + +libstats_unittests-stats_mgr_unittest.o: stats_mgr_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -MT libstats_unittests-stats_mgr_unittest.o -MD -MP -MF $(DEPDIR)/libstats_unittests-stats_mgr_unittest.Tpo -c -o libstats_unittests-stats_mgr_unittest.o `test -f 'stats_mgr_unittest.cc' || echo '$(srcdir)/'`stats_mgr_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstats_unittests-stats_mgr_unittest.Tpo $(DEPDIR)/libstats_unittests-stats_mgr_unittest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='stats_mgr_unittest.cc' object='libstats_unittests-stats_mgr_unittest.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -c -o libstats_unittests-stats_mgr_unittest.o `test -f 'stats_mgr_unittest.cc' || echo '$(srcdir)/'`stats_mgr_unittest.cc + +libstats_unittests-stats_mgr_unittest.obj: stats_mgr_unittest.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -MT libstats_unittests-stats_mgr_unittest.obj -MD -MP -MF $(DEPDIR)/libstats_unittests-stats_mgr_unittest.Tpo -c -o libstats_unittests-stats_mgr_unittest.obj `if test -f 'stats_mgr_unittest.cc'; then $(CYGPATH_W) 'stats_mgr_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/stats_mgr_unittest.cc'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstats_unittests-stats_mgr_unittest.Tpo $(DEPDIR)/libstats_unittests-stats_mgr_unittest.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='stats_mgr_unittest.cc' object='libstats_unittests-stats_mgr_unittest.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstats_unittests_CPPFLAGS) $(CPPFLAGS) $(libstats_unittests_CXXFLAGS) $(CXXFLAGS) -c -o libstats_unittests-stats_mgr_unittest.obj `if test -f 'stats_mgr_unittest.cc'; then $(CYGPATH_W) 'stats_mgr_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/stats_mgr_unittest.cc'; fi` + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + col="$$grn"; \ + else \ + col="$$red"; \ + fi; \ + echo "$${col}$$dashes$${std}"; \ + echo "$${col}$$banner$${std}"; \ + test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \ + test -z "$$report" || echo "$${col}$$report$${std}"; \ + echo "$${col}$$dashes$${std}"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-recursive +all-am: Makefile $(PROGRAMS) +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ + mostlyclean-am + +distclean: distclean-recursive + -rm -f ./$(DEPDIR)/libstats_unittests-context_unittest.Po + -rm -f ./$(DEPDIR)/libstats_unittests-observation_unittest.Po + -rm -f ./$(DEPDIR)/libstats_unittests-run_unittests.Po + -rm -f ./$(DEPDIR)/libstats_unittests-stats_mgr_unittest.Po + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f ./$(DEPDIR)/libstats_unittests-context_unittest.Po + -rm -f ./$(DEPDIR)/libstats_unittests-observation_unittest.Po + -rm -f ./$(DEPDIR)/libstats_unittests-run_unittests.Po + -rm -f ./$(DEPDIR)/libstats_unittests-stats_mgr_unittest.Po + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: + +.MAKE: $(am__recursive_targets) check-am install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--depfiles check check-TESTS check-am clean clean-generic \ + clean-libtool clean-noinstPROGRAMS cscopelist-am ctags \ + ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/lib/stats/tests/context_unittest.cc b/src/lib/stats/tests/context_unittest.cc new file mode 100644 index 0000000..92c754c --- /dev/null +++ b/src/lib/stats/tests/context_unittest.cc @@ -0,0 +1,126 @@ +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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 <config.h> + +#include <stats/context.h> +#include <gtest/gtest.h> +#include <util/chrono_time_utils.h> +#include <string> + +using namespace isc::data; +using namespace isc::stats; +using namespace std; +using namespace std::chrono; + +// Basic test that checks get, add, del methods +TEST(ContextTest, basic) { + + // Let's create a couple observations. Using floating point, + // as they're easiest to initialize. + ObservationPtr a(new Observation("alpha", 1.11)); + ObservationPtr b(new Observation("beta", 2.22)); + ObservationPtr c(new Observation("gamma", 3.33)); + string expected_a = a->getJSON()->str(); + string expected_b = b->getJSON()->str(); + string expected_c = c->getJSON()->str(); + + + // Context where we will store the observations. + StatContext ctx; + + // By default the context does not hold any statistics. + EXPECT_EQ(0, ctx.size()); + + // It should be possible to add 'a' statistic + EXPECT_NO_THROW(ctx.add(a)); + + // We can't add a duplicate. + EXPECT_THROW(ctx.add(a), DuplicateStat); + + // It should be ok to add other statistics + EXPECT_NO_THROW(ctx.add(b)); + EXPECT_NO_THROW(ctx.add(c)); + + // By now we should have 3 statistics recorded + EXPECT_EQ(3, ctx.size()); + + // Let's try to retrieve them + ObservationPtr from_ctx; + EXPECT_NO_THROW(from_ctx = ctx.get("alpha")); + ASSERT_TRUE(from_ctx); + EXPECT_EQ(expected_a, from_ctx->getJSON()->str()); + + EXPECT_NO_THROW(from_ctx = ctx.get("beta")); + ASSERT_TRUE(from_ctx); + EXPECT_EQ(expected_b, from_ctx->getJSON()->str()); + + EXPECT_NO_THROW(from_ctx = ctx.get("gamma")); + ASSERT_TRUE(from_ctx); + EXPECT_EQ(expected_c, from_ctx->getJSON()->str()); + + // Let's try to retrieve non-existing stat + EXPECT_NO_THROW(from_ctx = ctx.get("delta")); + EXPECT_FALSE(from_ctx); + + // Now delete one of the stats... + EXPECT_TRUE(ctx.del("beta")); + + // ... and check that it's really gone. + EXPECT_FALSE(ctx.get("beta")); + + // Attempt to delete non-existing stat should fail. + EXPECT_FALSE(ctx.del("beta")); + + ConstElementPtr result; + EXPECT_NO_THROW(result = ctx.getAll()); + + ASSERT_TRUE(result); + ElementPtr expected_result = Element::createMap(); + expected_result->set("alpha", a->getJSON()); + expected_result->set("gamma", c->getJSON()); + EXPECT_EQ(result->str(), expected_result->str()); + + // Reset all statistics. + EXPECT_NO_THROW(ctx.resetAll()); + + EXPECT_NO_THROW(from_ctx = ctx.get("alpha")); + ASSERT_TRUE(from_ctx); + EXPECT_NE(expected_a, from_ctx->getJSON()->str()); + EXPECT_EQ(0.0, a->getFloat().first); + + EXPECT_NO_THROW(from_ctx = ctx.get("gamma")); + ASSERT_TRUE(from_ctx); + EXPECT_NE(expected_c, from_ctx->getJSON()->str()); + EXPECT_EQ(0.0, c->getFloat().first); + + // Set sample count for all statistics + EXPECT_NO_THROW(ctx.setMaxSampleCountAll(50)); + + EXPECT_NO_THROW(from_ctx = ctx.get("alpha")); + ASSERT_TRUE(from_ctx); + EXPECT_EQ(from_ctx->getMaxSampleCount().second, 50); + + EXPECT_NO_THROW(from_ctx = ctx.get("gamma")); + ASSERT_TRUE(from_ctx); + EXPECT_EQ(from_ctx->getMaxSampleCount().second, 50); + + // Set sample age for all statistics + const StatsDuration& dur(minutes(4) + seconds(5) + milliseconds(3)); + EXPECT_NO_THROW(ctx.setMaxSampleAgeAll(dur)); + + EXPECT_NO_THROW(from_ctx = ctx.get("alpha")); + ASSERT_TRUE(from_ctx); + EXPECT_EQ(from_ctx->getMaxSampleAge().second, dur); + + EXPECT_NO_THROW(from_ctx = ctx.get("gamma")); + ASSERT_TRUE(from_ctx); + EXPECT_EQ(from_ctx->getMaxSampleAge().second, dur); + + // Clear all statistics. + EXPECT_NO_THROW(ctx.clear()); + EXPECT_EQ(0, ctx.size()); +} diff --git a/src/lib/stats/tests/observation_unittest.cc b/src/lib/stats/tests/observation_unittest.cc new file mode 100644 index 0000000..ad10368 --- /dev/null +++ b/src/lib/stats/tests/observation_unittest.cc @@ -0,0 +1,619 @@ +// Copyright (C) 2015-2021 Internet Systems Consortium, Inc. ("ISC") +// +// 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 <config.h> + +#include <stats/observation.h> +#include <exceptions/exceptions.h> +#include <util/chrono_time_utils.h> +#include <boost/shared_ptr.hpp> +#include <gtest/gtest.h> + +#include <iostream> +#include <sstream> + +#include <unistd.h> + +using namespace isc; +using namespace isc::stats; +using namespace std::chrono; + +namespace { + +static const StatsDuration& dur1234(hours(1) + minutes(2) + seconds(3) + + milliseconds(4)); +static const StatsDuration& dur5678(hours(5) + minutes(6) + seconds(7) + + milliseconds(8)); +static const StatsDuration& dur681012(hours(6) + minutes(8) + seconds(10) + + milliseconds(12)); +static const StatsDuration& dur453(minutes(4) + seconds(5) + milliseconds(3)); + +// This test verifies that the number of seconds can be retrieved. +TEST(StatsDurationTest, toSeconds) { + StatsDuration dur = StatsDuration::zero(); + dur += hours(1) + minutes(1) + seconds(1) + milliseconds(1); + EXPECT_EQ(3661, toSeconds(dur)); +} + +/// @brief Test class for Observation +/// +/// This simple fixture class initializes four observations: +/// a (integer), b (float), c(time duration) and d (string). +class ObservationTest : public ::testing::Test { +public: + + /// @brief Constructor + /// Initializes four observations. + ObservationTest() : + a("alpha", static_cast<int64_t>(1234)), // integer + b("beta", 12.34), // float + c("gamma", dur1234), // duration + d("delta", "1234") { // string + } + + Observation a; + Observation b; + Observation c; + Observation d; +}; + +// Basic tests for the Observation constructors. This test checks whether +// parameters passed to the constructor initialize the object properly. +TEST_F(ObservationTest, constructor) { + EXPECT_EQ(Observation::STAT_INTEGER, a.getType()); + EXPECT_EQ(Observation::STAT_FLOAT, b.getType()); + EXPECT_EQ(Observation::STAT_DURATION, c.getType()); + EXPECT_EQ(Observation::STAT_STRING, d.getType()); + + EXPECT_EQ(1234, a.getInteger().first); + EXPECT_EQ(12.34, b.getFloat().first); + EXPECT_EQ(dur1234, c.getDuration().first); + EXPECT_EQ("1234", d.getString().first); + + // Let's check that attempting to get a different type + // than used will cause an exception. + EXPECT_THROW(a.getFloat(), InvalidStatType); + EXPECT_THROW(a.getDuration(), InvalidStatType); + EXPECT_THROW(a.getString(), InvalidStatType); + + EXPECT_THROW(b.getInteger(), InvalidStatType); + EXPECT_THROW(b.getDuration(), InvalidStatType); + EXPECT_THROW(b.getString(), InvalidStatType); + + EXPECT_THROW(c.getInteger(), InvalidStatType); + EXPECT_THROW(c.getFloat(), InvalidStatType); + EXPECT_THROW(c.getString(), InvalidStatType); + + EXPECT_THROW(d.getInteger(), InvalidStatType); + EXPECT_THROW(d.getFloat(), InvalidStatType); + EXPECT_THROW(d.getDuration(), InvalidStatType); +} + +// This test checks whether it is possible to set to an absolute value for all +// given types. +TEST_F(ObservationTest, setValue) { + EXPECT_NO_THROW(a.setValue(static_cast<int64_t>(5678))); + EXPECT_NO_THROW(b.setValue(56e+78)); + EXPECT_NO_THROW(c.setValue(dur5678)); + EXPECT_NO_THROW(d.setValue("fiveSixSevenEight")); + + + EXPECT_EQ(5678, a.getInteger().first); + EXPECT_EQ(56e+78, b.getFloat().first); + EXPECT_EQ(dur5678, c.getDuration().first); + EXPECT_EQ("fiveSixSevenEight", d.getString().first); + + // Now check whether setting value to a different type does + // throw an exception + EXPECT_THROW(a.setValue(56e+78), InvalidStatType); + EXPECT_THROW(a.setValue(dur5678), InvalidStatType); + EXPECT_THROW(a.setValue("fiveSixSevenEight"), InvalidStatType); + + EXPECT_THROW(b.setValue(static_cast<int64_t>(5678)), InvalidStatType); + EXPECT_THROW(b.setValue(dur5678), InvalidStatType); + EXPECT_THROW(b.setValue("fiveSixSevenEight"), InvalidStatType); + + EXPECT_THROW(c.setValue(static_cast<int64_t>(5678)), InvalidStatType); + EXPECT_THROW(c.setValue(56e+78), InvalidStatType); + EXPECT_THROW(c.setValue("fiveSixSevenEight"), InvalidStatType); + + EXPECT_THROW(d.setValue(static_cast<int64_t>(5678)), InvalidStatType); + EXPECT_THROW(d.setValue(56e+78), InvalidStatType); + EXPECT_THROW(d.setValue(dur5678), InvalidStatType); +} + +// This test checks whether it is possible to add value to existing +// counter. +TEST_F(ObservationTest, addValue) { + // Note: all Observations were set to 1234, 12.34 or similar in + // ObservationTest constructor. + + EXPECT_NO_THROW(a.addValue(static_cast<int64_t>(5678))); + EXPECT_NO_THROW(b.addValue(56.78)); + EXPECT_NO_THROW(c.addValue(dur5678)); + EXPECT_NO_THROW(d.addValue("fiveSixSevenEight")); + + EXPECT_EQ(6912, a.getInteger().first); + EXPECT_EQ(69.12, b.getFloat().first); + EXPECT_EQ(dur681012, c.getDuration().first); + EXPECT_EQ("1234fiveSixSevenEight", d.getString().first); + + ASSERT_EQ(a.getSize(), 2); + ASSERT_EQ(b.getSize(), 2); + ASSERT_EQ(c.getSize(), 2); + ASSERT_EQ(d.getSize(), 2); +} + +// This test checks if collecting more than one sample +// works well. +TEST_F(ObservationTest, moreThanOne) { + // Arrays of 4 types of samples + int64_t int_samples[3] = {1234, 6912, 5678}; + double float_samples[3] = {12.34, 69.12, 56e+78}; + StatsDuration duration_samples[3] = {dur1234, + dur681012, dur5678}; + std::string string_samples[3] = {"1234", "1234fiveSixSevenEight", "fiveSixSevenEight"}; + + EXPECT_NO_THROW(a.addValue(static_cast<int64_t>(5678))); + EXPECT_NO_THROW(b.addValue(56.78)); + EXPECT_NO_THROW(c.addValue(dur5678)); + EXPECT_NO_THROW(d.addValue("fiveSixSevenEight")); + + EXPECT_NO_THROW(a.setValue(static_cast<int64_t>(5678))); + EXPECT_NO_THROW(b.setValue(56e+78)); + EXPECT_NO_THROW(c.setValue(dur5678)); + EXPECT_NO_THROW(d.setValue("fiveSixSevenEight")); + + ASSERT_EQ(a.getSize(), 3); + ASSERT_EQ(b.getSize(), 3); + ASSERT_EQ(c.getSize(), 3); + ASSERT_EQ(d.getSize(), 3); + + ASSERT_NO_THROW(a.getIntegers()); + ASSERT_NO_THROW(b.getFloats()); + ASSERT_NO_THROW(c.getDurations()); + ASSERT_NO_THROW(d.getStrings()); + + std::list<IntegerSample> samples_int = a.getIntegers(); // List of all integer samples + std::list<FloatSample> samples_float = b.getFloats(); // List of all float samples + std::list<DurationSample> samples_dur = c.getDurations(); // List of all duration samples + std::list<StringSample> samples_str = d.getStrings(); // List of all string samples + + uint32_t i = 2; // Index pointed to the end of array of samples + + for (std::list<IntegerSample>::iterator it = samples_int.begin(); it != samples_int.end(); ++it) { + EXPECT_EQ(int_samples[i], static_cast<int64_t>((*it).first)); + --i; + } + i = 2; + for (std::list<FloatSample>::iterator it = samples_float.begin(); it != samples_float.end(); ++it) { + EXPECT_EQ(float_samples[i], (*it).first); + --i; + } + i = 2; + for (std::list<DurationSample>::iterator it = samples_dur.begin(); it != samples_dur.end(); ++it) { + EXPECT_EQ(duration_samples[i], (*it).first); + --i; + } + i = 2; + for (std::list<StringSample>::iterator it = samples_str.begin(); it != samples_str.end(); ++it) { + EXPECT_EQ(string_samples[i], (*it).first); + --i; + } +} + +// This test checks whether the size of storage +// is equal to the true value +TEST_F(ObservationTest, getSize) { + // Check if size of storages is equal to 1 + ASSERT_EQ(a.getSize(), 1); + ASSERT_EQ(b.getSize(), 1); + ASSERT_EQ(c.getSize(), 1); + ASSERT_EQ(d.getSize(), 1); + + a.addValue(static_cast<int64_t>(5678)); + b.addValue(56.78); + c.addValue(dur5678); + d.addValue("fiveSixSevenEight"); + + EXPECT_NO_THROW(a.getSize()); + EXPECT_NO_THROW(b.getSize()); + EXPECT_NO_THROW(c.getSize()); + EXPECT_NO_THROW(d.getSize()); + + // Check if size of storages is equal to 2 + ASSERT_EQ(a.getSize(), 2); + ASSERT_EQ(b.getSize(), 2); + ASSERT_EQ(c.getSize(), 2); + ASSERT_EQ(d.getSize(), 2); + + a.setValue(static_cast<int64_t>(5678)); + b.setValue(56e+78); + c.setValue(dur5678); + d.setValue("fiveSixSevenEight"); + + EXPECT_NO_THROW(a.getSize()); + EXPECT_NO_THROW(b.getSize()); + EXPECT_NO_THROW(c.getSize()); + EXPECT_NO_THROW(d.getSize()); + + // Check if size of storages is equal to 3 + ASSERT_EQ(a.getSize(), 3); + ASSERT_EQ(b.getSize(), 3); + ASSERT_EQ(c.getSize(), 3); + ASSERT_EQ(d.getSize(), 3); +} + +// Checks whether setting amount limits works properly +TEST_F(ObservationTest, setCountLimit) { + // Preparing of 21 test's samples for each type of storage + int64_t int_samples[22] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21}; + double float_samples[22] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, + 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, + 20.0, 21.0}; + std::string string_samples[22] = {"a", "b", "c", "d", "e", "f", "g", "h", + "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", + "v"}; + StatsDuration duration_samples[22]; + + for (uint32_t i = 0; i < 22; ++i) { + duration_samples[i] = milliseconds(i); + } + + // By default the max_sample_count is set to 20 and max_sample_age + // is deactivated + // Adding 21 samples to each type of Observation + for (uint32_t i = 0; i < 21; ++i) { + a.setValue(int_samples[i]); + } + for (uint32_t i = 0; i < 21; ++i) { + b.setValue(float_samples[i]); + } + for (uint32_t i = 0; i < 21; ++i) { + c.setValue(duration_samples[i]); + } + for (uint32_t i = 0; i < 21; ++i) { + d.setValue(string_samples[i]); + } + + // Getting all 4 types of samples after inserting 21 values + std::list<IntegerSample> samples_int = a.getIntegers(); + std::list<FloatSample> samples_float = b.getFloats(); + std::list<DurationSample> samples_duration = c.getDurations(); + std::list<StringSample> samples_string = d.getStrings(); + + // Check if size of storages is equal to 20 + ASSERT_EQ(a.getSize(), 20); + ASSERT_EQ(b.getSize(), 20); + ASSERT_EQ(c.getSize(), 20); + ASSERT_EQ(d.getSize(), 20); + + // And whether stored values are correct + uint32_t i = 20; // index of the last element in array of test's samples + for (std::list<IntegerSample>::iterator it = samples_int.begin(); it != samples_int.end(); ++it) { + EXPECT_EQ((*it).first, int_samples[i]); + --i; + } + i = 20; // index of last element in array of test's samples + for (std::list<FloatSample>::iterator it = samples_float.begin(); it != samples_float.end(); ++it) { + EXPECT_EQ((*it).first, float_samples[i]); + --i; + } + i = 20; // index of last element in array of test's samples + for (std::list<DurationSample>::iterator it = samples_duration.begin(); it != samples_duration.end(); ++it) { + EXPECT_EQ((*it).first, duration_samples[i]); + --i; + } + i = 20; // index of last element in array of test's samples + for (std::list<StringSample>::iterator it = samples_string.begin(); it != samples_string.end(); ++it) { + EXPECT_EQ((*it).first, string_samples[i]); + --i; + } + + // Change size of storage to smaller one + ASSERT_NO_THROW(a.setMaxSampleCount(10)); + ASSERT_NO_THROW(b.setMaxSampleCount(10)); + ASSERT_NO_THROW(c.setMaxSampleCount(10)); + ASSERT_NO_THROW(d.setMaxSampleCount(10)); + + samples_int = a.getIntegers(); + samples_float = b.getFloats(); + samples_duration = c.getDurations(); + samples_string = d.getStrings(); + + // Check if size of storages is equal to 10 + ASSERT_EQ(a.getSize(), 10); + ASSERT_EQ(b.getSize(), 10); + ASSERT_EQ(c.getSize(), 10); + ASSERT_EQ(d.getSize(), 10); + + // And whether storages contain only the 10 newest values + i = 20; // index of last element in array of test's samples + for (std::list<IntegerSample>::iterator it = samples_int.begin(); it != samples_int.end(); ++it) { + EXPECT_EQ((*it).first, int_samples[i]); + --i; + } + i = 20; // index of last element in array of test's samples + for (std::list<FloatSample>::iterator it = samples_float.begin(); it != samples_float.end(); ++it) { + EXPECT_EQ((*it).first, float_samples[i]); + --i; + } + i = 20; // index of last element in array of test's samples + for (std::list<DurationSample>::iterator it = samples_duration.begin(); it != samples_duration.end(); ++it) { + EXPECT_EQ((*it).first, duration_samples[i]); + --i; + } + i = 20; // index of last element in array of test's samples + for (std::list<StringSample>::iterator it = samples_string.begin(); it != samples_string.end(); ++it) { + EXPECT_EQ((*it).first, string_samples[i]); + --i; + } + + // Resize max_sample_count to greater + ASSERT_NO_THROW(a.setMaxSampleCount(50)); + ASSERT_NO_THROW(b.setMaxSampleCount(50)); + ASSERT_NO_THROW(c.setMaxSampleCount(50)); + ASSERT_NO_THROW(d.setMaxSampleCount(50)); + + // Check if size of storages did not change without adding new value + ASSERT_EQ(a.getSize(), 10); + ASSERT_EQ(b.getSize(), 10); + ASSERT_EQ(c.getSize(), 10); + ASSERT_EQ(d.getSize(), 10); + + // Add new values to each type of Observation + a.setValue(static_cast<int64_t>(21)); + b.setValue(21.0); + c.setValue(milliseconds(21)); + d.setValue("v"); + + samples_int = a.getIntegers(); + samples_float = b.getFloats(); + samples_duration = c.getDurations(); + samples_string = d.getStrings(); + + ASSERT_EQ(a.getSize(), 11); + ASSERT_EQ(b.getSize(), 11); + ASSERT_EQ(c.getSize(), 11); + ASSERT_EQ(d.getSize(), 11); + + i = 21; // index of last element in array of test's samples + for (std::list<IntegerSample>::iterator it = samples_int.begin(); it != samples_int.end(); ++it) { + EXPECT_EQ((*it).first, int_samples[i]); + --i; + } + i = 21; // index of last element in array of test's samples + for (std::list<FloatSample>::iterator it = samples_float.begin(); it != samples_float.end(); ++it) { + EXPECT_EQ((*it).first, float_samples[i]); + --i; + } + i = 21; // index of last element in array of test's samples + for (std::list<DurationSample>::iterator it = samples_duration.begin(); it != samples_duration.end(); ++it) { + EXPECT_EQ((*it).first, duration_samples[i]); + --i; + } + i = 21; // index of last element in array of test's samples + for (std::list<StringSample>::iterator it = samples_string.begin(); it != samples_string.end(); ++it) { + EXPECT_EQ((*it).first, string_samples[i]); + --i; + } + +} + +// Checks whether setting age limits works properly +TEST_F(ObservationTest, setAgeLimit) { + // Set max_sample_age to 1 second + ASSERT_NO_THROW(c.setMaxSampleAge(seconds(1))); + // Add some value + c.setValue(milliseconds(5)); + // Wait 1 second + sleep(1); + // and add new value + c.setValue(milliseconds(3)); + + // get the list of all samples + std::list<DurationSample> samples_duration = c.getDurations(); + // check whether the size of samples is equal to 1 + ASSERT_EQ(c.getSize(), 1); + // and whether it contains an expected value + EXPECT_EQ((*samples_duration.begin()).first, milliseconds(3)); + + // Wait 1 second to ensure removing previously set value + sleep(1); + // add 10 new values + for (uint32_t i = 0; i < 10; ++i) { + c.setValue(milliseconds(i)); + } + // change the max_sample_age to smaller + ASSERT_NO_THROW(c.setMaxSampleAge(milliseconds(300))); + + samples_duration = c.getDurations(); + // check whether the size of samples is equal to 10 + ASSERT_EQ(c.getSize(), 10); + + // and whether it contains expected values + uint32_t i = 9; + for (std::list<DurationSample>::iterator it = samples_duration.begin(); it != samples_duration.end(); ++it) { + EXPECT_EQ((*it).first, milliseconds(i)); + --i; + } +} + +// Test checks whether we can get max_sample_age_ and max_sample_count_ +// properly. +TEST_F(ObservationTest, getLimits) { + // First checks whether getting default values works properly + EXPECT_EQ(a.getMaxSampleAge().first, false); + EXPECT_EQ(b.getMaxSampleAge().first, false); + EXPECT_EQ(c.getMaxSampleAge().first, false); + EXPECT_EQ(d.getMaxSampleAge().first, false); + + EXPECT_EQ(a.getMaxSampleCount().first, true); + EXPECT_EQ(b.getMaxSampleCount().first, true); + EXPECT_EQ(c.getMaxSampleCount().first, true); + EXPECT_EQ(d.getMaxSampleCount().first, true); + + EXPECT_EQ(a.getMaxSampleCount().second, 20); + EXPECT_EQ(b.getMaxSampleCount().second, 20); + EXPECT_EQ(c.getMaxSampleCount().second, 20); + EXPECT_EQ(d.getMaxSampleCount().second, 20); + + // change limit to time duration + ASSERT_NO_THROW(a.setMaxSampleAge(dur453)); + ASSERT_NO_THROW(b.setMaxSampleAge(dur453)); + ASSERT_NO_THROW(c.setMaxSampleAge(dur453)); + ASSERT_NO_THROW(d.setMaxSampleAge(dur453)); + + EXPECT_EQ(a.getMaxSampleAge().first, true); + EXPECT_EQ(b.getMaxSampleAge().first, true); + EXPECT_EQ(c.getMaxSampleAge().first, true); + EXPECT_EQ(d.getMaxSampleAge().first, true); + + EXPECT_EQ(a.getMaxSampleAge().second, dur453); + EXPECT_EQ(b.getMaxSampleAge().second, dur453); + EXPECT_EQ(c.getMaxSampleAge().second, dur453); + EXPECT_EQ(d.getMaxSampleAge().second, dur453); + + EXPECT_EQ(a.getMaxSampleCount().first, false); + EXPECT_EQ(b.getMaxSampleCount().first, false); + EXPECT_EQ(c.getMaxSampleCount().first, false); + EXPECT_EQ(d.getMaxSampleCount().first, false); + + EXPECT_EQ(a.getMaxSampleCount().second, 20); + EXPECT_EQ(b.getMaxSampleCount().second, 20); + EXPECT_EQ(c.getMaxSampleCount().second, 20); + EXPECT_EQ(d.getMaxSampleCount().second, 20); +} + +// limit defaults are tested with StatsMgr. + +// Test checks whether timing is reported properly. +TEST_F(ObservationTest, timers) { + auto before = SampleClock::now(); + b.setValue(123.0); // Set it to a random value and record the time. + + // Allow a bit of imprecision. This test allows 500ms. That should be ok, + // when running on virtual machines. + auto after = before + milliseconds(500); + + // Now wait some time. We want to confirm that the timestamp recorded is the + // time the observation took place, not current time. + sleep(1); + + FloatSample sample = b.getFloat(); + + // Let's check that the timestamp is within (before, after) range: + // before < sample-time < after + EXPECT_TRUE(before <= sample.second); + EXPECT_TRUE(sample.second <= after); +} + +// Checks whether an integer statistic can generate proper JSON structures. +// See https://gitlab.isc.org/isc-projects/kea/wikis/designs/Stats-design +/// for details. +TEST_F(ObservationTest, integerToJSON) { + // String which contains first added sample + std::string first_sample = ", [ 1234, \"" + + isc::util::clockToText(a.getInteger().second) + "\" ] ]"; + + a.setValue(static_cast<int64_t>(1234)); + + std::string exp = "[ [ 1234, \"" + + isc::util::clockToText(a.getInteger().second) + "\" ]" + first_sample; + + std::cout << a.getJSON()->str() << std::endl; + EXPECT_EQ(exp, a.getJSON()->str()); +} + +// Checks whether a floating point statistic can generate proper JSON +// structures. See +/// https://gitlab.isc.org/isc-projects/kea/wikis/designs/Stats-design +/// for details. +TEST_F(ObservationTest, floatToJSON) { + // String which contains first added sample + std::string first_sample = ", [ 12.34, \"" + + isc::util::clockToText(b.getFloat().second) + "\" ] ]"; + + // Let's use a value that converts easily to floating point. + // No need to deal with infinite fractions in binary systems. + + b.setValue(1234.5); + + std::string exp = "[ [ 1234.5, \"" + + isc::util::clockToText(b.getFloat().second) + "\" ]" + first_sample; + + std::cout << b.getJSON()->str() << std::endl; + EXPECT_EQ(exp, b.getJSON()->str()); +} + +// Checks whether a time duration statistic can generate proper JSON structures. +// See https://gitlab.isc.org/isc-projects/kea/wikis/designs/Stats-design for +// details. +TEST_F(ObservationTest, durationToJSON) { + // String which contains first added sample + std::string first_sample = ", [ \"01:02:03.004000\", \"" + + isc::util::clockToText(c.getDuration().second) + "\" ] ]"; + + // 1 hour 2 minutes 3 seconds and 4 milliseconds + c.setValue(dur1234); + + std::string exp = "[ [ \"01:02:03.004000\", \"" + + isc::util::clockToText(c.getDuration().second) + "\" ]" + first_sample; + + std::cout << c.getJSON()->str() << std::endl; + EXPECT_EQ(exp, c.getJSON()->str()); +} + +// Checks whether a string statistic can generate proper JSON structures. +// See https://gitlab.isc.org/isc-projects/kea/wikis/designs/Stats-design +// for details. +TEST_F(ObservationTest, stringToJSON) { + // String which contains first added sample + std::string first_sample = ", [ \"1234\", \"" + + isc::util::clockToText(d.getString().second) + "\" ] ]"; + + d.setValue("Lorem ipsum dolor sit amet"); + + std::string exp = "[ [ \"Lorem ipsum dolor sit amet\", \"" + + isc::util::clockToText(d.getString().second) + "\" ]" + first_sample; + + std::cout << d.getJSON()->str() << std::endl; + EXPECT_EQ(exp, d.getJSON()->str()); +} + +// Checks whether reset() resets the statistics properly. +TEST_F(ObservationTest, reset) { + EXPECT_NO_THROW(a.addValue(static_cast<int64_t>(5678))); + EXPECT_NO_THROW(b.addValue(56.78)); + EXPECT_NO_THROW(c.addValue(dur5678)); + EXPECT_NO_THROW(d.addValue("fiveSixSevenEight")); + + a.reset(); // integer + b.reset(); // float + c.reset(); // duration + d.reset(); // string + + EXPECT_EQ(0, a.getInteger().first); + EXPECT_EQ(0.0, b.getFloat().first); + EXPECT_EQ(StatsDuration::zero(), c.getDuration().first); + EXPECT_EQ("", d.getString().first); + + ASSERT_EQ(a.getSize(), 1); + ASSERT_EQ(b.getSize(), 1); + ASSERT_EQ(c.getSize(), 1); + ASSERT_EQ(d.getSize(), 1); +} + +// Checks whether an observation can keep its name. +TEST_F(ObservationTest, names) { + EXPECT_EQ("alpha", a.getName()); + EXPECT_EQ("beta", b.getName()); + EXPECT_EQ("gamma", c.getName()); + EXPECT_EQ("delta", d.getName()); +} + +} diff --git a/src/lib/stats/tests/run_unittests.cc b/src/lib/stats/tests/run_unittests.cc new file mode 100644 index 0000000..9d621ae --- /dev/null +++ b/src/lib/stats/tests/run_unittests.cc @@ -0,0 +1,18 @@ +// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// +// 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 <config.h> + +#include <gtest/gtest.h> + +int +main(int argc, char* argv[]) { + ::testing::InitGoogleTest(&argc, argv); + + int result = RUN_ALL_TESTS(); + + return (result); +} diff --git a/src/lib/stats/tests/stats_mgr_unittest.cc b/src/lib/stats/tests/stats_mgr_unittest.cc new file mode 100644 index 0000000..734d134 --- /dev/null +++ b/src/lib/stats/tests/stats_mgr_unittest.cc @@ -0,0 +1,1117 @@ +// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") +// +// 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 <config.h> + +#include <stats/stats_mgr.h> +#include <exceptions/exceptions.h> +#include <cc/data.h> +#include <cc/command_interpreter.h> +#include <util/chrono_time_utils.h> +#include <boost/shared_ptr.hpp> +#include <gtest/gtest.h> + +#include <iostream> +#include <sstream> + +using namespace isc; +using namespace isc::data; +using namespace isc::stats; +using namespace isc::config; +using namespace std::chrono; + +namespace { + +static const StatsDuration& dur1234(hours(1) + minutes(2) + seconds(3) + + milliseconds(4)); +static const StatsDuration& dur5678(hours(5) + minutes(6) + seconds(7) + + milliseconds(8)); +static const StatsDuration& dur1245(hours(1) + minutes(2) + seconds(45)); + +/// @brief Fixture class for StatsMgr testing +/// +/// Very simple class that makes sure that StatsMgr is indeed instantiated +/// before the test and any statistics are wiped out after it. +class StatsMgrTest : public ::testing::Test { +public: + /// @brief Constructor + /// Makes sure that the Statistics Manager is instantiated. + StatsMgrTest() { + StatsMgr::instance(); + StatsMgr::instance().removeAll(); + } + + /// @brief Destructor + /// Removes all statistics and restores class defaults. + ~StatsMgrTest() { + StatsMgr::instance().removeAll(); + StatsMgr::instance().setMaxSampleAgeDefault(StatsDuration::zero()); + StatsMgr::instance().setMaxSampleCountDefault(20); + } +}; + +// Basic test for statistics manager interface. +TEST_F(StatsMgrTest, basic) { + // Getting an instance + EXPECT_NO_THROW(StatsMgr::instance()); + + // Check that there are no statistics recorded by default. + EXPECT_EQ(0, StatsMgr::instance().count()); +} + +// Test checks whether it's possible to record and later report +// an integer statistic. +TEST_F(StatsMgrTest, integerStat) { + EXPECT_NO_THROW(StatsMgr::instance().setValue("alpha", + static_cast<int64_t>(1234))); + + ObservationPtr alpha; + EXPECT_NO_THROW(alpha = StatsMgr::instance().getObservation("alpha")); + ASSERT_TRUE(alpha); + + std::string exp = "{ \"alpha\": [ [ 1234, \"" + + isc::util::clockToText(alpha->getInteger().second) + "\" ] ] }"; + + EXPECT_EQ(exp, StatsMgr::instance().get("alpha")->str()); +} + +// Test checks whether it's possible to record and later report +// a floating point statistic. +TEST_F(StatsMgrTest, floatStat) { + EXPECT_NO_THROW(StatsMgr::instance().setValue("beta", 12.34)); + + ObservationPtr beta; + EXPECT_NO_THROW(beta = StatsMgr::instance().getObservation("beta")); + ASSERT_TRUE(beta); + + std::string exp = "{ \"beta\": [ [ 12.34, \"" + + isc::util::clockToText(beta->getFloat().second) + "\" ] ] }"; + + EXPECT_EQ(exp, StatsMgr::instance().get("beta")->str()); +} + +// Test checks whether it's possible to record and later report +// a duration statistic. +TEST_F(StatsMgrTest, durationStat) { + EXPECT_NO_THROW(StatsMgr::instance().setValue("gamma", dur1234)); + + ObservationPtr gamma; + EXPECT_NO_THROW(gamma = StatsMgr::instance().getObservation("gamma")); + ASSERT_TRUE(gamma); + + std::string exp = "{ \"gamma\": [ [ \"01:02:03.004000\", \"" + + isc::util::clockToText(gamma->getDuration().second) + "\" ] ] }"; + + EXPECT_EQ(exp, StatsMgr::instance().get("gamma")->str()); +} + +// Test checks whether it's possible to record and later report +// a string statistic. +TEST_F(StatsMgrTest, stringStat) { + EXPECT_NO_THROW(StatsMgr::instance().setValue("delta", + "Lorem ipsum")); + + ObservationPtr delta; + EXPECT_NO_THROW(delta = StatsMgr::instance().getObservation("delta")); + ASSERT_TRUE(delta); + + std::string exp = "{ \"delta\": [ [ \"Lorem ipsum\", \"" + + isc::util::clockToText(delta->getString().second) + "\" ] ] }"; + + EXPECT_EQ(exp, StatsMgr::instance().get("delta")->str()); +} + +// Basic test of getSize function. +TEST_F(StatsMgrTest, getSize) { + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + EXPECT_NO_THROW(StatsMgr::instance().getSize("alpha")); + EXPECT_NO_THROW(StatsMgr::instance().getSize("beta")); + EXPECT_NO_THROW(StatsMgr::instance().getSize("gamma")); + EXPECT_NO_THROW(StatsMgr::instance().getSize("delta")); + + EXPECT_EQ(StatsMgr::instance().getSize("alpha"), 1); + EXPECT_EQ(StatsMgr::instance().getSize("beta"), 1); + EXPECT_EQ(StatsMgr::instance().getSize("gamma"), 1); + EXPECT_EQ(StatsMgr::instance().getSize("delta"), 1); +} + +// Test checks whether setting age limit and count limit works properly. +TEST_F(StatsMgrTest, setLimits) { + // Initializing of an integer type observation + StatsMgr::instance().setValue("foo", static_cast<int64_t>(1)); + + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAge("foo", + seconds(1))); + + for (uint32_t i = 0; i < 10; ++i) { + if (i == 5) { + sleep(1); // wait one second to force exceeding the time limit + } + StatsMgr::instance().setValue("foo", static_cast<int64_t>(i)); + } + + EXPECT_EQ(StatsMgr::instance().getSize("foo"), 5); + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCount("foo", 100)); + + for (int64_t i = 0; i < 200; ++i) { + StatsMgr::instance().setValue("foo", i); + } + + EXPECT_EQ(StatsMgr::instance().getSize("foo"), 100); +} + +// Test checks whether setting age limit and count limit to existing +// statistics works properly. +TEST_F(StatsMgrTest, setLimitsAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // check the setting of time limit to existing statistics + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAgeAll(seconds(1))); + + // check if time limit was set properly and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, + seconds(1)); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, + seconds(1)); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, + seconds(1)); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, + seconds(1)); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); + + // check the setting of count limit to existing statistics + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountAll(1200)); + + // check if count limit was set properly and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 1200); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 1200); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 1200); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 1200); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); +} + +// Test checks whether setting default age limit and count limit works +// properly. +TEST_F(StatsMgrTest, setLimitsDefault) { + ASSERT_EQ(StatsMgr::instance().getMaxSampleCountDefault(), 20); + ASSERT_EQ(StatsMgr::instance().getMaxSampleAgeDefault(), StatsDuration::zero()); + + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", seconds(1234)); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // check what default applied + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, StatsDuration::zero()); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, StatsDuration::zero()); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, StatsDuration::zero()); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, StatsDuration::zero()); + + // Retry with another default count limits. + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountDefault(10)); + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAgeDefault(seconds(5))); + ASSERT_EQ(StatsMgr::instance().getMaxSampleCountDefault(), 10); + ASSERT_EQ(StatsMgr::instance().getMaxSampleAgeDefault(), seconds(5)); + + // Check the existing statistics were not updated. + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, StatsDuration::zero()); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, StatsDuration::zero()); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, StatsDuration::zero()); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 20); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, StatsDuration::zero()); + + // Remove all test statistics. + EXPECT_NO_THROW(StatsMgr::instance().removeAll()); + + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", seconds(1234)); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, seconds(5)); + + // Retry with count limit disable. + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountDefault(0)); + ASSERT_EQ(StatsMgr::instance().getMaxSampleCountDefault(), 0); + + // Check the existing statistics were not updated. + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, seconds(5)); + + // Remove all test statistics. + EXPECT_NO_THROW(StatsMgr::instance().removeAll()); + + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", seconds(1234)); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, seconds(5)); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 10); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, seconds(5)); + + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleCountDefault(20)); + EXPECT_NO_THROW(StatsMgr::instance().setMaxSampleAgeDefault(StatsDuration::zero())); +} + +// This test checks whether a single (get("foo")) and all (getAll()) +// statistics are reported properly. +TEST_F(StatsMgrTest, getGetAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem"); + + // The string's representation of firstly added statistics + std::string alpha_first = ", [ 1234, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("alpha") + ->getInteger().second) + "\" ] ]"; + std::string beta_first = ", [ 12.34, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("beta") + ->getFloat().second) + "\" ] ]"; + std::string gamma_first = ", [ \"01:02:03.004000\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("gamma") + ->getDuration().second) + "\" ] ]"; + std::string delta_first = ", [ \"Lorem\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("delta") + ->getString().second) + "\" ] ]"; + + // Now add some values to them + StatsMgr::instance().addValue("alpha", static_cast<int64_t>(5678)); + StatsMgr::instance().addValue("beta", 56.78); + StatsMgr::instance().addValue("gamma", dur5678); + StatsMgr::instance().addValue("delta", " ipsum"); + + // There should be 4 statistics reported + EXPECT_EQ(4, StatsMgr::instance().count()); + + // Now check whether they can be reported back + ConstElementPtr rep_alpha = StatsMgr::instance().get("alpha"); + ConstElementPtr rep_beta = StatsMgr::instance().get("beta"); + ConstElementPtr rep_gamma = StatsMgr::instance().get("gamma"); + ConstElementPtr rep_delta = StatsMgr::instance().get("delta"); + + ASSERT_TRUE(rep_alpha); + ASSERT_TRUE(rep_beta); + ASSERT_TRUE(rep_gamma); + ASSERT_TRUE(rep_delta); + + std::string exp_str_alpha = "[ [ 6912, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("alpha") + ->getInteger().second) + "\" ]" + alpha_first; + std::string exp_str_beta = "[ [ 69.12, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("beta") + ->getFloat().second) + "\" ]" + beta_first; + std::string exp_str_gamma = "[ [ \"06:08:10.012000\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("gamma") + ->getDuration().second) + "\" ]" + gamma_first; + std::string exp_str_delta = "[ [ \"Lorem ipsum\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("delta") + ->getString().second) + "\" ]" + delta_first; + + // Check that individual stats are reported properly + EXPECT_EQ("{ \"alpha\": " + exp_str_alpha + " }", rep_alpha->str()); + EXPECT_EQ("{ \"beta\": " + exp_str_beta + " }", rep_beta->str()); + EXPECT_EQ("{ \"gamma\": " + exp_str_gamma + " }", rep_gamma->str()); + EXPECT_EQ("{ \"delta\": " + exp_str_delta + " }", rep_delta->str()); + + // Check that non-existent metric is not reported. + EXPECT_EQ("{ }", StatsMgr::instance().get("epsilon")->str()); + + // Check that all of them can be reported at once + ConstElementPtr rep_all = StatsMgr::instance().getAll(); + ASSERT_TRUE(rep_all); + + // Verifying this is a bit more involved, as we don't know whether the + // order would be preserved or not. + EXPECT_EQ(4, rep_all->size()); + ASSERT_TRUE(rep_all->get("alpha")); + ASSERT_TRUE(rep_all->get("beta")); + ASSERT_TRUE(rep_all->get("delta")); + ASSERT_TRUE(rep_all->get("gamma")); + EXPECT_FALSE(rep_all->get("epsilon")); + + EXPECT_EQ(exp_str_alpha, rep_all->get("alpha")->str()); + EXPECT_EQ(exp_str_beta, rep_all->get("beta")->str()); + EXPECT_EQ(exp_str_gamma, rep_all->get("gamma")->str()); + EXPECT_EQ(exp_str_delta, rep_all->get("delta")->str()); +} + +// This test checks whether existing statistics can be reset. +TEST_F(StatsMgrTest, reset) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // This should reset alpha to 0 + EXPECT_NO_THROW(StatsMgr::instance().reset("alpha")); + EXPECT_EQ(0, + StatsMgr::instance().getObservation("alpha")->getInteger().first); + + // The other stats should remain untouched + EXPECT_EQ(12.34, + StatsMgr::instance().getObservation("beta")->getFloat().first); + EXPECT_EQ(dur1234, + StatsMgr::instance().getObservation("gamma")->getDuration().first); + EXPECT_EQ("Lorem ipsum", + StatsMgr::instance().getObservation("delta")->getString().first); + + // Now let's wipe them, too. + EXPECT_NO_THROW(StatsMgr::instance().reset("beta")); + EXPECT_NO_THROW(StatsMgr::instance().reset("gamma")); + EXPECT_NO_THROW(StatsMgr::instance().reset("delta")); + EXPECT_EQ(0.0, + StatsMgr::instance().getObservation("beta")->getFloat().first); + EXPECT_EQ(StatsDuration::zero(), + StatsMgr::instance().getObservation("gamma")->getDuration().first); + EXPECT_EQ("", + StatsMgr::instance().getObservation("delta")->getString().first); + + // Resetting statistics should not remove them + EXPECT_EQ(4, StatsMgr::instance().count()); +} + +// This test checks whether existing statistics can be reset. +TEST_F(StatsMgrTest, resetAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // This should reset alpha to 0 + EXPECT_NO_THROW(StatsMgr::instance().resetAll()); + EXPECT_EQ(0, + StatsMgr::instance().getObservation("alpha")->getInteger().first); + EXPECT_EQ(0.0, + StatsMgr::instance().getObservation("beta")->getFloat().first); + EXPECT_EQ(StatsDuration::zero(), + StatsMgr::instance().getObservation("gamma")->getDuration().first); + EXPECT_EQ("", + StatsMgr::instance().getObservation("delta")->getString().first); + + // Resetting all statistics should not remove them + EXPECT_EQ(4, StatsMgr::instance().count()); +} + +// This test checks whether statistics can be removed. +TEST_F(StatsMgrTest, removeAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // This should reset alpha to 0 + EXPECT_NO_THROW(StatsMgr::instance().removeAll()); + + // Resetting all statistics should not remove them + EXPECT_EQ(0, StatsMgr::instance().count()); + + // There should be no such statistics anymore + EXPECT_EQ("{ }", StatsMgr::instance().get("alpha")->str()); + EXPECT_EQ("{ }", StatsMgr::instance().get("beta")->str()); + EXPECT_EQ("{ }", StatsMgr::instance().get("gamma")->str()); + EXPECT_EQ("{ }", StatsMgr::instance().get("delta")->str()); + + // There should be no such statistics anymore + EXPECT_FALSE(StatsMgr::instance().getObservation("alpha")); + EXPECT_FALSE(StatsMgr::instance().getObservation("beta")); + EXPECT_FALSE(StatsMgr::instance().getObservation("gamma")); + EXPECT_FALSE(StatsMgr::instance().getObservation("delta")); +} + +// This is a performance benchmark that checks how long does it take +// to increment a single statistic million times. +// +// Data points: +// It took 00:00:00.363709 (363ms) on late 2013 Mac with Mac OS X 10.9.5. +TEST_F(StatsMgrTest, DISABLED_performanceSingleAdd) { + StatsMgr::instance().removeAll(); + + uint32_t cycles = 1000000; + + auto before = SampleClock::now(); + for (uint32_t i = 0; i < cycles; ++i) { + StatsMgr::instance().addValue("metric1", 0.1 * i); + } + auto after = SampleClock::now(); + + auto dur = after - before; + + std::cout << "Incrementing a single statistic " << cycles << " times took: " + << isc::util::durationToText(dur) << std::endl; +} + +// This is a performance benchmark that checks how long does it take +// to set absolute value of a single statistic million times. +// +// Data points: +// It took 00:00:00.361003 (361ms) on late 2013 Mac with Mac OS X 10.9.5. +TEST_F(StatsMgrTest, DISABLED_performanceSingleSet) { + StatsMgr::instance().removeAll(); + + uint32_t cycles = 1000000; + + auto before = SampleClock::now(); + for (uint32_t i = 0; i < cycles; ++i) { + StatsMgr::instance().setValue("metric1", 0.1 * i); + } + auto after = SampleClock::now(); + + auto dur = after - before; + + std::cout << "Setting a single statistic " << cycles << " times took: " + << isc::util::durationToText(dur) << std::endl; +} + +// This is a performance benchmark that checks how long does it take to +// increment one statistic a million times, when there is 1000 other statistics +// present. +// +// Data points: +// 00:00:00.436943 (436ms) on late 2013 Mac with Mac OS X 10.9.5 +TEST_F(StatsMgrTest, DISABLED_performanceMultipleAdd) { + StatsMgr::instance().removeAll(); + + uint32_t cycles = 1000000; + uint32_t stats = 1000; + + for (uint32_t i = 0; i < stats; ++i) { + std::stringstream tmp; + tmp << "statistic" << i; + StatsMgr::instance().setValue(tmp.str(), static_cast<int64_t>(i)); + } + + auto before = SampleClock::now(); + for (uint32_t i = 0; i < cycles; ++i) { + StatsMgr::instance().addValue("metric1", static_cast<int64_t>(i)); + } + auto after = SampleClock::now(); + + auto dur = after - before; + + std::cout << "Incrementing one of " << stats << " statistics " << cycles + << " times took: " << isc::util::durationToText(dur) << std::endl; +} + +// This is a performance benchmark that checks how long does it take to +// set one statistic to a given value a million times, when there is 1000 other +// statistics present. +// +// Data points: +// 00:00:00.424518 (424ms) on late 2013 Mac with Mac OS X 10.9.5 +TEST_F(StatsMgrTest, DISABLED_performanceMultipleSet) { + StatsMgr::instance().removeAll(); + + uint32_t cycles = 1000000; + uint32_t stats = 1000; + + for (uint32_t i = 0; i < stats; ++i) { + std::stringstream tmp; + tmp << "statistic" << i; + StatsMgr::instance().setValue(tmp.str(), static_cast<int64_t>(i)); + } + + auto before = SampleClock::now(); + for (uint32_t i = 0; i < cycles; ++i) { + StatsMgr::instance().setValue("metric1", static_cast<int64_t>(i)); + } + auto after = SampleClock::now(); + + auto dur = after - before; + + std::cout << "Setting one of " << stats << " statistics " << cycles + << " times took: " << isc::util::durationToText(dur) << std::endl; +} + +// Test checks whether statistics name can be generated using various +// indexes. +TEST_F(StatsMgrTest, generateName) { + // generateName is a templated method, so in principle anything printable + // to stream can be used as index. However, in practice only integers + // and possibly strings will be used. + + // Let's text integer as index. + EXPECT_EQ("subnet[123].pkt4-received", + StatsMgr::generateName("subnet", 123, "pkt4-received")); + + // Lets' test string as index. + EXPECT_EQ("subnet[foo].pkt4-received", + StatsMgr::generateName("subnet", "foo", "pkt4-received")); +} + +// Test checks if statistic-get handler is able to return specified statistic. +TEST_F(StatsMgrTest, commandStatisticGet) { + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + + ConstElementPtr rsp = StatsMgr::instance().statisticGetHandler("statistic-get", + params); + + ObservationPtr alpha; + EXPECT_NO_THROW(alpha = StatsMgr::instance().getObservation("alpha")); + ASSERT_TRUE(alpha); + + std::string exp = "{ \"alpha\": [ [ 1234, \"" + + isc::util::clockToText(alpha->getInteger().second) + "\" ] ] }"; + + EXPECT_EQ("{ \"arguments\": " + exp + ", \"result\": 0 }", rsp->str()); +} + +// Test checks if statistic-get is able to handle: +// - a request without parameters +// - a request with missing statistic name +// - a request for non-existing statistic. +TEST_F(StatsMgrTest, commandStatisticGetNegative) { + // Case 1: a request without parameters + ConstElementPtr rsp = StatsMgr::instance().statisticGetHandler("statistic-get", + ElementPtr()); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 2: a request with missing statistic name + ElementPtr params = Element::createMap(); + rsp = StatsMgr::instance().statisticGetHandler("statistic-get", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 3: a request for non-existing statistic + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticGetHandler("statistic-get", params); + EXPECT_EQ("{ \"arguments\": { }, \"result\": 0 }", rsp->str()); +} + +// This test checks whether statistic-get-all command returns all statistics +// correctly. +TEST_F(StatsMgrTest, commandGetAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // Now get them. They're used to generate expected output + ConstElementPtr rep_alpha = StatsMgr::instance().get("alpha"); + ConstElementPtr rep_beta = StatsMgr::instance().get("beta"); + ConstElementPtr rep_gamma = StatsMgr::instance().get("gamma"); + ConstElementPtr rep_delta = StatsMgr::instance().get("delta"); + + ASSERT_TRUE(rep_alpha); + ASSERT_TRUE(rep_beta); + ASSERT_TRUE(rep_gamma); + ASSERT_TRUE(rep_delta); + + std::string exp_str_alpha = "[ [ 1234, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("alpha") + ->getInteger().second) + "\" ] ]"; + std::string exp_str_beta = "[ [ 12.34, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("beta") + ->getFloat().second) + "\" ] ]"; + std::string exp_str_gamma = "[ [ \"01:02:03.004000\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("gamma") + ->getDuration().second) + "\" ] ]"; + std::string exp_str_delta = "[ [ \"Lorem ipsum\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("delta") + ->getString().second) + "\" ] ]"; + + // Check that all of them can be reported at once + ConstElementPtr rsp = StatsMgr::instance().statisticGetAllHandler( + "statistic-get-all", ElementPtr()); + ASSERT_TRUE(rsp); + int status_code; + ConstElementPtr rep_all = parseAnswer(status_code, rsp); + ASSERT_EQ(0, status_code); + ASSERT_TRUE(rep_all); + + // Verifying this is a bit more involved, as we don't know whether the + // order would be preserved or not. + EXPECT_EQ(4, rep_all->size()); + ASSERT_TRUE(rep_all->get("alpha")); + ASSERT_TRUE(rep_all->get("beta")); + ASSERT_TRUE(rep_all->get("delta")); + ASSERT_TRUE(rep_all->get("gamma")); + EXPECT_FALSE(rep_all->get("epsilon")); + + EXPECT_EQ(exp_str_alpha, rep_all->get("alpha")->str()); + EXPECT_EQ(exp_str_beta, rep_all->get("beta")->str()); + EXPECT_EQ(exp_str_gamma, rep_all->get("gamma")->str()); + EXPECT_EQ(exp_str_delta, rep_all->get("delta")->str()); +} + +// Test checks if statistic-reset handler is able to reset specified statistic. +TEST_F(StatsMgrTest, commandStatisticReset) { + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + + ConstElementPtr rsp = + StatsMgr::instance().statisticResetHandler("statistic-reset", params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + ObservationPtr alpha; + EXPECT_NO_THROW(alpha = StatsMgr::instance().getObservation("alpha")); + ASSERT_TRUE(alpha); + + // Check that it was indeed reset + EXPECT_EQ(0, alpha->getInteger().first); +} + +// Test checks if statistic-reset is able to handle: +// - a request without parameters +// - a request with missing statistic name +// - a request for non-existing statistic. +TEST_F(StatsMgrTest, commandStatisticResetNegative) { + // Case 1: a request without parameters + ConstElementPtr rsp = + StatsMgr::instance().statisticResetHandler("statistic-reset", ElementPtr()); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 2: a request with missing statistic name + ElementPtr params = Element::createMap(); + rsp = StatsMgr::instance().statisticResetHandler("statistic-reset", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 3: a request for non-existing statistic + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticResetHandler("statistic-reset", params); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }", + rsp->str()); +} + +// This test checks whether statistic-reset-all command really resets all +// statistics correctly. +TEST_F(StatsMgrTest, commandResetAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // Now get them. They're used to generate expected output + ConstElementPtr rep_alpha = StatsMgr::instance().get("alpha"); + ConstElementPtr rep_beta = StatsMgr::instance().get("beta"); + ConstElementPtr rep_gamma = StatsMgr::instance().get("gamma"); + ConstElementPtr rep_delta = StatsMgr::instance().get("delta"); + + ASSERT_TRUE(rep_alpha); + ASSERT_TRUE(rep_beta); + ASSERT_TRUE(rep_gamma); + ASSERT_TRUE(rep_delta); + + std::string exp_str_alpha = "[ [ 1234, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("alpha") + ->getInteger().second) + "\" ] ]"; + std::string exp_str_beta = "[ [ 12.34, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("beta") + ->getFloat().second) + "\" ] ]"; + std::string exp_str_gamma = "[ [ \"01:02:03.004000\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("gamma") + ->getDuration().second) + "\" ] ]"; + std::string exp_str_delta = "[ [ \"Lorem ipsum\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("delta") + ->getString().second) + "\" ] ]"; + + // Check that all of them can be reset at once + ConstElementPtr rsp = StatsMgr::instance().statisticResetAllHandler( + "statistic-reset-all", ElementPtr()); + ASSERT_TRUE(rsp); + int status_code; + ConstElementPtr rep_all = parseAnswer(status_code, rsp); + ASSERT_EQ(0, status_code); + ASSERT_TRUE(rep_all); + + // Check that they're indeed reset + EXPECT_EQ(0, + StatsMgr::instance().getObservation("alpha")->getInteger().first); + EXPECT_EQ(0.0f, + StatsMgr::instance().getObservation("beta")->getFloat().first); + EXPECT_EQ(StatsDuration::zero(), + StatsMgr::instance().getObservation("gamma")->getDuration().first); + EXPECT_EQ("", + StatsMgr::instance().getObservation("delta")->getString().first); +} + +// Test checks if statistic-remove handler is able to remove a statistic. +TEST_F(StatsMgrTest, commandStatisticRemove) { + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + + ConstElementPtr rsp = + StatsMgr::instance().statisticRemoveHandler("statistic-remove", params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + // It should be gone. + EXPECT_FALSE(StatsMgr::instance().getObservation("alpha")); + EXPECT_EQ(0, StatsMgr::instance().count()); +} + +// Test checks if statistic-remove is able to handle: +// - a request without parameters +// - a request with missing statistic name +// - a request for non-existing statistic. +TEST_F(StatsMgrTest, commandStatisticRemoveNegative) { + // Case 1: a request without parameters + ConstElementPtr rsp = + StatsMgr::instance().statisticRemoveHandler("statistic-remove", ElementPtr()); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 2: a request with missing statistic name + ElementPtr params = Element::createMap(); + rsp = StatsMgr::instance().statisticRemoveHandler("statistic-remove", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 3: a request for non-existing statistic + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticRemoveHandler("statistic-remove", params); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }", + rsp->str()); +} + +// This test checks whether statistic-remove-all command really resets all +// statistics correctly. +TEST_F(StatsMgrTest, commandRemoveAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + // Check that all of them can be reset at once + ConstElementPtr rsp = StatsMgr::instance().statisticRemoveAllHandler( + "statistic-remove-all", ElementPtr()); + ASSERT_TRUE(rsp); + int status_code; + ConstElementPtr rep_all = parseAnswer(status_code, rsp); + ASSERT_EQ(0, status_code); + ASSERT_TRUE(rep_all); + std::string exp = "\"Warning: statistic-remove-all command is deprecated."; + exp += " All statistics removed.\""; + EXPECT_EQ(exp, rep_all->str()); + + EXPECT_FALSE(StatsMgr::instance().getObservation("alpha")); + EXPECT_FALSE(StatsMgr::instance().getObservation("beta")); + EXPECT_FALSE(StatsMgr::instance().getObservation("gamma")); + EXPECT_FALSE(StatsMgr::instance().getObservation("delta")); + EXPECT_EQ(0, StatsMgr::instance().count()); +} + +// This test checks whether statistic-sample-age-set command really set +// max_sample_age_ limit correctly. +TEST_F(StatsMgrTest, commandSetMaxSampleAge) { + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + params->set("duration", Element::create(1245)); // minutes(20) + seconds(45) + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + // check if time limit was set properly and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, + minutes(20) + seconds(45)); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); +} + +// Test checks if statistic-sample-age-set is able to handle: +// - a request without parameters +// - a request without duration parameter +// - a request with missing statistic name +// - a request for non-existing statistic. +TEST_F(StatsMgrTest, commandSetMaxSampleAgeNegative) { + // Case 1: a request without parameters + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", ElementPtr()); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 2: a request without duration parameter + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 3: a request with missing statistic name + params = Element::createMap(); + params->set("duration", Element::create(100)); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 4: a request for non-existing statistic + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticSetMaxSampleAgeHandler("statistic-sample-age-set", params); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }", + rsp->str()); +} + +TEST_F(StatsMgrTest, commandSetMaxSampleAgeAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + ElementPtr params = Element::createMap(); + params->set("duration", Element::create(3765)); // set duration to 3765 seconds + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleAgeAllHandler(params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + // check defaults + EXPECT_EQ(StatsMgr::instance().getMaxSampleAgeDefault(), seconds(3765)); + EXPECT_EQ(StatsMgr::instance().getMaxSampleCountDefault(), 0); + + // check if time limit was set properly and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().second, + dur1245); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().second, + dur1245); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().second, + dur1245); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().second, + dur1245); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, false); +} + +// This test checks whether statistic-sample-count-set command really set +// max_sample_count_ limit correctly. +TEST_F(StatsMgrTest, commandSetMaxSampleCount) { + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + params->set("max-samples", Element::create(15)); + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + // check if time limit was set properly and whether duration limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 15); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); +} + +// Test checks if statistic-sample-count-set is able to handle: +// - a request without parameters +// - a request without max-samples parameter +// - a request with missing statistic name +// - a request for non-existing statistic. +TEST_F(StatsMgrTest, commandSetMaxSampleCountNegative) { + // Case 1: a request without parameters + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", ElementPtr()); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 2: a request without max-samples parameter + ElementPtr params = Element::createMap(); + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 3: a request with missing statistic name + params = Element::createMap(); + params->set("max-samples", Element::create(10)); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", params); + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); + + // Case 4: a request for non-existing statistic + params->set("name", Element::create("alpha")); + rsp = StatsMgr::instance().statisticSetMaxSampleCountHandler("statistic-sample-count-set", params); + EXPECT_EQ("{ \"result\": 1, \"text\": \"No 'alpha' statistic found\" }", + rsp->str()); +} + +TEST_F(StatsMgrTest, commandSetMaxSampleCountAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast<int64_t>(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + + ElementPtr params = Element::createMap(); + params->set("max-samples", Element::create(200)); + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleCountAllHandler(params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(CONTROL_RESULT_SUCCESS, status_code); + + // check default + EXPECT_EQ(StatsMgr::instance().getMaxSampleCountDefault(), 200); + + // check if count limit was set properly and whether count limit is disabled + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleCount().second, 200); + EXPECT_EQ(StatsMgr::instance().getObservation("alpha")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleCount().second, 200); + EXPECT_EQ(StatsMgr::instance().getObservation("beta")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleCount().second, 200); + EXPECT_EQ(StatsMgr::instance().getObservation("gamma")->getMaxSampleAge().first, false); + + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().first, true); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleCount().second, 200); + EXPECT_EQ(StatsMgr::instance().getObservation("delta")->getMaxSampleAge().first, false); +} + +// Test checks if statistics-sample-count-set-all fails on zero. +TEST_F(StatsMgrTest, commandSetMaxSampleCountAllZero) { + ElementPtr params = Element::createMap(); + params->set("max-samples", Element::create(0)); + + ConstElementPtr rsp = + StatsMgr::instance().statisticSetMaxSampleCountAllHandler(params); + int status_code; + ASSERT_NO_THROW(parseAnswer(status_code, rsp)); + EXPECT_EQ(status_code, CONTROL_RESULT_ERROR); +} + +} diff --git a/src/lib/stats/testutils/Makefile.am b/src/lib/stats/testutils/Makefile.am new file mode 100644 index 0000000..009257f --- /dev/null +++ b/src/lib/stats/testutils/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = stats_test_utils.h diff --git a/src/lib/stats/testutils/Makefile.in b/src/lib/stats/testutils/Makefile.in new file mode 100644 index 0000000..7470813 --- /dev/null +++ b/src/lib/stats/testutils/Makefile.in @@ -0,0 +1,524 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/lib/stats/testutils +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4macros/ax_boost_for_kea.m4 \ + $(top_srcdir)/m4macros/ax_cpp11.m4 \ + $(top_srcdir)/m4macros/ax_crypto.m4 \ + $(top_srcdir)/m4macros/ax_find_library.m4 \ + $(top_srcdir)/m4macros/ax_gssapi.m4 \ + $(top_srcdir)/m4macros/ax_gtest.m4 \ + $(top_srcdir)/m4macros/ax_isc_rpath.m4 \ + $(top_srcdir)/m4macros/ax_sysrepo.m4 \ + $(top_srcdir)/m4macros/libtool.m4 \ + $(top_srcdir)/m4macros/ltoptions.m4 \ + $(top_srcdir)/m4macros/ltsugar.m4 \ + $(top_srcdir)/m4macros/ltversion.m4 \ + $(top_srcdir)/m4macros/lt~obsolete.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__DIST_COMMON = $(srcdir)/Makefile.in +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +ASCIIDOC = @ASCIIDOC@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BOOST_INCLUDES = @BOOST_INCLUDES@ +BOOST_LIBS = @BOOST_LIBS@ +BOTAN_TOOL = @BOTAN_TOOL@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CONTRIB_DIR = @CONTRIB_DIR@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPTO_CFLAGS = @CRYPTO_CFLAGS@ +CRYPTO_INCLUDES = @CRYPTO_INCLUDES@ +CRYPTO_LDFLAGS = @CRYPTO_LDFLAGS@ +CRYPTO_LIBS = @CRYPTO_LIBS@ +CRYPTO_PACKAGE = @CRYPTO_PACKAGE@ +CRYPTO_RPATH = @CRYPTO_RPATH@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DISTCHECK_BOOST_CONFIGURE_FLAG = @DISTCHECK_BOOST_CONFIGURE_FLAG@ +DISTCHECK_CONTRIB_CONFIGURE_FLAG = @DISTCHECK_CONTRIB_CONFIGURE_FLAG@ +DISTCHECK_CRYPTO_CONFIGURE_FLAG = @DISTCHECK_CRYPTO_CONFIGURE_FLAG@ +DISTCHECK_GTEST_CONFIGURE_FLAG = @DISTCHECK_GTEST_CONFIGURE_FLAG@ +DISTCHECK_KEA_SHELL_CONFIGURE_FLAG = @DISTCHECK_KEA_SHELL_CONFIGURE_FLAG@ +DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG = @DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG@ +DISTCHECK_PERFDHCP_CONFIGURE_FLAG = @DISTCHECK_PERFDHCP_CONFIGURE_FLAG@ +DISTCHECK_PREMIUM_CONFIGURE_FLAG = @DISTCHECK_PREMIUM_CONFIGURE_FLAG@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GENHTML = @GENHTML@ +GREP = @GREP@ +GSSAPI_CFLAGS = @GSSAPI_CFLAGS@ +GSSAPI_LIBS = @GSSAPI_LIBS@ +GTEST_CONFIG = @GTEST_CONFIG@ +GTEST_INCLUDES = @GTEST_INCLUDES@ +GTEST_LDADD = @GTEST_LDADD@ +GTEST_LDFLAGS = @GTEST_LDFLAGS@ +GTEST_SOURCE = @GTEST_SOURCE@ +HAVE_SYSREPO = @HAVE_SYSREPO@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KEA_CXXFLAGS = @KEA_CXXFLAGS@ +KEA_SRCID = @KEA_SRCID@ +KRB5_CONFIG = @KRB5_CONFIG@ +LCOV = @LCOV@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LOG4CPLUS_INCLUDES = @LOG4CPLUS_INCLUDES@ +LOG4CPLUS_LIBS = @LOG4CPLUS_LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PACKAGE_VERSION_TYPE = @PACKAGE_VERSION_TYPE@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PDFLATEX = @PDFLATEX@ +PERL = @PERL@ +PGSQL_CPPFLAGS = @PGSQL_CPPFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PKGPYTHONDIR = @PKGPYTHONDIR@ +PKG_CONFIG = @PKG_CONFIG@ +PLANTUML = @PLANTUML@ +PREMIUM_DIR = @PREMIUM_DIR@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +RANLIB = @RANLIB@ +SED = @SED@ +SEP = @SEP@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SPHINXBUILD = @SPHINXBUILD@ +SRPD_PLUGINS_PATH = @SRPD_PLUGINS_PATH@ +SR_REPO_PATH = @SR_REPO_PATH@ +STRIP = @STRIP@ +SYSREPOCPP_VERSION = @SYSREPOCPP_VERSION@ +SYSREPO_CPPFLAGS = @SYSREPO_CPPFLAGS@ +SYSREPO_INCLUDEDIR = @SYSREPO_INCLUDEDIR@ +SYSREPO_LIBS = @SYSREPO_LIBS@ +SYSREPO_VERSION = @SYSREPO_VERSION@ +USE_LCOV = @USE_LCOV@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +WARNING_GCC_44_STRICT_ALIASING_CFLAG = @WARNING_GCC_44_STRICT_ALIASING_CFLAG@ +YACC = @YACC@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +EXTRA_DIST = stats_test_utils.h +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib/stats/testutils/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/lib/stats/testutils/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +tags TAGS: + +ctags CTAGS: + +cscope cscopelist: + + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic clean-libtool \ + cscopelist-am ctags-am distclean distclean-generic \ + distclean-libtool distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/lib/stats/testutils/stats_test_utils.h b/src/lib/stats/testutils/stats_test_utils.h new file mode 100644 index 0000000..808dced --- /dev/null +++ b/src/lib/stats/testutils/stats_test_utils.h @@ -0,0 +1,64 @@ +// Copyright (C) 2020-2021 Internet Systems Consortium, Inc. ("ISC") +// +// 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 STATS_TEST_UTILS_H +#define STATS_TEST_UTILS_H + +#include <cc/data.h> +#include <stats/stats_mgr.h> + +#include <gtest/gtest.h> + +namespace isc { +namespace stats { +namespace test { + +/// @brief Type of name x value for statistics. +typedef std::map<std::string, int64_t> StatMap; + +/// @brief Compares a statistic to an expected value. +/// +/// Attempt to fetch the named statistic from the StatsMgr and if +/// found, compare its observed value to the given value. +/// Fails if the stat is not found or if the values do not match. +/// +/// @param name StatsMgr name for the statistic to check. +/// @param expected_value expected value of the statistic. +inline void checkStat(const std::string& name, const int64_t expected_value) { + using namespace isc::stats; + ObservationPtr obs = StatsMgr::instance().getObservation(name); + ASSERT_TRUE(obs) << " stat: " << name << " not found "; + ASSERT_EQ(expected_value, obs->getInteger().first) + << " stat: " << name << " value wrong"; +} + +/// @brief Check if a statistic does not exists. +/// +/// @param name StatsMgr name for the statistic to check. +inline void checkNoStat(const std::string& name) { + using namespace isc::stats; + EXPECT_FALSE(StatsMgr::instance().getObservation(name)); +} + +/// @brief Compares StatsMgr statistics against expected values. +/// +/// Iterates over a list of statistic names and expected values, attempting +/// to fetch each from the StatsMgr and if found, compare its observed +/// value to the expected value. Fails if any of the expected stats are not +/// found or if the values do not match. +/// +/// @param expected_stats Map of expected static names and values. +inline void checkStats(const StatMap& expected_stats) { + for (const auto& it : expected_stats) { + checkStat(it.first, it.second); + } +} + +} +} +} + +#endif // STATS_TEST_UTILS_H |