bump default compiler for parallel mode to g++-4.4.x

git-svn-id: 4e7379b20b57f8e3dde5a0b7363f233184647162@1992 4e380d45-d1fd-0310-85a7-d18ec86df0ad

# This -*- Makefile -*- is intended for processing with GNU make.

############################################################################
#  make.settings.gnu
#
#  Part of the STXXL. See http://stxxl.sourceforge.net
#
#  Copyright (C) 2002-2007 Roman Dementiev <dementiev@mpi-sb.mpg.de>
#  Copyright (C) 2006-2008 Johannes Singler <singler@ira.uka.de>
#  Copyright (C) 2007-2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
#
#  Distributed under the Boost Software License, Version 1.0.
#  (See accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt)
############################################################################

TOPDIR	?= $(error TOPDIR not defined) # DO NOT CHANGE! This is set elsewhere.

# Change this file according to your paths.

# Instead of modifying this file, you could also set your modified variables
# in make.settings.local (needs to be created first).
-include $(TOPDIR)/make.settings.local

USE_BOOST	?= no	# set 'yes' to use Boost libraries or 'no' to not use Boost libraries
USE_MACOSX	?= no	# set 'yes' if you run Mac OS X, 'no' otherwise
USE_FREEBSD	?= no	# set 'yes' if you run FreeBSD, 'no' otherwise
USE_PMODE	?= no	# will be overridden from main Makefile
USE_MCSTL	?= no	# will be overridden from main Makefile
USE_ICPC	?= no	# will be overridden from main Makefile

STXXL_ROOT	?= $(TOPDIR)

ifeq ($(strip $(USE_ICPC)),yes)
COMPILER_ICPC	?= icpc
COMPILER	?= $(COMPILER_ICPC)
#ICPC_GCC	?= gcc-x.y    # override the gcc/g++ used to find headers and libraries
WARNINGS	?= -Wall -w1 -openmp-report0 -vec-report0
endif

ifeq ($(strip $(USE_PMODE)),yes)
COMPILER_GCC	?= g++-4.4.x
LIBNAME		?= pmstxxl
endif

ifeq ($(strip $(USE_MCSTL)),yes)
COMPILER_GCC	?= g++-4.2.3
LIBNAME		?= mcstxxl
# the root directory of your MCSTL installation
MCSTL_ROOT	?= $(HOME)/work/mcstl
endif

#BOOST_ROOT	?= /usr/local/boost-1.34.1

COMPILER_GCC	?= g++
COMPILER	?= $(COMPILER_GCC)
LINKER		?= $(COMPILER)
OPT_LEVEL	?= 3
OPT		?= -O$(OPT_LEVEL) # compiler optimization level
WARNINGS	?= -W -Wall -Woverloaded-virtual -Wundef
DEBUG		?= # put here -g option to include the debug information into the binaries

LIBNAME		?= stxxl

# Hint: for g++-4.3 with c++0x support, enable the following:
#STXXL_SPECIFIC	+= -std=c++0x

#### TROUBLESHOOTING
#
# For automatical checking of order of the output elements in
# the sorters: stxxl::stream::sort, stxxl::stream::merge_runs,
# stxxl::sort, and stxxl::ksort use
#
#STXXL_SPECIFIC	+= -DSTXXL_CHECK_ORDER_IN_SORTS
#
# If your program aborts with message "read/write: wrong parameter"
# or "Invalid argument"
# this could be that your kernel does not support direct I/O
# then try to set it off recompiling the libs and your code with option
#
#STXXL_SPECIFIC	+= -DSTXXL_DIRECT_IO_OFF
#
# But for the best performance it is strongly recommended
# to reconfigure the kernel for the support of the direct I/O.
#
# FIXME: documentation needed
#
#STXXL_SPECIFIC += -DSTXXL_DEBUGMON

#### You usually shouldn't need to change the sections below #####

#### MACOSX CONFIGURATION ########################################

ifeq ($(strip $(USE_MACOSX)),yes)

PTHREAD_FLAG	?=

GET_FILE_ID	?= stat -L -f '%d:%i' $1

endif

##################################################################

#### FREEBSD CONFIGURATION #######################################

ifeq ($(strip $(USE_FREEBSD)),yes)

PTHREAD_FLAG	?= -pthread

GET_FILE_ID	?= stat -L -f '%d:%i' $1

endif

##################################################################

#### LINUX (DEFAULT) CONFIGURATION ###############################

PTHREAD_FLAG	?= -pthread

# get a unique identifier for a file or directory,
# e.g. device number + inode number
GET_FILE_ID	?= stat -L -c '%d:%i' $1

##################################################################

#### STXXL CONFIGURATION #########################################

# create make.settings.local in the root directory
ifneq (,$(strip $(wildcard $(CURDIR)/include/stxxl.h)))
ifeq (,$(strip $(wildcard $(CURDIR)/make.settings.local)))
ifeq (,$(STXXL_AUTOCONFIG))
$(warning *** WARNING: you did not have a make.settings.local file -- creating ...)
endif
$(shell echo -e '\043STXXL_ROOT	 = $(CURDIR:$(HOME)%=$$(HOME)%)' >> $(CURDIR)/make.settings.local)
MCSTL_ROOT	?= $(HOME)/work/mcstl
$(shell echo -e '\043MCSTL_ROOT	 = $(MCSTL_ROOT:$(HOME)%=$$(HOME)%)' >> $(CURDIR)/make.settings.local)
$(shell echo -e '\043COMPILER_GCC	 = g++-4.2' >> $(CURDIR)/make.settings.local)
$(shell echo -e '\043COMPILER_GCC	 = g++-4.3 -std=c++0x' >> $(CURDIR)/make.settings.local)
$(shell echo -e '\043COMPILER_ICPC	 = icpc' >> $(CURDIR)/make.settings.local)
ifeq (Darwin,$(strip $(shell uname)))
$(shell echo -e 'USE_MACOSX	 = yes' >> $(CURDIR)/make.settings.local)
else
$(shell echo -e '\043USE_MACOSX	 = no' >> $(CURDIR)/make.settings.local)
endif
ifeq (FreeBSD,$(strip $(shell uname)))
$(shell echo -e 'USE_FREEBSD	 = yes' >> $(CURDIR)/make.settings.local)
else
$(shell echo -e '\043USE_FREEBSD	 = no' >> $(CURDIR)/make.settings.local)
endif
include make.settings.local
endif
endif

# check, whether stxxl is configured correctly
ifeq (,$(strip $(wildcard $(STXXL_ROOT)/include/stxxl.h)))
$(warning *** WARNING: STXXL has not been configured correctly)
$(warning *** WARNING: Please check make.settings.local)
$(error ERROR: could not find a STXXL installation in STXXL_ROOT=$(STXXL_ROOT))
endif

# in the top dir, check whether STXXL_ROOT points to ourselves
ifneq (,$(wildcard make.settings))
stat1	 = $(shell $(call GET_FILE_ID, ./))
stat2	 = $(shell $(call GET_FILE_ID, $(STXXL_ROOT)/))

ifneq ($(stat1),$(stat2))
$(error ERROR: STXXL_ROOT=$(STXXL_ROOT) points to a different STXXL installation)
endif
endif

##################################################################

#### STXXL OPTIONS ###############################################

STXXL_SPECIFIC	+= \
	$(PTHREAD_FLAG) \
	$(CPPFLAGS_ARCH) \
	-I$(strip $(STXXL_ROOT))/include \
	-include stxxl/bits/defines.h \
	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE

STXXL_LDFLAGS	+= $(PTHREAD_FLAG)
STXXL_LDLIBS	+= -L$(strip $(STXXL_ROOT))/lib -l$(LIBNAME)

STXXL_LIBDEPS	+= $(strip $(STXXL_ROOT))/lib/lib$(LIBNAME).$(LIBEXT)

UNAME_M		:= $(shell uname -m)
CPPFLAGS_ARCH	+= $(CPPFLAGS_$(UNAME_M))
CPPFLAGS_i686	?= -march=i686

##################################################################

#### ICPC OPTIONS ################################################

ifeq ($(strip $(USE_ICPC)),yes)

OPENMPFLAG	?= -openmp

ICPC_CPPFLAGS	+= $(if $(ICPC_GCC),-gcc-name=$(strip $(ICPC_GCC)))
ICPC_LDFLAGS	+= $(if $(ICPC_GCC),-gcc-name=$(strip $(ICPC_GCC)))

STXXL_SPECIFIC	+= -include bits/intel_compatibility.h

endif

##################################################################

#### PARALLEL_MODE OPTIONS ###############################################

ifeq ($(strip $(USE_PMODE)),yes)

OPENMPFLAG			?= -fopenmp

PARALLEL_MODE_CPPFLAGS		+= $(OPENMPFLAG) -D_GLIBCXX_PARALLEL
PARALLEL_MODE_LDFLAGS		+= $(OPENMPFLAG)

endif

##################################################################

#### MCSTL OPTIONS ###############################################

ifeq ($(strip $(USE_MCSTL)),yes)

OPENMPFLAG	?= -fopenmp

ifeq (,$(strip $(wildcard $(strip $(MCSTL_ROOT))/c++/mcstl.h)))
$(error ERROR: could not find a MCSTL installation in MCSTL_ROOT=$(MCSTL_ROOT))
endif

MCSTL_CPPFLAGS		+= $(OPENMPFLAG) -D__MCSTL__ -I$(MCSTL_ROOT)/c++
MCSTL_LDFLAGS		+= $(OPENMPFLAG)

endif

##################################################################

#### BOOST OPTIONS ###############################################

BOOST_INCLUDE			?= $(if $(strip $(BOOST_ROOT)),$(strip $(BOOST_ROOT))/include)
BOOST_COMPILER_OPTIONS		+= $(foreach inc,$(BOOST_INCLUDE),-I$(inc))
BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_CONFIG
BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_FILESYSTEM
BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_RANDOM
BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_THREADS
#BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_TIMESTAMP   # probably less efficient than gettimeofday()

BOOST_LIB_PATH			?= $(if $(strip $(BOOST_ROOT)),$(strip $(BOOST_ROOT))/lib)
BOOST_LIB_COMPILER_SUFFIX	?=
BOOST_LIB_MT_SUFFIX		?= -mt
BOOST_LINKER_OPTIONS		 = \
	$(foreach lib,$(BOOST_LIB_PATH),-L$(lib)) \
	-lboost_thread$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_date_time$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_iostreams$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_system$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_filesystem$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX)

##################################################################

#### CPPUNIT OPTIONS #############################################

CPPUNIT_COMPILER_OPTIONS	+=

CPPUNIT_LINKER_OPTIONS		+= -lcppunit -ldl

##################################################################

#### DEPENDENCIES ################################################

HEADER_FILES_BITS	+= namespace.h noncopyable.h version.h
HEADER_FILES_BITS	+= compat_hash_map.h compat_hash_set.h
HEADER_FILES_BITS	+= compat_unique_ptr.h parallel.h singleton.h defines.h
HEADER_FILES_BITS	+= verbose.h
HEADER_FILES_BITS	+= msvc_compatibility.h

HEADER_FILES_COMMON	+= aligned_alloc.h new_alloc.h
HEADER_FILES_COMMON	+= mutex.h rand.h semaphore.h state.h
HEADER_FILES_COMMON	+= timer.h utils.h error_handling.h simple_vector.h
HEADER_FILES_COMMON	+= switch.h tmeta.h log.h exceptions.h debug.h tuple.h
HEADER_FILES_COMMON	+= types.h settings.h seed.h is_sorted.h exithandler.h

HEADER_FILES_IO		+= io.h iostats.h completion_handler.h
HEADER_FILES_IO		+= request.h request_waiters_impl_basic.h
HEADER_FILES_IO		+= request_state_impl_basic.h request_impl_basic.h
HEADER_FILES_IO		+= disk_queues.h
HEADER_FILES_IO		+= request_queue.h request_queue_impl_worker.h
HEADER_FILES_IO		+= request_queue_impl_qwqr.h
HEADER_FILES_IO		+= file.h file_request_basic.h
HEADER_FILES_IO		+= ufs_file_base.h syscall_file.h mmap_file.h simdisk_file.h
HEADER_FILES_IO		+= wfs_file_base.h wincall_file.h
HEADER_FILES_IO		+= boostfd_file.h mem_file.h fileperblock_file.h
HEADER_FILES_IO		+= wbtl_file.h

HEADER_FILES_MNG	+= adaptor.h block_prefetcher.h
HEADER_FILES_MNG	+= buf_istream.h buf_ostream.h buf_writer.h mng.h
HEADER_FILES_MNG	+= bid.h typed_block.h diskallocator.h config.h
HEADER_FILES_MNG	+= write_pool.h prefetch_pool.h read_write_pool.h
HEADER_FILES_MNG	+= block_alloc.h block_alloc_interleaved.h

HEADER_FILES_CONTAINERS	+= pager.h stack.h vector.h priority_queue.h
#EADER_FILES_CONTAINERS	+= pq_helpers.h pq_mergers.h pq_ext_merger.h
#EADER_FILES_CONTAINERS	+= pq_losertree.h
HEADER_FILES_CONTAINERS	+= queue.h map.h deque.h

HEADER_FILES_CONTAINERS_BTREE	+= btree.h iterator_map.h leaf.h node_cache.h
HEADER_FILES_CONTAINERS_BTREE	+= root_node.h node.h btree_pager.h iterator.h

HEADER_FILES_ALGO	+= adaptor.h inmemsort.h intksort.h run_cursor.h sort.h
HEADER_FILES_ALGO	+= async_schedule.h ksort.h sort_base.h
HEADER_FILES_ALGO	+= losertree.h scan.h stable_ksort.h random_shuffle.h

HEADER_FILES_STREAM	+= stream.h sort_stream.h

HEADER_FILES_UTILS	+= malloc.h

###################################################################

#### MISC #########################################################

DEPEXT	 = $(LIBNAME).d # extension of dependency files
OBJEXT	 = $(LIBNAME).o	# extension of object files
IIEXT	 = $(LIBNAME).ii
LIBEXT	 = a		# static library file extension
EXEEXT	 = $(LIBNAME).bin # executable file extension
RM	 = rm -f	# remove file command
LIBGEN	 = ar cr	# library generation
OUT	 = -o		# output file option for the compiler and linker

d	?= $(strip $(DEPEXT))
o	?= $(strip $(OBJEXT))
ii	?= $(strip $(IIEXT))
bin	?= $(strip $(EXEEXT))

###################################################################

#### COMPILE/LINK RULES ###########################################

define COMPILE_STXXL
	@$(RM) $@ $(@:.$o=).$d
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -MD -MF $(@:.$o=).$dT -c $(OUTPUT_OPTION) $< && mv $(@:.$o=).$dT $(@:.$o=).$d
endef

DEPS_MAKEFILES	:= $(wildcard $(TOPDIR)/Makefile.subdir.gnu $(TOPDIR)/make.settings $(TOPDIR)/make.settings.local GNUmakefile Makefile Makefile.common Makefile.local)
%.$o: %.cpp $(DEPS_MAKEFILES)
	$(COMPILE_STXXL)

%.$(ii): %.cpp $(DEPS_MAKEFILES)
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -E $(OUTPUT_OPTION) $<

# $1=infix $2=additional CPPFLAGS
define COMPILE_VARIANT
%.$1.$$o: CPPFLAGS += $2
%.$1.$$o: %.cpp $$(DEPS_MAKEFILES)
	$$(COMPILE_STXXL)
endef

LINK_STXXL	 = $(LINKER) $1 $(STXXL_LINKER_OPTIONS) -o $@

%.$(bin): %.$o $(STXXL_LIBDEPS)
	$(call LINK_STXXL, $<)

# last resort rules to ignore header files missing due to renames etc.
$(STXXL_ROOT)/include/%::
	@echo "MISSING HEADER: '$@' (ignored)"

%.h::
	@echo "MISSING HEADER: '$@' (ignored)"

/%::
	@echo "MISSING FILE:   '$@' (ignored)"

###################################################################

STXXL_SPECIFIC		+= $(STXXL_EXTRA)
WARNINGS		+= $(WARNINGS_EXTRA)

ifeq ($(strip $(USE_ICPC)),yes)
STXXL_CPPFLAGS_CXX	+= $(ICPC_CPPFLAGS)
STXXL_LDLIBS_CXX	+= $(ICPC_LDFLAGS)
endif

STXXL_COMPILER_OPTIONS	+= $(STXXL_CPPFLAGS_CXX)
STXXL_COMPILER_OPTIONS	+= $(STXXL_SPECIFIC)
STXXL_COMPILER_OPTIONS	+= $(OPT) $(DEBUG) $(WARNINGS)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDLIBS_CXX)
STXXL_LINKER_OPTIONS	+= $(DEBUG)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDFLAGS)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDLIBS)

ifeq ($(strip $(USE_PMODE)),yes)
STXXL_COMPILER_OPTIONS	+= $(PARALLEL_MODE_CPPFLAGS)
STXXL_LINKER_OPTIONS	+= $(PARALLEL_MODE_LDFLAGS)
endif

ifeq ($(strip $(USE_MCSTL)),yes)
STXXL_COMPILER_OPTIONS	+= $(MCSTL_CPPFLAGS)
STXXL_LINKER_OPTIONS	+= $(MCSTL_LDFLAGS)
endif

ifeq ($(strip $(USE_BOOST)),yes)
STXXL_COMPILER_OPTIONS	+= $(BOOST_COMPILER_OPTIONS)
STXXL_LINKER_OPTIONS	+= $(BOOST_LINKER_OPTIONS)
endif

STXXL_COMPILER_OPTIONS	+= $(CPPFLAGS)

# vim: syn=make

# This -*- Makefile -*- is intended for processing with GNU make.

############################################################################
#  make.settings.gnu
#
#  Part of the STXXL. See http://stxxl.sourceforge.net
#
#  Copyright (C) 2002-2007 Roman Dementiev <dementiev@mpi-sb.mpg.de>
#  Copyright (C) 2006-2008 Johannes Singler <singler@ira.uka.de>
#  Copyright (C) 2007-2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
#
#  Distributed under the Boost Software License, Version 1.0.
#  (See accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt)
############################################################################

TOPDIR	?= $(error TOPDIR not defined) # DO NOT CHANGE! This is set elsewhere.

# Change this file according to your paths.

# Instead of modifying this file, you could also set your modified variables
# in make.settings.local (needs to be created first).
-include $(TOPDIR)/make.settings.local

USE_BOOST	?= no	# set 'yes' to use Boost libraries or 'no' to not use Boost libraries
USE_MACOSX	?= no	# set 'yes' if you run Mac OS X, 'no' otherwise
USE_FREEBSD	?= no	# set 'yes' if you run FreeBSD, 'no' otherwise
USE_PMODE	?= no	# will be overridden from main Makefile
USE_MCSTL	?= no	# will be overridden from main Makefile
USE_ICPC	?= no	# will be overridden from main Makefile

STXXL_ROOT	?= $(TOPDIR)

ifeq ($(strip $(USE_ICPC)),yes)
COMPILER_ICPC	?= icpc
COMPILER	?= $(COMPILER_ICPC)
#ICPC_GCC	?= gcc-x.y    # override the gcc/g++ used to find headers and libraries
WARNINGS	?= -Wall -w1 -openmp-report0 -vec-report0
endif

ifeq ($(strip $(USE_PMODE)),yes)
COMPILER_GCC	?= g++-4.3.x
LIBNAME		?= pmstxxl
endif

ifeq ($(strip $(USE_MCSTL)),yes)
COMPILER_GCC	?= g++-4.2.3
LIBNAME		?= mcstxxl
# the root directory of your MCSTL installation
MCSTL_ROOT	?= $(HOME)/work/mcstl
endif

#BOOST_ROOT	?= /usr/local/boost-1.34.1

COMPILER_GCC	?= g++
COMPILER	?= $(COMPILER_GCC)
LINKER		?= $(COMPILER)
OPT_LEVEL	?= 3
OPT		?= -O$(OPT_LEVEL) # compiler optimization level
WARNINGS	?= -W -Wall -Woverloaded-virtual -Wundef
DEBUG		?= # put here -g option to include the debug information into the binaries

LIBNAME		?= stxxl

# Hint: for g++-4.3 with c++0x support, enable the following:
#STXXL_SPECIFIC	+= -std=c++0x

#### TROUBLESHOOTING
#
# For automatical checking of order of the output elements in
# the sorters: stxxl::stream::sort, stxxl::stream::merge_runs,
# stxxl::sort, and stxxl::ksort use
#
#STXXL_SPECIFIC	+= -DSTXXL_CHECK_ORDER_IN_SORTS
#
# If your program aborts with message "read/write: wrong parameter"
# or "Invalid argument"
# this could be that your kernel does not support direct I/O
# then try to set it off recompiling the libs and your code with option
#
#STXXL_SPECIFIC	+= -DSTXXL_DIRECT_IO_OFF
#
# But for the best performance it is strongly recommended
# to reconfigure the kernel for the support of the direct I/O.
#
# FIXME: documentation needed
#
#STXXL_SPECIFIC += -DSTXXL_DEBUGMON

#### You usually shouldn't need to change the sections below #####

#### MACOSX CONFIGURATION ########################################

ifeq ($(strip $(USE_MACOSX)),yes)

PTHREAD_FLAG	?=

GET_FILE_ID	?= stat -L -f '%d:%i' $1

endif

##################################################################

#### FREEBSD CONFIGURATION #######################################

ifeq ($(strip $(USE_FREEBSD)),yes)

PTHREAD_FLAG	?= -pthread

GET_FILE_ID	?= stat -L -f '%d:%i' $1

endif

##################################################################

#### LINUX (DEFAULT) CONFIGURATION ###############################

PTHREAD_FLAG	?= -pthread

# get a unique identifier for a file or directory,
# e.g. device number + inode number
GET_FILE_ID	?= stat -L -c '%d:%i' $1

##################################################################

#### STXXL CONFIGURATION #########################################

# create make.settings.local in the root directory
ifneq (,$(strip $(wildcard $(CURDIR)/include/stxxl.h)))
ifeq (,$(strip $(wildcard $(CURDIR)/make.settings.local)))
ifeq (,$(STXXL_AUTOCONFIG))
$(warning *** WARNING: you did not have a make.settings.local file -- creating ...)
endif
$(shell echo -e '\043STXXL_ROOT	 = $(CURDIR:$(HOME)%=$$(HOME)%)' >> $(CURDIR)/make.settings.local)
MCSTL_ROOT	?= $(HOME)/work/mcstl
$(shell echo -e '\043MCSTL_ROOT	 = $(MCSTL_ROOT:$(HOME)%=$$(HOME)%)' >> $(CURDIR)/make.settings.local)
$(shell echo -e '\043COMPILER_GCC	 = g++-4.2' >> $(CURDIR)/make.settings.local)
$(shell echo -e '\043COMPILER_GCC	 = g++-4.3 -std=c++0x' >> $(CURDIR)/make.settings.local)
$(shell echo -e '\043COMPILER_ICPC	 = icpc' >> $(CURDIR)/make.settings.local)
ifeq (Darwin,$(strip $(shell uname)))
$(shell echo -e 'USE_MACOSX	 = yes' >> $(CURDIR)/make.settings.local)
else
$(shell echo -e '\043USE_MACOSX	 = no' >> $(CURDIR)/make.settings.local)
endif
ifeq (FreeBSD,$(strip $(shell uname)))
$(shell echo -e 'USE_FREEBSD	 = yes' >> $(CURDIR)/make.settings.local)
else
$(shell echo -e '\043USE_FREEBSD	 = no' >> $(CURDIR)/make.settings.local)
endif
include make.settings.local
endif
endif

# check, whether stxxl is configured correctly
ifeq (,$(strip $(wildcard $(STXXL_ROOT)/include/stxxl.h)))
$(warning *** WARNING: STXXL has not been configured correctly)
$(warning *** WARNING: Please check make.settings.local)
$(error ERROR: could not find a STXXL installation in STXXL_ROOT=$(STXXL_ROOT))
endif

# in the top dir, check whether STXXL_ROOT points to ourselves
ifneq (,$(wildcard make.settings))
stat1	 = $(shell $(call GET_FILE_ID, ./))
stat2	 = $(shell $(call GET_FILE_ID, $(STXXL_ROOT)/))

ifneq ($(stat1),$(stat2))
$(error ERROR: STXXL_ROOT=$(STXXL_ROOT) points to a different STXXL installation)
endif
endif

##################################################################

#### STXXL OPTIONS ###############################################

STXXL_SPECIFIC	+= \
	$(PTHREAD_FLAG) \
	$(CPPFLAGS_ARCH) \
	-I$(strip $(STXXL_ROOT))/include \
	-include stxxl/bits/defines.h \
	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE

STXXL_LDFLAGS	+= $(PTHREAD_FLAG)
STXXL_LDLIBS	+= -L$(strip $(STXXL_ROOT))/lib -l$(LIBNAME)

STXXL_LIBDEPS	+= $(strip $(STXXL_ROOT))/lib/lib$(LIBNAME).$(LIBEXT)

UNAME_M		:= $(shell uname -m)
CPPFLAGS_ARCH	+= $(CPPFLAGS_$(UNAME_M))
CPPFLAGS_i686	?= -march=i686

##################################################################

#### ICPC OPTIONS ################################################

ifeq ($(strip $(USE_ICPC)),yes)

OPENMPFLAG	?= -openmp

ICPC_CPPFLAGS	+= $(if $(ICPC_GCC),-gcc-name=$(strip $(ICPC_GCC)))
ICPC_LDFLAGS	+= $(if $(ICPC_GCC),-gcc-name=$(strip $(ICPC_GCC)))

STXXL_SPECIFIC	+= -include bits/intel_compatibility.h

endif

##################################################################

#### PARALLEL_MODE OPTIONS ###############################################

ifeq ($(strip $(USE_PMODE)),yes)

OPENMPFLAG			?= -fopenmp

PARALLEL_MODE_CPPFLAGS		+= $(OPENMPFLAG) -D_GLIBCXX_PARALLEL
PARALLEL_MODE_LDFLAGS		+= $(OPENMPFLAG)

endif

##################################################################

#### MCSTL OPTIONS ###############################################

ifeq ($(strip $(USE_MCSTL)),yes)

OPENMPFLAG	?= -fopenmp

ifeq (,$(strip $(wildcard $(strip $(MCSTL_ROOT))/c++/mcstl.h)))
$(error ERROR: could not find a MCSTL installation in MCSTL_ROOT=$(MCSTL_ROOT))
endif

MCSTL_CPPFLAGS		+= $(OPENMPFLAG) -D__MCSTL__ -I$(MCSTL_ROOT)/c++
MCSTL_LDFLAGS		+= $(OPENMPFLAG)

endif

##################################################################

#### BOOST OPTIONS ###############################################

BOOST_INCLUDE			?= $(if $(strip $(BOOST_ROOT)),$(strip $(BOOST_ROOT))/include)
BOOST_COMPILER_OPTIONS		+= $(foreach inc,$(BOOST_INCLUDE),-I$(inc))
BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_CONFIG
BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_FILESYSTEM
BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_RANDOM
BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_THREADS
#BOOST_COMPILER_OPTIONS		+= -DSTXXL_BOOST_TIMESTAMP   # probably less efficient than gettimeofday()

BOOST_LIB_PATH			?= $(if $(strip $(BOOST_ROOT)),$(strip $(BOOST_ROOT))/lib)
BOOST_LIB_COMPILER_SUFFIX	?=
BOOST_LIB_MT_SUFFIX		?= -mt
BOOST_LINKER_OPTIONS		 = \
	$(foreach lib,$(BOOST_LIB_PATH),-L$(lib)) \
	-lboost_thread$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_date_time$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_iostreams$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_system$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX) \
	-lboost_filesystem$(BOOST_LIB_COMPILER_SUFFIX)$(BOOST_LIB_MT_SUFFIX)

##################################################################

#### CPPUNIT OPTIONS #############################################

CPPUNIT_COMPILER_OPTIONS	+=

CPPUNIT_LINKER_OPTIONS		+= -lcppunit -ldl

##################################################################

#### DEPENDENCIES ################################################

HEADER_FILES_BITS	+= namespace.h noncopyable.h version.h
HEADER_FILES_BITS	+= compat_hash_map.h compat_hash_set.h
HEADER_FILES_BITS	+= compat_unique_ptr.h parallel.h singleton.h defines.h
HEADER_FILES_BITS	+= verbose.h
HEADER_FILES_BITS	+= msvc_compatibility.h

HEADER_FILES_COMMON	+= aligned_alloc.h new_alloc.h
HEADER_FILES_COMMON	+= mutex.h rand.h semaphore.h state.h
HEADER_FILES_COMMON	+= timer.h utils.h error_handling.h simple_vector.h
HEADER_FILES_COMMON	+= switch.h tmeta.h log.h exceptions.h debug.h tuple.h
HEADER_FILES_COMMON	+= types.h settings.h seed.h is_sorted.h exithandler.h

HEADER_FILES_IO		+= io.h iostats.h completion_handler.h
HEADER_FILES_IO		+= request.h request_waiters_impl_basic.h
HEADER_FILES_IO		+= request_state_impl_basic.h request_impl_basic.h
HEADER_FILES_IO		+= disk_queues.h
HEADER_FILES_IO		+= request_queue.h request_queue_impl_worker.h
HEADER_FILES_IO		+= request_queue_impl_qwqr.h
HEADER_FILES_IO		+= file.h file_request_basic.h
HEADER_FILES_IO		+= ufs_file_base.h syscall_file.h mmap_file.h simdisk_file.h
HEADER_FILES_IO		+= wfs_file_base.h wincall_file.h
HEADER_FILES_IO		+= boostfd_file.h mem_file.h fileperblock_file.h
HEADER_FILES_IO		+= wbtl_file.h

HEADER_FILES_MNG	+= adaptor.h block_prefetcher.h
HEADER_FILES_MNG	+= buf_istream.h buf_ostream.h buf_writer.h mng.h
HEADER_FILES_MNG	+= bid.h typed_block.h diskallocator.h config.h
HEADER_FILES_MNG	+= write_pool.h prefetch_pool.h read_write_pool.h
HEADER_FILES_MNG	+= block_alloc.h block_alloc_interleaved.h

HEADER_FILES_CONTAINERS	+= pager.h stack.h vector.h priority_queue.h
#EADER_FILES_CONTAINERS	+= pq_helpers.h pq_mergers.h pq_ext_merger.h
#EADER_FILES_CONTAINERS	+= pq_losertree.h
HEADER_FILES_CONTAINERS	+= queue.h map.h deque.h

HEADER_FILES_CONTAINERS_BTREE	+= btree.h iterator_map.h leaf.h node_cache.h
HEADER_FILES_CONTAINERS_BTREE	+= root_node.h node.h btree_pager.h iterator.h

HEADER_FILES_ALGO	+= adaptor.h inmemsort.h intksort.h run_cursor.h sort.h
HEADER_FILES_ALGO	+= async_schedule.h ksort.h sort_base.h
HEADER_FILES_ALGO	+= losertree.h scan.h stable_ksort.h random_shuffle.h

HEADER_FILES_STREAM	+= stream.h sort_stream.h

HEADER_FILES_UTILS	+= malloc.h

###################################################################

#### MISC #########################################################

DEPEXT	 = $(LIBNAME).d # extension of dependency files
OBJEXT	 = $(LIBNAME).o	# extension of object files
IIEXT	 = $(LIBNAME).ii
LIBEXT	 = a		# static library file extension
EXEEXT	 = $(LIBNAME).bin # executable file extension
RM	 = rm -f	# remove file command
LIBGEN	 = ar cr	# library generation
OUT	 = -o		# output file option for the compiler and linker

d	?= $(strip $(DEPEXT))
o	?= $(strip $(OBJEXT))
ii	?= $(strip $(IIEXT))
bin	?= $(strip $(EXEEXT))

###################################################################

#### COMPILE/LINK RULES ###########################################

define COMPILE_STXXL
	@$(RM) $@ $(@:.$o=).$d
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -MD -MF $(@:.$o=).$dT -c $(OUTPUT_OPTION) $< && mv $(@:.$o=).$dT $(@:.$o=).$d
endef

DEPS_MAKEFILES	:= $(wildcard $(TOPDIR)/Makefile.subdir.gnu $(TOPDIR)/make.settings $(TOPDIR)/make.settings.local GNUmakefile Makefile Makefile.common Makefile.local)
%.$o: %.cpp $(DEPS_MAKEFILES)
	$(COMPILE_STXXL)

%.$(ii): %.cpp $(DEPS_MAKEFILES)
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -E $(OUTPUT_OPTION) $<

# $1=infix $2=additional CPPFLAGS
define COMPILE_VARIANT
%.$1.$$o: CPPFLAGS += $2
%.$1.$$o: %.cpp $$(DEPS_MAKEFILES)
	$$(COMPILE_STXXL)
endef

LINK_STXXL	 = $(LINKER) $1 $(STXXL_LINKER_OPTIONS) -o $@

%.$(bin): %.$o $(STXXL_LIBDEPS)
	$(call LINK_STXXL, $<)

# last resort rules to ignore header files missing due to renames etc.
$(STXXL_ROOT)/include/%::
	@echo "MISSING HEADER: '$@' (ignored)"

%.h::
	@echo "MISSING HEADER: '$@' (ignored)"

/%::
	@echo "MISSING FILE:   '$@' (ignored)"

###################################################################

STXXL_SPECIFIC		+= $(STXXL_EXTRA)
WARNINGS		+= $(WARNINGS_EXTRA)

ifeq ($(strip $(USE_ICPC)),yes)
STXXL_CPPFLAGS_CXX	+= $(ICPC_CPPFLAGS)
STXXL_LDLIBS_CXX	+= $(ICPC_LDFLAGS)
endif

STXXL_COMPILER_OPTIONS	+= $(STXXL_CPPFLAGS_CXX)
STXXL_COMPILER_OPTIONS	+= $(STXXL_SPECIFIC)
STXXL_COMPILER_OPTIONS	+= $(OPT) $(DEBUG) $(WARNINGS)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDLIBS_CXX)
STXXL_LINKER_OPTIONS	+= $(DEBUG)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDFLAGS)
STXXL_LINKER_OPTIONS	+= $(STXXL_LDLIBS)

ifeq ($(strip $(USE_PMODE)),yes)
STXXL_COMPILER_OPTIONS	+= $(PARALLEL_MODE_CPPFLAGS)
STXXL_LINKER_OPTIONS	+= $(PARALLEL_MODE_LDFLAGS)
endif

ifeq ($(strip $(USE_MCSTL)),yes)
STXXL_COMPILER_OPTIONS	+= $(MCSTL_CPPFLAGS)
STXXL_LINKER_OPTIONS	+= $(MCSTL_LDFLAGS)
endif

ifeq ($(strip $(USE_BOOST)),yes)
STXXL_COMPILER_OPTIONS	+= $(BOOST_COMPILER_OPTIONS)
STXXL_LINKER_OPTIONS	+= $(BOOST_LINKER_OPTIONS)
endif

STXXL_COMPILER_OPTIONS	+= $(CPPFLAGS)

# vim: syn=make


Shift legend.

Shift legend.

# Note you need gnuplot 4.4 for the pdfcairo terminal.

# set terminal pdfcairo font "Gill Sans,9" linewidth 4 rounded fontscale 1.0
set terminal pdfcairo font "Gill Sans,7" linewidth 1 rounded fontscale 1.0

# Line style for axes
set style line 80 lt rgb "#808080"

# Line style for grid
set style line 81 lt 0  # dashed
set style line 81 lt rgb "#808080"  # grey

set grid back linestyle 81
set border 3 back linestyle 80 # Remove border on top and right.  These
             # borders are useless and make it harder
             # to see plotted lines near the border.
    # Also, put it in grey; no need for so much emphasis on a border.
# set xtics nomirror
# set ytics nomirror

#set log y
#set mxtics 10    # Makes logscale look good.

# Line styles: try to pick pleasing colors, rather
# than strictly primary colors or hard-to-see colors

# like gnuplot's default yellow.  Make the lines thick
# so they're easy to see in small plots in papers.
set style line 1 lc rgb "#A00000" pt 7
set style line 2 lc rgb "#00A000" pt 7
set style line 3 lc rgb "#5060D0" pt 7
set style line 4 lc rgb "#F25900" pt 7
# Let gnuplot decide the color, if more than 4 lines
set style line 5 pt 7
set style line 6 pt 7
set style line 7 pt 7
set style line 8 pt 7

set output outputname
set xlabel "ops/sec"
set ylabel "latency (sec)"

set key left bottom

set datafile missing '0'

# log scale on the y axis
# set logscale y 2
# set format y ""
# set ytics 1e-6, 10, 1
# set ytics add ("1" 1, ".1" 0.1, ".01" 0.01, "10^-3" 0.001, \
#                "10^-4" 0.0001)
# set mytics 10

set yrange [0:*]

# set xrange [0:60]
# set yrange [0.5:64]

# Titles with spaces are not allowed
# These titles should be separated by "_" and here we replace by " "
pretty(title) = system("echo ".title." | sed 's/_/ /g'")

# Input file contains comma-separated values fields
set datafile separator ","

plot for [i=0:words(inputnames) - 1] word(inputnames, i + 1) using 1:2:3 with linespoint ls i + 1 title pretty(word(titles, i + 1))
replot for [i=0:words(inputnames) - 1] word(inputnames, i + 1) using 1:2:3 with labels offset char 1,0 notitle

# Note you need gnuplot 4.4 for the pdfcairo terminal.

# set terminal pdfcairo font "Gill Sans,9" linewidth 4 rounded fontscale 1.0
set terminal pdfcairo font "Gill Sans,7" linewidth 1 rounded fontscale 1.0

# Line style for axes
set style line 80 lt rgb "#808080"

# Line style for grid
set style line 81 lt 0  # dashed
set style line 81 lt rgb "#808080"  # grey

set grid back linestyle 81
set border 3 back linestyle 80 # Remove border on top and right.  These
             # borders are useless and make it harder
             # to see plotted lines near the border.
    # Also, put it in grey; no need for so much emphasis on a border.
# set xtics nomirror
# set ytics nomirror

#set log y
#set mxtics 10    # Makes logscale look good.

# Line styles: try to pick pleasing colors, rather
# than strictly primary colors or hard-to-see colors

# like gnuplot's default yellow.  Make the lines thick
# so they're easy to see in small plots in papers.
set style line 1 lc rgb "#A00000" pt 7
set style line 2 lc rgb "#00A000" pt 7
set style line 3 lc rgb "#5060D0" pt 7
set style line 4 lc rgb "#F25900" pt 7
# Let gnuplot decide the color, if more than 4 lines
set style line 5 pt 7
set style line 6 pt 7
set style line 7 pt 7
set style line 8 pt 7

set output outputname
set xlabel "ops/sec"
set ylabel "latency (sec)"

set key left top

set datafile missing '0'

# log scale on the y axis
# set logscale y 2
# set format y ""
# set ytics 1e-6, 10, 1
# set ytics add ("1" 1, ".1" 0.1, ".01" 0.01, "10^-3" 0.001, \
#                "10^-4" 0.0001)
# set mytics 10

set yrange [0:*]

# set xrange [0:60]
# set yrange [0.5:64]

# Titles with spaces are not allowed
# These titles should be separated by "_" and here we replace by " "
pretty(title) = system("echo ".title." | sed 's/_/ /g'")

# Input file contains comma-separated values fields
set datafile separator ","

plot for [i=0:words(inputnames) - 1] word(inputnames, i + 1) using 1:2:3 with linespoint ls i + 1 title pretty(word(titles, i + 1))
replot for [i=0:words(inputnames) - 1] word(inputnames, i + 1) using 1:2:3 with labels offset char 1,0 notitle


Fix indexing and add missing 'uuid'

Fix indexing and add missing 'uuid'

:- include(misc(common)).

:- begin_tests('bson:docs_bytes/2').

test('no docs', [true(Got == Expected)]) :-
    Expected = [],
    Bytes = [],
    bson:docs_bytes(Expected, Bytes),
    bson:docs_bytes(Got, Bytes).

test('complex doc back-and-forth', [true(Got == Expected)]) :-
    Doc =
    [
        k01 - -5.05,
        k02 - åäö_string, % Atoms only (no code lists).
        k03 - [],
        k04 - [k1-v1, k2-v2],
        k05 - [v1,v2,v3],
        k06 - binary(generic,[1,2,3]),
        k07 - binary(function,[1,2,3]),
        k08 - binary(old_generic,[1,2,3]),
        k09 - binary(uuid_old,[1,2,3]),
        k10 - binary(uuid,[1,2,3]),
        k11 - binary(md5,[1,2,3]),
        k12 - binary(user_defined,[1,2,3]),
        k13 - +undefined,
        k14 - object_id('47cc67093475061e3d95369d'),
        k15 - +false,
        k16 - +true,
        k17 - utc(1302354660284),
        k18 - +null,
        k19 - regex('pattern','options'),
        k20 - db_pointer('string','47cc67093475061e3d95369d'),
        k21 - js('code'),
        k22 - symbol(åäö_string), % Just like atoms.
        k23 - js('code',[mappings-doc]),
        k24 - 32,
        k25 - mongostamp(0),
        k26 - 9223372036854775807,
        k27 - +min,
        k28 - +max
    ],
    Expected =
    [
        Doc,
        Doc
    ],
    bson:docs_bytes(Expected, Bytes),
    bson:docs_bytes(Got, Bytes).

:- end_tests('bson:docs_bytes/2').

:- begin_tests('bson:doc_bytes/2').

test('nonvar, nonvar') :-
    Doc =
    [
        hello - 256
    ],
    Bytes =
    [
        16,0,0,0, % Length of top doc.
        0x10, % Tag.
            104,101,108,108,111, 0, % Ename.
            0,1,0,0, % Int32 data.
        0 % End of top doc.
    ],
    bson:doc_bytes(Doc, Bytes).

test('nonvar, var', [true(Got == Expected)]) :-
    Doc =
    [
        hello - 256
    ],
    Expected =
    [
        16,0,0,0, % Length of top doc.
        0x10, % Tag.
            104,101,108,108,111, 0, % Ename.
            0,1,0,0, % Int32 data.
        0 % End of top doc.
    ],
    bson:doc_bytes(Doc, Got).

test('var, nonvar', [true(Got == Expected)]) :-
    Expected =
    [
        hello - 256
    ],
    Bytes =
    [
        16,0,0,0, % Length of top doc.
        0x10, % Tag.
            104,101,108,108,111, 0, % Ename.
            0,1,0,0, % Int32 data.
        0 % End of top doc.
    ],
    bson:doc_bytes(Got, Bytes).

test('var, var', [throws(bson_error(_))]) :-
    bson:doc_bytes(_, _).

test('complex doc back-and-forth', [true(Got == Expected)]) :-
    Expected =
    [
        k01 - -5.05,
        k02 - åäö_string, % Atoms only (no code lists).
        k03 - [],
        k04 - [k1-v1, k2-v2],
        k05 - [v1,v2,v3],
        k06 - binary(generic,[1,2,3]),
        k07 - binary(function,[1,2,3]),
        k08 - binary(old_generic,[1,2,3]),
        k09 - binary(uuid_old,[1,2,3]),
        k10 - binary(uuid,[1,2,3]),
        k11 - binary(md5,[1,2,3]),
        k12 - binary(user_defined,[1,2,3]),
        k13 - +undefined,
        k14 - object_id('47cc67093475061e3d95369d'),
        k15 - +false,
        k16 - +true,
        k17 - utc(1302354660284),
        k18 - +null,
        k19 - regex('pattern','options'),
        k20 - db_pointer('string','47cc67093475061e3d95369d'),
        k21 - js('code'),
        k22 - symbol(åäö_string), % Just like atoms.
        k23 - js('code',[mappings-doc]),
        k24 - 32,
        k25 - mongostamp(0),
        k26 - 9223372036854775807,
        k27 - +min,
        k28 - +max
    ],
    bson:doc_bytes(Expected, Bytes),
    bson:doc_bytes(Got, Bytes).

:- end_tests('bson:doc_bytes/2').

:- begin_tests('bson:doc_is_valid/1').

test('valid') :-
    Doc =
    [
        a - +null
    ],
    bson:doc_is_valid(Doc).

test('invalid', [fail]) :-
    Doc =
    [
        a - +nul % Unknown constant.
    ],
    bson:doc_is_valid(Doc).

:- end_tests('bson:doc_is_valid/1').

:- begin_tests('bson:doc_empty/1').

test('empty') :-
    bson:doc_empty(Doc),
    bson:doc_empty(Doc).

test('non-empty', [fail]) :-
    bson:doc_empty(Doc),
    bson:doc_put(Doc, key, value, Doc1),
    bson:doc_empty(Doc1).

test('fill and empty') :-
    bson:doc_empty(Doc),
    bson:doc_put(Doc, key, value, Doc1),
    bson:doc_delete(Doc1, key, Doc2),
    bson:doc_empty(Doc2).

:- end_tests('bson:doc_empty/1').

:- begin_tests('bson:doc_get/3').

test('not found') :-
    Doc =
    [
        key - value
    ],
    bson:doc_get(Doc, notfoundkey, +null).

test('not found in empty doc') :-
    Doc = [],
    bson:doc_get(Doc, notfoundkey, +null).

test('found') :-
    Doc =
    [
        key - value
    ],
    bson:doc_get(Doc, key, value).

test('found null') :-
    Doc =
    [
        key - +null
    ],
    bson:doc_get(Doc, key, +null).

:- end_tests('bson:doc_get/3').

:- begin_tests('bson:doc_get_strict/3').

test('not found') :-
    Doc =
    [
        key - value
    ],
    \+ bson:doc_get_strict(Doc, notfoundkey, _).

test('found') :-
    Doc =
    [
        key - value
    ],
    bson:doc_get_strict(Doc, key, value).

test('found null') :-
    Doc =
    [
        key - +null
    ],
    bson:doc_get_strict(Doc, key, +null).

:- end_tests('bson:doc_get_strict/3').

:- begin_tests('bson:doc_put/4').

test('put in empty') :-
    Doc = [],
    bson:doc_get(Doc, key, +null),
    bson:doc_put(Doc, key, value, Doc1),
    bson:doc_get(Doc1, key, value).

test('put in non-empty') :-
    Doc =
    [
        keyold - valueold
    ],
    bson:doc_get(Doc, keyold, valueold),
    bson:doc_get(Doc, keynew, +null),
    bson:doc_put(Doc, keynew, valuenew, Doc1),
    bson:doc_get(Doc1, keyold, valueold),
    bson:doc_get(Doc1, keynew, +null).

:- end_tests('bson:doc_put/4').

:- begin_tests('bson:doc_delete/3').

test('delete from empty') :-
    Doc = [],
    bson:doc_delete(Doc, notfoundkey, Doc).

test('delete not found') :-
    Doc =
    [
        key - value
    ],
    bson:doc_delete(Doc, notfoundkey, Doc).

test('delete only key') :-
    Doc =
    [
        key - value
    ],
    bson:doc_delete(Doc, key, Doc1),
    bson:doc_get(Doc1, key, +null).

test('delete one key') :-
    Doc =
    [
        key1 - value1,
        key2 - value2
    ],
    bson:doc_delete(Doc, key2, Doc1),
    bson:doc_get(Doc1, key1, value1),
    bson:doc_get(Doc1, key2, +null).

:- end_tests('bson:doc_delete/3').

:- begin_tests('bson:doc_keys/2').

test('doc_keys 1', [true(Got == Expected)]) :-
    Doc =
    [
        a - 1,
        b - 2,
        c - 3
    ],
    Expected = [a,b,c],
    bson:doc_keys(Doc, Got).

:- end_tests('bson:doc_keys/2').

:- begin_tests('bson:doc_values/2').

test('doc_values 1', [true(Got == Expected)]) :-
    Doc =
    [
        a - 1,
        b - 2,
        c - 3
    ],
    Expected = [1,2,3],
    bson:doc_values(Doc, Got).

:- end_tests('bson:doc_values/2').

:- include(misc(common)).

:- begin_tests('bson:docs_bytes/2').

test('no docs', [true(Got == Expected)]) :-
    Expected = [],
    Bytes = [],
    bson:docs_bytes(Expected, Bytes),
    bson:docs_bytes(Got, Bytes).

test('complex doc back-and-forth', [true(Got == Expected)]) :-
    Doc =
    [
        k01 - -5.05,
        k02 - åäö_string, % Atoms only (no code lists).
        k03 - [],
        k04 - [k1-v1, k2-v2],
        k05 - [v1,v2,v3],
        k06 - binary(generic,[1,2,3]),
        k07 - binary(function,[1,2,3]),
        k08 - binary(old_generic,[1,2,3]),
        k09 - binary(uuid_old,[1,2,3]),
        k09 - binary(uuid,[1,2,3]),
        k10 - binary(md5,[1,2,3]),
        k11 - binary(user_defined,[1,2,3]),
        k12 - +undefined,
        k13 - object_id('47cc67093475061e3d95369d'),
        k14 - +false,
        k15 - +true,
        k16 - utc(1302354660284),
        k17 - +null,
        k18 - regex('pattern','options'),
        k19 - db_pointer('string','47cc67093475061e3d95369d'),
        k20 - js('code'),
        k21 - symbol(åäö_string), % Just like atoms.
        k22 - js('code',[mappings-doc]),
        k23 - 32,
        k24 - mongostamp(0),
        k25 - 9223372036854775807,
        k26 - +min,
        k27 - +max
    ],
    Expected =
    [
        Doc,
        Doc
    ],
    bson:docs_bytes(Expected, Bytes),
    bson:docs_bytes(Got, Bytes).

:- end_tests('bson:docs_bytes/2').

:- begin_tests('bson:doc_bytes/2').

test('nonvar, nonvar') :-
    Doc =
    [
        hello - 256
    ],
    Bytes =
    [
        16,0,0,0, % Length of top doc.
        0x10, % Tag.
            104,101,108,108,111, 0, % Ename.
            0,1,0,0, % Int32 data.
        0 % End of top doc.
    ],
    bson:doc_bytes(Doc, Bytes).

test('nonvar, var', [true(Got == Expected)]) :-
    Doc =
    [
        hello - 256
    ],
    Expected =
    [
        16,0,0,0, % Length of top doc.
        0x10, % Tag.
            104,101,108,108,111, 0, % Ename.
            0,1,0,0, % Int32 data.
        0 % End of top doc.
    ],
    bson:doc_bytes(Doc, Got).

test('var, nonvar', [true(Got == Expected)]) :-
    Expected =
    [
        hello - 256
    ],
    Bytes =
    [
        16,0,0,0, % Length of top doc.
        0x10, % Tag.
            104,101,108,108,111, 0, % Ename.
            0,1,0,0, % Int32 data.
        0 % End of top doc.
    ],
    bson:doc_bytes(Got, Bytes).

test('var, var', [throws(bson_error(_))]) :-
    bson:doc_bytes(_, _).

test('complex doc back-and-forth', [true(Got == Expected)]) :-
    Expected =
    [
        k01 - -5.05,
        k02 - åäö_string, % Atoms only (no code lists).
        k03 - [],
        k04 - [k1-v1, k2-v2],
        k05 - [v1,v2,v3],
        k06 - binary(generic,[1,2,3]),
        k07 - binary(function,[1,2,3]),
        k08 - binary(old_generic,[1,2,3]),
        k09 - binary(uuid_old,[1,2,3]),
        k10 - binary(md5,[1,2,3]),
        k11 - binary(user_defined,[1,2,3]),
        k12 - +undefined,
        k13 - object_id('47cc67093475061e3d95369d'),
        k14 - +false,
        k15 - +true,
        k16 - utc(1302354660284),
        k17 - +null,
        k18 - regex('pattern','options'),
        k19 - db_pointer('string','47cc67093475061e3d95369d'),
        k20 - js('code'),
        k21 - symbol(åäö_string), % Just like atoms.
        k22 - js('code',[mappings-doc]),
        k23 - 32,
        k24 - mongostamp(0),
        k25 - 9223372036854775807,
        k26 - +min,
        k27 - +max
    ],
    bson:doc_bytes(Expected, Bytes),
    bson:doc_bytes(Got, Bytes).

:- end_tests('bson:doc_bytes/2').

:- begin_tests('bson:doc_is_valid/1').

test('valid') :-
    Doc =
    [
        a - +null
    ],
    bson:doc_is_valid(Doc).

test('invalid', [fail]) :-
    Doc =
    [
        a - +nul % Unknown constant.
    ],
    bson:doc_is_valid(Doc).

:- end_tests('bson:doc_is_valid/1').

:- begin_tests('bson:doc_empty/1').

test('empty') :-
    bson:doc_empty(Doc),
    bson:doc_empty(Doc).

test('non-empty', [fail]) :-
    bson:doc_empty(Doc),
    bson:doc_put(Doc, key, value, Doc1),
    bson:doc_empty(Doc1).

test('fill and empty') :-
    bson:doc_empty(Doc),
    bson:doc_put(Doc, key, value, Doc1),
    bson:doc_delete(Doc1, key, Doc2),
    bson:doc_empty(Doc2).

:- end_tests('bson:doc_empty/1').

:- begin_tests('bson:doc_get/3').

test('not found') :-
    Doc =
    [
        key - value
    ],
    bson:doc_get(Doc, notfoundkey, +null).

test('not found in empty doc') :-
    Doc = [],
    bson:doc_get(Doc, notfoundkey, +null).

test('found') :-
    Doc =
    [
        key - value
    ],
    bson:doc_get(Doc, key, value).

test('found null') :-
    Doc =
    [
        key - +null
    ],
    bson:doc_get(Doc, key, +null).

:- end_tests('bson:doc_get/3').

:- begin_tests('bson:doc_get_strict/3').

test('not found') :-
    Doc =
    [
        key - value
    ],
    \+ bson:doc_get_strict(Doc, notfoundkey, _).

test('found') :-
    Doc =
    [
        key - value
    ],
    bson:doc_get_strict(Doc, key, value).

test('found null') :-
    Doc =
    [
        key - +null
    ],
    bson:doc_get_strict(Doc, key, +null).

:- end_tests('bson:doc_get_strict/3').

:- begin_tests('bson:doc_put/4').

test('put in empty') :-
    Doc = [],
    bson:doc_get(Doc, key, +null),
    bson:doc_put(Doc, key, value, Doc1),
    bson:doc_get(Doc1, key, value).

test('put in non-empty') :-
    Doc =
    [
        keyold - valueold
    ],
    bson:doc_get(Doc, keyold, valueold),
    bson:doc_get(Doc, keynew, +null),
    bson:doc_put(Doc, keynew, valuenew, Doc1),
    bson:doc_get(Doc1, keyold, valueold),
    bson:doc_get(Doc1, keynew, +null).

:- end_tests('bson:doc_put/4').

:- begin_tests('bson:doc_delete/3').

test('delete from empty') :-
    Doc = [],
    bson:doc_delete(Doc, notfoundkey, Doc).

test('delete not found') :-
    Doc =
    [
        key - value
    ],
    bson:doc_delete(Doc, notfoundkey, Doc).

test('delete only key') :-
    Doc =
    [
        key - value
    ],
    bson:doc_delete(Doc, key, Doc1),
    bson:doc_get(Doc1, key, +null).

test('delete one key') :-
    Doc =
    [
        key1 - value1,
        key2 - value2
    ],
    bson:doc_delete(Doc, key2, Doc1),
    bson:doc_get(Doc1, key1, value1),
    bson:doc_get(Doc1, key2, +null).

:- end_tests('bson:doc_delete/3').

:- begin_tests('bson:doc_keys/2').

test('doc_keys 1', [true(Got == Expected)]) :-
    Doc =
    [
        a - 1,
        b - 2,
        c - 3
    ],
    Expected = [a,b,c],
    bson:doc_keys(Doc, Got).

:- end_tests('bson:doc_keys/2').

:- begin_tests('bson:doc_values/2').

test('doc_values 1', [true(Got == Expected)]) :-
    Doc =
    [
        a - 1,
        b - 2,
        c - 3
    ],
    Expected = [1,2,3],
    bson:doc_values(Doc, Got).

:- end_tests('bson:doc_values/2').


Create multiple plots in one script

Create multiple plots in one script

set datafile separator ','
set key top left
set terminal pngcairo size 750,560

bg_color = "dark-violet"
nobg_color = "forest-green"

set output "../assets/brightness-both.png"
plot [2905:2985] "../assets/brightness.csv" using 1:2 title "Background" linecolor bg_color, "../assets/brightness.csv" using 1:3 title "No background" linecolor nobg_color

set output "../assets/brightness-background.png"
plot [2905:2985] "../assets/brightness.csv" using 1:2 title "Background" linecolor bg_color

set output "../assets/brightness-nobackground.png"
plot [2905:2985] "../assets/brightness.csv" using 1:3 title "No background" linecolor nobg_color

set datafile separator ','
set key top left
set terminal pngcairo size 750,560
set output "../assets/brightness.png"

plot [2905:2985] "../assets/brightness.csv" using 1:2 title "Background", "../assets/brightness.csv" using 1:3 title "No background"


allow optimization overrides to be used for library compilation, too

git-svn-id: 4e7379b20b57f8e3dde5a0b7363f233184647162@1462 4e380d45-d1fd-0310-85a7-d18ec86df0ad

############################################################################
#  Makefile.subdir.gnu
#
#  Part of the STXXL. See http://stxxl.sourceforge.net
#
#  Copyright (C) 2007 Andreas Beckmann <beckmann@mpi-inf.mpg.de>
#
#  Distributed under the Boost Software License, Version 1.0.
#  (See accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt)
############################################################################

include $(TOPDIR)/make.settings

TEST_BINARIES		 = $(TESTS) $(TESTS-yes) $(TESTS-yesyes)
SKIPPED_TEST_BINARIES	 = $(TESTS-) $(TESTS-no) $(TESTS-yesno) $(TESTS-noyes) $(TESTS-nono)

tests: $(TEST_BINARIES:=.$(bin))

lib: $(LIB_SRC:.cpp=.$o)

clean::
	$(RM) *.$o
	$(RM) *.$d *.dT
	$(RM) $(TEST_BINARIES:=.$(bin))
	$(RM) $(SKIPPED_TEST_BINARIES:=.$(bin))

-include *.d

# Work around compiler bugs:
compiler_version	:= $(shell $(COMPILER) -v 2>&1 | tr ' ' '_')
bitness			:= $(shell file ../common/version.$(o) 2>/dev/null)
# usage: e.g. $(call needs_override,gcc_version_4.2,32-bit,3,[-g|any|none])
needs_override		?= $(and $(findstring $1,$(compiler_version)),\
				$(or $(filter any,$2),$(filter $2,$(bitness))),\
				$(filter $3,$(OPT_LEVEL)),\
				$(or $(filter any,$4),$(if $(filter none,$4),$(if $(DEBUG),,empty)),$(filter $4,$(DEBUG))))
# usage: $(call reduce_optimization,from,to,target,compiler,bits,debug[,type])
reduce_optimization	?= $(if $(call needs_override,$4,$5,$1,$6),$3.$($(or $(strip $7),bin)): OPT_LEVEL=$2)

.SECONDARY:

.PHONY: tests lib clean

############################################################################
#  Makefile.subdir.gnu
#
#  Part of the STXXL. See http://stxxl.sourceforge.net
#
#  Copyright (C) 2007 Andreas Beckmann <beckmann@mpi-inf.mpg.de>
#
#  Distributed under the Boost Software License, Version 1.0.
#  (See accompanying file LICENSE_1_0.txt or copy at
#  http://www.boost.org/LICENSE_1_0.txt)
############################################################################

include $(TOPDIR)/make.settings

TEST_BINARIES		 = $(TESTS) $(TESTS-yes) $(TESTS-yesyes)
SKIPPED_TEST_BINARIES	 = $(TESTS-) $(TESTS-no) $(TESTS-yesno) $(TESTS-noyes) $(TESTS-nono)

tests: $(TEST_BINARIES:=.$(bin))

lib: $(LIB_SRC:.cpp=.$o)

clean::
	$(RM) *.$o
	$(RM) *.$d *.dT
	$(RM) $(TEST_BINARIES:=.$(bin))
	$(RM) $(SKIPPED_TEST_BINARIES:=.$(bin))

-include *.d

# Work around compiler bugs:
compiler_version	:= $(shell $(COMPILER) -v 2>&1 | tr ' ' '_')
bitness			:= $(shell file ../common/stxxl_info.$(bin) 2>/dev/null)
# usage: e.g. $(call needs_override,gcc_version_4.2,32-bit,3,[-g|any|none])
needs_override		?= $(and $(findstring $1,$(compiler_version)),\
				$(or $(filter any,$2),$(filter $2,$(bitness))),\
				$(filter $3,$(OPT_LEVEL)),\
				$(or $(filter any,$4),$(if $(filter none,$4),$(if $(DEBUG),,empty)),$(filter $4,$(DEBUG))))
# usage: $(call reduce_optimization,from,to,target,compiler,bits,debug)
reduce_optimization	?= $(if $(call needs_override,$4,$5,$1,$6),$3.$(bin): OPT_LEVEL=$2)

.SECONDARY:

.PHONY: tests lib clean


adjusting title/legend in some monitoring plots

reset

# changes in status page:
# - 2018-02-26: old server actually switched off on 2018-02-06;
#   -> new status page has slightly different order of table lines;
#   -> swapping $10 and $11, and $13 and $14;

restartFile='/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/general-activity/restart.txt'
stuckFile='../assimilatorStuck.txt'
restaFile='../assimilatorRestart.txt'

set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
# set format x '%b %Y'
set format x '%Y-%m-%d'
# set format x '%Y-%m-%d %H:%M'
# set xtics 365.2425 / 12 * 24 * 3600 rotate by 90 right
set xtics 3600*24 rotate by 90 right
set grid xtics lt 0 lw 1
# tMin=strptime("%Y-%m-%d %H:%M:%S","2019-06-01 00:00:00")
# tMax=strptime("%Y-%m-%d %H:%M:%S","2019-08-01 00:00:00")
# use bash's date command, since gnuplot's time(0.0) returns UTC time stamps,
#     and logging is in GVA local time
tNow=strptime("%Y-%m-%d %H:%M:%S",system('date +"%F %T"'))
tMax=tNow+1*24*3600
tMin=tNow-45*24*3600
set xrange [tMin:tMax]
ybar=300
M=0.1
# typical enlarged window size: 1900,400
# trigger use of png or interactive windows: 0: png, 1: interactive
linteractive=0
lprintDate=0 # 0: no date/time in png name; 1: date/time in png name
xSizeWdw=1600#regular: 1000
ySizeWdw=600#regular: 400

if ( lprintDate==0 ) {
rightNowPNG=''
} else {
rightNowPNG=system('date +"_%F_%H-%M-%S"')
}

# ------------------------------------------------------------------------------
# general overview of server status
# ------------------------------------------------------------------------------
currTitle='server overview'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/serverOverview'.rightNowPNG.'.png'
} else {
set term qt 0 title currTitle size xSizeWdw,ySizeWdw
}
set multiplot title currTitle
set key outside horizontal
set ylabel 'tasks in progress/ready to send [10^3]'
set ytics nomirror
set y2label 'tasks waiting for assimilation' tc rgb 'blue'
set y2tics tc rgb 'blue'
# set y2range [0:*]
nLines=system("wc -l ".restaFile." | awk '{print ($1)}'")
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:($4/1000) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'in progress',\
     ''               index 0 using 1:($3/1000*M) with linespoints pt 7 ps 1 lt 2 lw 1 lc rgb 'green' title 'ready to send '.gprintf('(x%.1f)',1.0/M),\
     ''               index 0 using 1:6 with linespoints axis x1y2 pt 7 ps 1 lt 2 lw 1 lc rgb 'blue' notitle,\
     restartFile index 0 using 1:(ybar) with impulses lt -1 lw 2 notitle,\
     '< paste '.stuckFile.' '.restaFile.' | head -n'.nLines index 0 using 1:(0.5*ybar):1:3 with xerrorbars lt -1 lw 1 notitle

unset grid
set grid ytics lt 0 lw 1
replot
unset grid
set grid y2tics lt 0 lw 1 lc rgb 'blue'
replot
unset multiplot
# set y2range [*:*]

# credit
currTitle='credit'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/creditOverview'.rightNowPNG.'.png'
} else {
set term qt 1 title currTitle size xSizeWdw,2*ySizeWdw
}
set title currTitle
set key inside horizontal bottom center
set ylabel 'with recent credit [10^3]' tc rgb 'red'
set ytics nomirror tc rgb 'red'
set y2label 'with credit [10^3]' tc rgb 'blue'
set y2tics tc rgb 'blue'
set grid xtics ytics lt 0 lw 1 lc rgb 'black'
set multiplot layout 2,1
fact=1E3
#
set title 'users'
# set yrange [7.5E3/fact:10E3/fact]
# set y2range [158E3/fact:165E3/fact]
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:($11/fact) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'users with recent credit',\
     ''               index 0 using 1:($10/fact) with linespoints axis x1y2 pt 7 ps 1 lt 1 lw 1 lc rgb 'blue' title 'users with credit'
set title 'computers'
# set yrange [21E3/fact:25E3/fact]
# set y2range [450E3/fact:470E3/fact]
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:($14/fact) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'hosts with recent credit',\
     ''               index 0 using 1:($13/fact) with linespoints axis x1y2 pt 7 ps 1 lt 1 lw 1 lc rgb 'blue' title 'hosts with credit'
# set yrange [*:*]
# set y2range [*:*]
unset multiplot
set key inside horizontal top center

# gigaflops
currTitle='TeraFLOPs'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/teraFLOPsOverview'.rightNowPNG.'.png'
} else {
set term qt 2 title currTitle size xSizeWdw,ySizeWdw
}
set title currTitle
set key outside horizontal
set ylabel 'TeraFLOPs []' tc rgb 'black'
set ytics mirror tc rgb 'black'
unset y2label
unset y2tics
set grid xtics ytics lt 0 lw 1 lc rgb 'black'
# set yrange [70:155]
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:($16/1000) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' notitle
# set yrange [*:*]
unset title

# WUs waiting for validation
currTitle='Validation'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/validationOverview'.rightNowPNG.'.png'
} else {
set term qt 3 title currTitle size xSizeWdw,ySizeWdw
}
set title currTitle
set key outside horizontal
set ylabel 'WUs waiting for validation []' tc rgb 'black'
set ytics mirror tc rgb 'black'
unset y2label
unset y2tics
set grid xtics ytics lt 0 lw 1 lc rgb 'black'
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:5 with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' notitle
unset title

# ------------------------------------------------------------------------------
# sixtrack
# ------------------------------------------------------------------------------
currTitle='SixTrack app'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/sixtrackOverview'.rightNowPNG.'.png'
} else {
set term qt 4 title currTitle size xSizeWdw,ySizeWdw
}
set multiplot title currTitle
set key outside horizontal
set ylabel 'tasks in progress/unsent [10^3]'
set ytics nomirror
set y2label 'users in last 24h' tc rgb 'blue'
set y2tics tc rgb 'blue'
set xtics rotate by 90 right
set grid xtics lt 0 lw 1
plot \
     '< cat ????-??/SixTrack_status_????-??.dat' index 0 using 1:($4/1000) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'in progress',\
     ''               index 0 using 1:($3/1000*M) with linespoints pt 7 ps 1 lt 2 lw 1 lc rgb 'green' title 'ready to send '.gprintf('(x%.1f)',1.0/M),\
     ''               index 0 using 1:5 with linespoints axis x1y2 pt 7 ps 1 lt 2 lw 1 lc rgb 'blue' notitle
unset grid
set grid ytics lt 0 lw 1
replot
unset grid
set grid y2tics lt 0 lw 1 lc rgb 'blue'
replot
unset multiplot

# ------------------------------------------------------------------------------
# sixtracktest
# ------------------------------------------------------------------------------
currTitle='sixtracktest app'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/sixtracktestOverview'.rightNowPNG.'.png'
} else {
set term qt 5 title currTitle size xSizeWdw,ySizeWdw
}
set multiplot title currTitle
set key outside horizontal
set ylabel 'tasks in progress/unsent [10^3]'
set ytics nomirror
set y2label 'users in last 24h' tc rgb 'blue'
set y2tics tc rgb 'blue'
set xtics rotate by 90 right
set grid xtics lt 0 lw 1
plot \
     '< cat ????-??/sixtracktest_status_????-??.dat' index 0 using 1:($4/1000) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'in progress',\
     ''               index 0 using 1:($3/1000*M) with linespoints pt 7 ps 1 lt 2 lw 1 lc rgb 'green' title 'ready to send '.gprintf('(x%.1f)',1.0/M),\
     ''               index 0 using 1:5 with linespoints axis x1y2 pt 7 ps 1 lt 2 lw 1 lc rgb 'blue' notitle
unset grid
set grid ytics lt 0 lw 1
replot
unset grid
set grid y2tics lt 0 lw 1 lc rgb 'blue'
replot
unset multiplot

reset

# changes in status page:
# - 2018-02-26: old server actually switched off on 2018-02-06;
#   -> new status page has slightly different order of table lines;
#   -> swapping $10 and $11, and $13 and $14;

restartFile='/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/general-activity/restart.txt'
stuckFile='../assimilatorStuck.txt'
restaFile='../assimilatorRestart.txt'

set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
# set format x '%b %Y'
set format x '%Y-%m-%d'
# set format x '%Y-%m-%d %H:%M'
# set xtics 365.2425 / 12 * 24 * 3600 rotate by 90 right
set xtics 3600*24 rotate by 90 right
set grid xtics lt 0 lw 1
# tMin=strptime("%Y-%m-%d %H:%M:%S","2019-06-01 00:00:00")
# tMax=strptime("%Y-%m-%d %H:%M:%S","2019-08-01 00:00:00")
# use bash's date command, since gnuplot's time(0.0) returns UTC time stamps,
#     and logging is in GVA local time
tNow=strptime("%Y-%m-%d %H:%M:%S",system('date +"%F %T"'))
tMax=tNow+1*24*3600
tMin=tNow-45*24*3600
set xrange [tMin:tMax]
ybar=300
M=0.1
# typical enlarged window size: 1900,400
# trigger use of png or interactive windows: 0: png, 1: interactive
linteractive=0
lprintDate=0 # 0: no date/time in png name; 1: date/time in png name
xSizeWdw=1600#regular: 1000
ySizeWdw=600#regular: 400

if ( lprintDate==0 ) {
rightNowPNG=''
} else {
rightNowPNG=system('date +"_%F_%H-%M-%S"')
}

# ------------------------------------------------------------------------------
# general overview of server status
# ------------------------------------------------------------------------------
currTitle='server overview'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/serverOverview'.rightNowPNG.'.png'
} else {
set term qt 0 title currTitle size xSizeWdw,ySizeWdw
}
set multiplot title currTitle
set key outside horizontal
set ylabel 'tasks in progress/ready to send [10^3]'
set ytics nomirror
set y2label 'tasks waiting for assimilation' tc rgb 'blue'
set y2tics tc rgb 'blue'
# set y2range [0:*]
nLines=system("wc -l ".restaFile." | awk '{print ($1)}'")
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:($4/1000) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'in progress',\
     ''               index 0 using 1:($3/1000*M) with linespoints pt 7 ps 1 lt 2 lw 1 lc rgb 'green' title 'ready to send '.gprintf('(x%.1f)',1.0/M),\
     ''               index 0 using 1:6 with linespoints axis x1y2 pt 7 ps 1 lt 2 lw 1 lc rgb 'blue' notitle,\
     restartFile index 0 using 1:(ybar) with impulses lt -1 lw 2 notitle,\
     '< paste '.stuckFile.' '.restaFile.' | head -n'.nLines index 0 using 1:(0.5*ybar):1:3 with xerrorbars lt -1 lw 1 notitle

unset grid
set grid ytics lt 0 lw 1
replot
unset grid
set grid y2tics lt 0 lw 1 lc rgb 'blue'
replot
unset multiplot
# set y2range [*:*]

# credit
currTitle='credit'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/creditOverview'.rightNowPNG.'.png'
} else {
set term qt 1 title currTitle size xSizeWdw,2*ySizeWdw
}
set title currTitle
set key inside horizontal top center
set ylabel 'recent credit [10^3]' tc rgb 'red'
set ytics nomirror tc rgb 'red'
set y2label 'total credit [10^3]' tc rgb 'blue'
set y2tics tc rgb 'blue'
set grid xtics ytics lt 0 lw 1 lc rgb 'black'
set multiplot layout 2,1
fact=1E3
#
set title 'users'
# set yrange [7.5E3/fact:10E3/fact]
# set y2range [158E3/fact:165E3/fact]
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:($11/fact) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'with recent credit',\
     ''               index 0 using 1:($10/fact) with linespoints axis x1y2 pt 7 ps 1 lt 1 lw 1 lc rgb 'blue' title 'with credit'
set title 'computers'
# set yrange [21E3/fact:25E3/fact]
# set y2range [450E3/fact:470E3/fact]
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:($14/fact) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'with recent credit',\
     ''               index 0 using 1:($13/fact) with linespoints axis x1y2 pt 7 ps 1 lt 1 lw 1 lc rgb 'blue' title 'with credit'
# set yrange [*:*]
# set y2range [*:*]
unset multiplot

# gigaflops
currTitle='TeraFLOPs'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/teraFLOPsOverview'.rightNowPNG.'.png'
} else {
set term qt 2 title currTitle size xSizeWdw,ySizeWdw
}
set title currTitle
set key outside horizontal
set ylabel 'TeraFLOPs []' tc rgb 'black'
set ytics mirror tc rgb 'black'
unset y2label
unset y2tics
set grid xtics ytics lt 0 lw 1 lc rgb 'black'
# set yrange [70:155]
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:($16/1000) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' notitle
# set yrange [*:*]
unset title

# WUs waiting for validation
currTitle='Validation'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/validationOverview'.rightNowPNG.'.png'
} else {
set term qt 3 title currTitle size xSizeWdw,ySizeWdw
}
set title currTitle
set key outside horizontal
set ylabel 'WUs waiting for validation []' tc rgb 'black'
set ytics mirror tc rgb 'black'
unset y2label
unset y2tics
set grid xtics ytics lt 0 lw 1 lc rgb 'black'
plot \
     '< cat ????-??/server_status_????-??.dat' index 0 using 1:5 with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' notitle
unset title

# ------------------------------------------------------------------------------
# sixtrack
# ------------------------------------------------------------------------------
currTitle='SixTrack app'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/sixtrackOverview'.rightNowPNG.'.png'
} else {
set term qt 4 title currTitle size xSizeWdw,ySizeWdw
}
set multiplot title currTitle
set key outside horizontal
set ylabel 'tasks in progress/unsent [10^3]'
set ytics nomirror
set y2label 'users in last 24h' tc rgb 'blue'
set y2tics tc rgb 'blue'
set xtics rotate by 90 right
set grid xtics lt 0 lw 1
plot \
     '< cat ????-??/SixTrack_status_????-??.dat' index 0 using 1:($4/1000) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'in progress',\
     ''               index 0 using 1:($3/1000*M) with linespoints pt 7 ps 1 lt 2 lw 1 lc rgb 'green' title 'ready to send '.gprintf('(x%.1f)',1.0/M),\
     ''               index 0 using 1:5 with linespoints axis x1y2 pt 7 ps 1 lt 2 lw 1 lc rgb 'blue' notitle
unset grid
set grid ytics lt 0 lw 1
replot
unset grid
set grid y2tics lt 0 lw 1 lc rgb 'blue'
replot
unset multiplot

# ------------------------------------------------------------------------------
# sixtracktest
# ------------------------------------------------------------------------------
currTitle='sixtracktest app'
if ( linteractive==0 ) {
set term png size xSizeWdw,ySizeWdw notransparent enhanced
set output '/afs/cern.ch/work/s/sixtadm/public/monitor_activity/boinc_software/monitor-boinc-server/boincStatus/sixtracktestOverview'.rightNowPNG.'.png'
} else {
set term qt 5 title currTitle size xSizeWdw,ySizeWdw
}
set multiplot title currTitle
set key outside horizontal
set ylabel 'tasks in progress/unsent [10^3]'
set ytics nomirror
set y2label 'users in last 24h' tc rgb 'blue'
set y2tics tc rgb 'blue'
set xtics rotate by 90 right
set grid xtics lt 0 lw 1
plot \
     '< cat ????-??/sixtracktest_status_????-??.dat' index 0 using 1:($4/1000) with linespoints pt 7 ps 1 lt 1 lw 1 lc rgb 'red' title 'in progress',\
     ''               index 0 using 1:($3/1000*M) with linespoints pt 7 ps 1 lt 2 lw 1 lc rgb 'green' title 'ready to send '.gprintf('(x%.1f)',1.0/M),\
     ''               index 0 using 1:5 with linespoints axis x1y2 pt 7 ps 1 lt 2 lw 1 lc rgb 'blue' notitle
unset grid
set grid ytics lt 0 lw 1
replot
unset grid
set grid y2tics lt 0 lw 1 lc rgb 'blue'
replot
unset multiplot


consider various multiplot formats for visualisation

set term epscairo enhanced truecolor font "Helvetica,14" size 8.6cm,6cm

set output outfile

set multiplot title titletext

set style line 1 lc rgb "red" pt 7 ps 0.2
set style line 2 lc rgb "blue" pt 7 ps 0.2
set style line 3 lc rgb "black" pt 7 ps 0.2

#set xl "Time/s"
set yl "Temperature/{/Symbol \260}C"

set xl offset 0,0.3 font ",10"
set yl offset 1.2,0 font ",10"

set xtics font ",8"
set ytics font ",8"

set size 1,0.5
set origin 0,0.45

set key font ",8"
plot filename u 1:2 ls 1 title "onboard", filename u 1:4 ls 2 title "external probe"

set size 1,0.5
set origin 0,0
set xl "Time/s"
set yl "Relative Humidity/%"
plot filename u 1:3 ls 3 notitle

set term epscairo enhanced truecolor font "Helvetica,14" size 8.6cm,6cm

set output outfile

set multiplot title titletext

set style line 1 lc rgb "red" pt 7 ps 0.2
set style line 2 lc rgb "blue" pt 7 ps 0.2
set style line 3 lc rgb "black" pt 7 ps 0.2

#set xl "Time/s"
set yl "Temperature/{/Symbol \260}C"

set xl offset 0,0.3 font ",10"
set yl offset 1.2,0 font ",10"

set xtics font ",8"
set ytics font ",8"

set size 1,0.5
set origin 0,0.45

plot filename u 1:2 ls 1 notitle, filename u 1:4 ls 2 notitle

set size 1,0.5
set origin 0,0
set xl "Time/s"
set yl "Relative Humidity/%"
plot filename u 1:3 ls 3 notitle


Add second point to reveal secret curve.

set terminal png transparent nointerlace \
    font "lucon.ttf,20" \
    size 1920,1080 nocrop \
    noenhanced \
    background '#FFFFFF'

set output "linear-2.png"
set encoding utf8

set style line 101 linetype 1 linewidth 5 linecolor rgbcolor '#000000'
set style line 102 linetype 2 linewidth 4 linecolor rgbcolor '#999999'
set style line 103 linetype 3 linewidth 4 linecolor rgbcolor '#A00000'
set style line 104 linetype 4 linewidth 4 linecolor rgbcolor '#FF0000'
set style line 105 linetype 5 linewidth 4 linecolor rgbcolor '#007000'
set style line 106 linetype 6 linewidth 6 linecolor rgbcolor '#00FF00'
set style line 107 linetype 7 linewidth 4 linecolor rgbcolor '#0000A0'
set style line 108 linetype 8 linewidth 4 linecolor rgbcolor '#1E90FF'
set style line 109 linetype 9 linewidth 4 linecolor rgbcolor '#A020F0'

set key off

# TODO: set origin and size as options or calculate.
set origin 0.02,0
set size 0.98,1
set ytics
set xtics
set border
set colorbox
set xrange [-20:-14]
set grid xtics
set mxtics
set xlabel "x" font "lucon.ttf,30"

set grid ytics
set mytics
set my2tics
set ylabel "f(x)" font "lucon.ttf,30"
#set ytics nomirror
#set y2tics nomirror
set label 1 "2005-2017 © eigenholser" \
    at screen 0.99,0.014 right font "times.ttf,12"
set label 2 "f(x) = 4x + 42" at screen 0.21,0.865 left font "times.ttf,30"
set label 3 "f(x) = α(x + 17) - 26" at screen 0.21,0.830 left font "times.ttf,30"
set title "Linear polynomials passing through point (-17,-26)" font "lucon.ttf,30"

# Greek α symbol is U03B1
f(x) = 4.0*x + 42
x1 = -17
x2 = -15
set style line 1 pointtype 7 linecolor rgb '#000000' pointsize 4
plot \
    (-89.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-55.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-34.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-21.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-13.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (13.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (21.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (34.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (55.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (89.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    f(x) axes x1y1 not with lines linestyle 106, \
    '+' using ($0 == 0 ? x1 : NaN):(f(x1)):(sprintf('(%.1d,%.1d)', x1, f(x1))) \
    with labels offset char -3,2 left textcolor rgb 'blue' \
    point linestyle 1 notitle, \
    '+' using ($0 == 0 ? x2 : NaN):(f(x2)):(sprintf('(%.1d,%.1d)', x2, f(x2))) \
    with labels offset char 1,-1.2 left textcolor rgb 'blue' \
    point linestyle 1 notitle

set terminal png transparent nointerlace \
    font "lucon.ttf,20" \
    size 1920,1080 nocrop \
    noenhanced \
    background '#FFFFFF'

set output "linear-2.png"
set encoding utf8

set style line 101 linetype 1 linewidth 5 linecolor rgbcolor '#000000'
set style line 102 linetype 2 linewidth 4 linecolor rgbcolor '#999999'
set style line 103 linetype 3 linewidth 4 linecolor rgbcolor '#A00000'
set style line 104 linetype 4 linewidth 4 linecolor rgbcolor '#FF0000'
set style line 105 linetype 5 linewidth 4 linecolor rgbcolor '#007000'
set style line 106 linetype 6 linewidth 6 linecolor rgbcolor '#00FF00'
set style line 107 linetype 7 linewidth 4 linecolor rgbcolor '#0000A0'
set style line 108 linetype 8 linewidth 4 linecolor rgbcolor '#1E90FF'
set style line 109 linetype 9 linewidth 4 linecolor rgbcolor '#A020F0'

set key off

# TODO: set origin and size as options or calculate.
set origin 0.02,0
set size 0.98,1
set ytics
set xtics
set border
set colorbox
set xrange [-20:-14]
set grid xtics
set mxtics
set xlabel "x" font "lucon.ttf,30"

set grid ytics
set mytics
set my2tics
set ylabel "f(x)" font "lucon.ttf,30"
#set ytics nomirror
#set y2tics nomirror
set label 1 "2005-2017 © eigenholser" \
    at screen 0.99,0.014 right font "times.ttf,12"
set label 2 "f(x) = 4x + 42" at screen 0.21,0.865 left font "times.ttf,30"
set label 3 "f(x) = α(x + 17) - 26" at screen 0.21,0.830 left font "times.ttf,30"
set title "Linear polynomials passing through point (-17,-26)" font "lucon.ttf,30"

# Greek α symbol is U03B1
f(x) = 4.0*x + 42
x1 = -17
set style line 1 pointtype 7 linecolor rgb '#000000' pointsize 4
plot \
    (-89.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-55.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-34.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-21.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (-13.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (13.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (21.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (34.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (55.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    (89.0*(x + 17) - 26) axes x1y1 not with lines linestyle 102, \
    f(x) axes x1y1 not with lines linestyle 106, \
    '+' using ($0 == 0 ? x1 : NaN):(f(x1)):(sprintf('(%.1d,%.1d)', x1, f(x1))) \
    with labels offset char -2,2.5 left textcolor rgb 'blue' \
    point linestyle 1 notitle


Bump font size of traffic graphs

Bump font size of traffic graphs