autodetect Mac OS X when creating make.settings.local

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

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

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_MCSTL	?= no	# will be overriden from main Makefile
USE_ICPC	?= no	# will be overriden from main Makefile

STXXL_ROOT	?= $(HOME)/work/stxxl

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_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		?= -O3 # compiler optimization level
WARNINGS	?= -W -Wall
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

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

#### 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 #########################################

# check, whether stxxl has been configured
ifeq (,$(strip $(wildcard $(STXXL_ROOT)/include/stxxl.h)))
$(warning *** WARNING: STXXL has not been configured correctly)
ifeq (,$(strip $(wildcard $(CURDIR)/make.settings.local)))
ifneq (,$(strip $(wildcard $(CURDIR)/include/stxxl.h)))
$(warning *** WARNING: trying autoconfiguration for STXXL_ROOT=$(CURDIR:$(HOME)%=$$(HOME)%))
$(warning *** WARNING: you did not have a make.settings.local file -- creating ...)
$(shell echo 'STXXL_ROOT	 = $(CURDIR:$(HOME)%=$$(HOME)%)' >> $(CURDIR)/make.settings.local)
MCSTL_ROOT	?= $(HOME)/work/mcstl
$(shell echo '#MCSTL_ROOT	 = $(MCSTL_ROOT:$(HOME)%=$$(HOME)%)' >> $(CURDIR)/make.settings.local)
$(shell echo '#COMPILER_GCC	 = g++-4.2.3' >> $(CURDIR)/make.settings.local)
$(shell echo '#COMPILER_ICPC	 = icpc' >> $(CURDIR)/make.settings.local)
ifeq (Darwin,$(strip $(shell uname)))
$(shell echo 'USE_MACOSX	 = yes' >> $(CURDIR)/make.settings.local)
else
$(shell echo '#USE_MACOSX	 = no' >> $(CURDIR)/make.settings.local)
endif
$(error ERROR: Please check make.settings.local and try again)
endif
else
$(warning *** WARNING: Please check make.settings.local)
endif
$(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) \
	-DSORT_OPTIMAL_PREFETCHING \
	-DUSE_MALLOC_LOCK \
	-DCOUNT_WAIT_TIME \
	-I$(strip $(STXXL_ROOT))/include \
	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE \
	$(POSIX_MEMALIGN) $(XOPEN_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

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

#### 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__ $(MCSTL_INCLUDES_PREPEND) -I$(MCSTL_ROOT)/c++
MCSTL_LDFLAGS		+= $(OPENMPFLAG)

MCSTL_INCLUDES_PREPEND	+= $(if $(findstring 4.3,$(COMPILER)),-I$(MCSTL_ROOT)/c++/mod_stl/gcc-4.3)

endif

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

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

BOOST_COMPILER_OPTIONS	 = \
	-DSTXXL_BOOST_TIMESTAMP \
	-DSTXXL_BOOST_CONFIG \
	-DSTXXL_BOOST_FILESYSTEM \
	-DSTXXL_BOOST_THREADS \
	-DSTXXL_BOOST_RANDOM \
	$(if $(strip $(BOOST_ROOT)),-I$(strip $(BOOST_ROOT)))

BOOST_LIB_COMPILER_SUFFIX	?=
BOOST_LIB_MT_SUFFIX		?= -mt
BOOST_LINKER_OPTIONS		 = \
	-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_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_auto_ptr.h

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

HEADER_FILES_IO		+= completion_handler.h io.h iobase.h iostats.h
HEADER_FILES_IO		+= mmap_file.h simdisk_file.h syscall_file.h
HEADER_FILES_IO		+= ufs_file.h wincall_file.h wfs_file.h boostfd_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	+= write_pool.h prefetch_pool.h

HEADER_FILES_CONTAINERS	+= pager.h stack.h vector.h priority_queue.h queue.h
HEADER_FILES_CONTAINERS	+= 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 interleaved_alloc.h ksort.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 ###########################################

DEPS_MAKEFILES	:= $(wildcard ../Makefile.subdir.gnu ../make.settings ../make.settings.local GNUmakefile Makefile.local)
%.$o: %.cpp $(DEPS_MAKEFILES)
	@$(RM) $@ $*.$d
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -MD -MF $*.$dT -c $(OUTPUT_OPTION) $< && mv $*.$dT $*.$d

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

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

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

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

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_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.

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_MCSTL	?= no	# will be overriden from main Makefile
USE_ICPC	?= no	# will be overriden from main Makefile

STXXL_ROOT	?= $(HOME)/work/stxxl

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_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		?= -O3 # compiler optimization level
WARNINGS	?= -W -Wall
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

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

#### 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 #########################################

# check, whether stxxl has been configured
ifeq (,$(strip $(wildcard $(STXXL_ROOT)/include/stxxl.h)))
$(warning *** WARNING: STXXL has not been configured correctly)
ifeq (,$(strip $(wildcard $(CURDIR)/make.settings.local)))
ifneq (,$(strip $(wildcard $(CURDIR)/include/stxxl.h)))
$(warning *** WARNING: trying autoconfiguration for STXXL_ROOT=$(CURDIR:$(HOME)%=$$(HOME)%))
$(warning *** WARNING: you did not have a make.settings.local file -- creating ...)
$(shell echo 'STXXL_ROOT	 = $(CURDIR:$(HOME)%=$$(HOME)%)' >> $(CURDIR)/make.settings.local)
MCSTL_ROOT	?= $(HOME)/work/mcstl
$(shell echo '#MCSTL_ROOT	 = $(MCSTL_ROOT:$(HOME)%=$$(HOME)%)' >> $(CURDIR)/make.settings.local)
$(shell echo '#COMPILER_GCC	 = g++-4.2.3' >> $(CURDIR)/make.settings.local)
$(shell echo '#COMPILER_ICPC	 = icpc' >> $(CURDIR)/make.settings.local)
$(shell echo '#USE_MACOSX	 = no' >> $(CURDIR)/make.settings.local)
$(error ERROR: Please check make.settings.local and try again)
endif
else
$(warning *** WARNING: Please check make.settings.local)
endif
$(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) \
	-DSORT_OPTIMAL_PREFETCHING \
	-DUSE_MALLOC_LOCK \
	-DCOUNT_WAIT_TIME \
	-I$(strip $(STXXL_ROOT))/include \
	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE \
	$(POSIX_MEMALIGN) $(XOPEN_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

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

#### 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__ $(MCSTL_INCLUDES_PREPEND) -I$(MCSTL_ROOT)/c++
MCSTL_LDFLAGS		+= $(OPENMPFLAG)

MCSTL_INCLUDES_PREPEND	+= $(if $(findstring 4.3,$(COMPILER)),-I$(MCSTL_ROOT)/c++/mod_stl/gcc-4.3)

endif

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

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

BOOST_COMPILER_OPTIONS	 = \
	-DSTXXL_BOOST_TIMESTAMP \
	-DSTXXL_BOOST_CONFIG \
	-DSTXXL_BOOST_FILESYSTEM \
	-DSTXXL_BOOST_THREADS \
	-DSTXXL_BOOST_RANDOM \
	$(if $(strip $(BOOST_ROOT)),-I$(strip $(BOOST_ROOT)))

BOOST_LIB_COMPILER_SUFFIX	?=
BOOST_LIB_MT_SUFFIX		?= -mt
BOOST_LINKER_OPTIONS		 = \
	-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_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_auto_ptr.h

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

HEADER_FILES_IO		+= completion_handler.h io.h iobase.h iostats.h
HEADER_FILES_IO		+= mmap_file.h simdisk_file.h syscall_file.h
HEADER_FILES_IO		+= ufs_file.h wincall_file.h wfs_file.h boostfd_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	+= write_pool.h prefetch_pool.h

HEADER_FILES_CONTAINERS	+= pager.h stack.h vector.h priority_queue.h queue.h
HEADER_FILES_CONTAINERS	+= 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 interleaved_alloc.h ksort.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 ###########################################

DEPS_MAKEFILES	:= $(wildcard ../Makefile.subdir.gnu ../make.settings ../make.settings.local GNUmakefile Makefile.local)
%.$o: %.cpp $(DEPS_MAKEFILES)
	@$(RM) $@ $*.$d
	$(COMPILER) $(STXXL_COMPILER_OPTIONS) -MD -MF $*.$dT -c $(OUTPUT_OPTION) $< && mv $*.$dT $*.$d

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

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

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

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

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_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


Update plotter script

Update plotter script

#!/usr/bin/env gnuplot
set term postscript enhanced color 20

set log xy
se gri
set xlabel "mini-region memory footprint(MB)"
set ylabel "load bandwidth (GB/s)"
set arrow from 40,10 to 40,1000 nohead lc 2
set arrow from 4,10 to 4,1000 nohead lc 2
set arrow from 0.5,10 to 0.5,1000 nohead lc 2
set label 4 at first 100,12 "Memory"
set label 3 at first 10,12 "L3"
set label 2 at first 1,12 "L2"
set label 1 at first 0.1,12 "L1"
set yrange[10:1000]
set out "benchmark-saya-saya.eps"
plot 'benchmark-saya-saya.txt' u (8*4*$2*$3*$4/2**20):($16)  t ""
set out "benchmark-saya-bara.eps"
plot 'benchmark-saya-bara.txt' u (8*2*$1*$2*$3*$4/2**20):($13)  t ""
set out "benchmark-standalone.eps"
plot 'benchmark-standalone.txt' u (8*2*$1*$2*$3*$4/2**20):($13)  t ""


cumulative average graph

cumulative average graph

set key left box
set title "Average Cumulative Insert Time"
set xlabel "Unique Items"
set ylabel "Seconds"
set xrange [0:1024]
set terminal png size 800, 600
set output "insert-cumulative-example.png"
plot "./std-set-example-1024-30.dat" with lines lc rgb "green" title "trie", "./std-unordered_set-example-1024-30.dat" with lines lc rgb "red" title "hash table"

set key left box
set title "Cumulative Insert Time"
set xlabel "Unique Items"
set ylabel "Seconds"
set xrange [0:1024]
set terminal png size 800, 600
set output "insert-cumulative-example.png"
plot "./std-set-example-1024-30.dat" with lines lc rgb "green" title "trie", "./std-unordered_set-example-1024-30.dat" with lines lc rgb "red" title "hash table"


Removing plt

Removing plt


Adjusted plot for numbers >15000, added goal line, fixed timezone issue

set term png truecolor size 820,500 font "Helvetica, 13pt"
set title "Spendenanzahl Krautreporter, Stand: ". system("TZ='Europe/Berlin' date +'%a, %H:%M:%S Uhr'")
set grid xtics
set grid ytics
set output "krautcounter.png"

# set ad day-month
set xdata time
# parse timestamp
set timefmt "%s"
set format x "%d.%m, %H:%M"
# tic with 1 day
#set xtic '+str(60*60*24*1))
set xtic 60*60*6
#set xtic 1
set xlabel "Zeitpunkt (CEST)"
set autoscale x

# Freitag Abend
set xrange ["1402584745":"1402704000"]
# Donnerstag Abend
#set xrange ["1402584745":"1402617600"]
# zoom
#set xrange ["1402656165":"1402704000"]

set ytic 1000
set ylabel "Anzahl"
set yrange [10000:16000]

set key left top inside horizontal

set style fill solid 1.0
set style data boxes

plot "krautcounter.data" using ($1+7200):2 title "Spenden", 15000 title "Ziel"

set key center bottom outside horizontal

set output "krautcounter2.png"
set ytic 500
set xtic 60*60*3
set term png truecolor size 1600,800 font "Helvetica, 13pt"
plot "krautcounter.data" using ($1+7200):2 title "Spenden", 15000 title "Ziel"

set output "krautcounter3.png"

set y2tic 1000
set y2range [-4.218215e+07:-4.217715e07]
set format y2 ""
set grid noy2tics

y(x) = 112*((x+1402584745)/(60*60))-100000000
#fit y(x) 'krautcounter2.data' using ($1+7200):2 via m
plot "krautcounter.data" using ($1+7200):2 title "Spenden", y(x) title "Vorhersage" axes x1y2

set term png truecolor size 820,400 font "Helvetica, 13pt"
set title "Spendenanzahl Krautreporter, Stand: ". system("date +'%a, %H:%M:%S Uhr'")
set grid xtics
set grid ytics
set output "krautcounter.png"

# set ad day-month
set xdata time
# parse timestamp
set timefmt "%s"
set format x "%d.%m, %H:%M"
# tic with 1 day
#set xtic '+str(60*60*24*1))
set xtic 60*60*6
#set xtic 1
set xlabel "Zeitpunkt (CEST)"
set autoscale x

# Freitag Abend
set xrange ["1402584745":"1402704000"]
# Donnerstag Abend
#set xrange ["1402584745":"1402617600"]

set ytic 1000
set ylabel "Anzahl"
set yrange [10000:15000]

set key left top inside horizontal

set style fill solid 1.0
set style data boxes

plot "krautcounter.data" using ($1+7200):2 title "Spenden"

set key center bottom outside horizontal

set output "krautcounter2.png"
set ytic 500
set xtic 60*60*3
set term png truecolor size 1600,800 font "Helvetica, 13pt"
plot "krautcounter.data" using ($1+7200):2 title "Spenden"#, y(x) title "Vorhersage" axes x1y2

set output "krautcounter3.png"

set y2tic 1000
set y2range [-4.218215e+07:-4.217715e07]
set format y2 ""
set grid noy2tics

y(x) = 112*((x+1402584745)/(60*60))-100000000
#fit y(x) 'krautcounter2.data' using ($1+7200):2 via m
plot "krautcounter.data" using ($1+7200):2 title "Spenden", y(x) title "Vorhersage" axes x1y2


Started some document predicates.

Started some document predicates.

:- include(misc(common)).

database('prolongo_test').
collection('testcoll').
database_dot_collection('prolongo_test.testcoll').

ms_since_epoch(MilliSeconds) :-
    core:get_time(FloatSeconds),
    FloatMilliSeconds is FloatSeconds * 1000,
    MilliSeconds is floor(FloatMilliSeconds).

%%  doc_get(+Doc, +Key, ?Value) is semidet.
%
%   True if Value is the value associated with Key in Doc,
%   or @(null) if the Key cannot be found. This means that there
%   is no way of knowing if it actually was @(null) or not found.

doc_get([], _, @(null)).
doc_get([K-V|_], K, V) :- !.
doc_get([_|Pairs], K, V) :-
    doc_get(Pairs, K, V).

%%  doc_put(+Doc, +Key, +Value, ?NewDoc) is semidet.
%
%   True if NewDoc is Doc with the addition or update of the pair
%   Key-Value.

doc_put([], K, V, [K-V]).
doc_put([K-_|Pairs], K, V, [K-V|Pairs]) :- !.
doc_put([Other|Pairs], K, V, [Other|Pairs1]) :-
    doc_put(Pairs, K, V, Pairs1).

%%  doc_delete(+Doc, +Key, ?NewDoc) is semidet.
%
%   True if NewDoc is Doc with the first pair with Key as
%   key removed. No change if Key cannot be found.

doc_delete([], _, []).
doc_delete([K-_|Pairs], K, Pairs) :- !.
doc_delete([Other|Pairs], K, [Other|Pairs1]) :-
    doc_delete(Pairs, K, Pairs1).

:- begin_tests('mongo:insert/3').

test('insert',
[
    setup(mongo:new_mongo(Mongo)),
    cleanup(mongo:free_mongo(Mongo))
]) :-
    ms_since_epoch(MilliSeconds),
    Document =
    [
        hello - [åäö,5.05],
        now   - utc(MilliSeconds)
    ],
    database_dot_collection(DbDotColl),
    mongo:insert(Mongo, Document, DbDotColl).

:- end_tests('mongo:insert/3').

:- begin_tests('mongo:command/3').

test('drop collection',
[
    setup(mongo:new_mongo(Mongo)),
    cleanup(mongo:free_mongo(Mongo))
]) :-
    Command =
    [
        drop - Coll
    ],
    collection(Coll),
    database(Db),
    mongo:command(Mongo, Command, Db, Result),
    doc_get(Result, ok, 1.0).

/*
% Takes a bit too long when MongoDB reallocates the collection later.
test('drop database',
[
    setup(mongo:new_mongo(Mongo)),
    cleanup(mongo:free_mongo(Mongo))
]) :-
    Command =
    [
        dropDatabase - 1
    ],
    database(Db),
    mongo:command(Mongo, Command, Db).
*/

:- end_tests('mongo:command/3').

:- include(misc(common)).

database('prolongo_test').
collection('testcoll').
database_dot_collection('prolongo_test.testcoll').

ms_since_epoch(MilliSeconds) :-
    core:get_time(FloatSeconds),
    FloatMilliSeconds is FloatSeconds * 1000,
    MilliSeconds is floor(FloatMilliSeconds).

doc_value([], _Key, null).
doc_value([Key-Value|_Pairs], Key, Value) :- !.
doc_value([_Pair|Pairs], Key, Value) :-
    doc_value(Pairs, Key, Value).

:- begin_tests('mongo:insert/3').

test('insert',
[
    setup(mongo:new_mongo(Mongo)),
    cleanup(mongo:free_mongo(Mongo))
]) :-
    ms_since_epoch(MilliSeconds),
    Document =
    [
        hello - [åäö,5.05],
        now   - utc(MilliSeconds)
    ],
    database_dot_collection(DbDotColl),
    mongo:insert(Mongo, Document, DbDotColl).

:- end_tests('mongo:insert/3').

:- begin_tests('mongo:command/3').

test('drop collection',
[
    setup(mongo:new_mongo(Mongo)),
    cleanup(mongo:free_mongo(Mongo))
]) :-
    Command =
    [
        drop - Coll
    ],
    collection(Coll),
    database(Db),
    mongo:command(Mongo, Command, Db, Result),
    doc_value(Result, ok, 1.0).

/*
% Takes a bit too long when MongoDB reallocates the collection later.
test('drop database',
[
    setup(mongo:new_mongo(Mongo)),
    cleanup(mongo:free_mongo(Mongo))
]) :-
    Command =
    [
        dropDatabase - 1
    ],
    database(Db),
    mongo:command(Mongo, Command, Db).
*/

:- end_tests('mongo:command/3').


More UTs on http_headers_v

More UTs on http_headers_v

:- begin_tests(http_headers_v).
:- use_module(http_headers_v).

test(http_headers_list_obj_bug1) :-

   List = [ 'Location' = 'http : //www . facebook . com/unsupportedbrowser',
            'P3P' = 'CP= " Facebook   does   not   have   a   P3P   policy .   Learn   why   here :   http : //fb . me/p3p "',
            'X-Content-Type-Options' = nosniff,
            'X-Frame-Options' = 'DENY',
            'Set-Cookie' = 'datr=KEqyTzuMCfz1GhP8w26-BZg7 ;   expires=Thu ,   15-May-2014   12 : 20 : 56   GMT ;   path=/ ;   domain= . facebook . com ;   httponly',
            'Set-Cookie' = 'lsd=AVqm9Avf ;   path=/ ;   domain= . facebook . com',
            'Content-Type' = 'text/html ;   charset=utf-8',
            'X-FB-Debug' = 'f+bKUUtzin/3WCNVE3tWLoNB0ksWI1iaPqSmhhrIdpk=',
            'Date' = 'Tue ,   15   May   2012   12 : 20 : 56   GMT',
            'Content-Length' = '0',
            'Connection' = close
          ],
   http_headers_list_obj(List, _).

test(list_to_http_headers_v1) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              transfer_encoding = chunked],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_general_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(list_to_http_headers_v2) :-

   Headers = ['DatE' = 'Tue, 03 Apr 2012 19:32:50 GMT',
              'Transfer-Encoding' = chunked],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_general_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(list_to_http_headers_v_functor_form) :-

   Headers = [date('Tue, 03 Apr 2012 19:32:50 GMT'),
              transfer_encoding(chunked)],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_general_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(list_to_http_headers_v_functor_form2) :-

   Headers = ['DatE'('Tue, 03 Apr 2012 19:32:50 GMT'),
              'Transfer-Encoding'(chunked)],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_general_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(list_to_http_request_headers_v1) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              accept = 'text/html',
              host = 'kogorta.dp.ua',
              transfer_encoding = chunked
              ],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Accept' = 'text/html',
                  'Host' = 'kogorta.dp.ua',
                  'Transfer-Encoding' = chunked
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1).

test(list_to_http_request_headers_v2) :-

   Headers = [accept = 'text/html',
              date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              host = 'kogorta.dp.ua',
              transfer_encoding = chunked
              ],
   Headers_Ref = ['Accept' = 'text/html',
                  'Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Host' = 'kogorta.dp.ua',
                  'Transfer-Encoding' = chunked
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1).

test(list_to_http_response_headers_v) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              location = 'http://kogorta.dp.ua/'
              ],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Location' = 'http://kogorta.dp.ua/'
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_response_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1).

test(list_to_http_invalid_mixed_headers_v) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              host = 'kogorta.dp.ua',
              location = 'http://kogorta.dp.ua/',
              transfer_encoding = chunked
              ],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Host' = 'kogorta.dp.ua',
                  'Location' = 'http://kogorta.dp.ua/',
                  'Transfer-Encoding' = chunked
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_response_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1).

test(list_to_http_invalid_bulk_headers_v1) :-

   Headers = [bulk1 = 1, '' = 3],
   Headers_Ref = ['Bulk1' = 1, '' = 3],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk == Headers).

test(list_to_http_invalid_bulk_headers_v2) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              bulk1 = 1,
              transfer_encoding = chunked],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Bulk1' = 1,
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk == [bulk1 = 1]).

test(list_to_http_invalid_bulk_headers_v3) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              accept = 'text/html',
              host = 'kogorta.dp.ua',
              transfer_encoding = chunked,
              bulk1 = 1
              ],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Accept' = 'text/html',
                  'Host' = 'kogorta.dp.ua',
                  'Transfer-Encoding' = chunked,
                  'Bulk1' = 1
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk == [bulk1 = 1]).

test(list_to_http_invalid_bulk_headers_v4) :-

   Headers = [bulk1 = 1,
              date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              accept = 'text/html',
              host = 'kogorta.dp.ua',
              transfer_encoding = chunked
              ],
   Headers_Ref = ['Bulk1' = 1,
                  'Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Accept' = 'text/html',
                  'Host' = 'kogorta.dp.ua',
                  'Transfer-Encoding' = chunked
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk == [bulk1 = 1]).

test(list_to_http_invalid_bulk_headers_v5) :-

   Headers = [bulk1 = 1,
              date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              bulk2 = 2,
              host = 'kogorta.dp.ua',
              bulk3 = 3,
              location = 'http://kogorta.dp.ua/',
              bulk4 = 4,
              transfer_encoding = chunked,
              bulk5 = 5
              ],
   Headers_Ref = ['Bulk1' = 1,
                  'Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Bulk2' = 2,
                  'Host' = 'kogorta.dp.ua',
                  'Bulk3' = 3,
                  'Location' = 'http://kogorta.dp.ua/',
                  'Bulk4' = 4,
                  'Transfer-Encoding' = chunked,
                  'Bulk5' = 5
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_response_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk ==
            [bulk1 = 1, bulk2 = 2, bulk3 = 3,
             bulk4 = 4, bulk5 = 5
            ]).

test(list_to_http_invalid_bulk_headers_v6) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              bulk1 = 1,
              bulk2 = 2,
              host = 'kogorta.dp.ua',
              bulk3 = 3,
              location = 'http://kogorta.dp.ua/',
              bulk4 = 4,
              transfer_encoding = chunked,
              bulk5 = 5
              ],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Bulk1' = 1,
                  'Bulk2' = 2,
                  'Host' = 'kogorta.dp.ua',
                  'Bulk3' = 3,
                  'Location' = 'http://kogorta.dp.ua/',
                  'Bulk4' = 4,
                  'Transfer-Encoding' = chunked,
                  'Bulk5' = 5
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_response_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk ==
            [bulk1 = 1, bulk2 = 2, bulk3 = 3,
             bulk4 = 4, bulk5 = 5
            ]).

test(list_to_http_invalid_bulk_headers_v7) :-

   Headers = [
              date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              host = 'kogorta.dp.ua',
              location = 'http://kogorta.dp.ua/',
              bulk1 = 1,
              bulk2 = 2,
              bulk3 = 3,
              bulk4 = 4,
              transfer_encoding = chunked,
              bulk5 = 5
              ],
   Headers_Ref = [
                  'Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Host' = 'kogorta.dp.ua',
                  'Location' = 'http://kogorta.dp.ua/',
                  'Bulk1' = 1,
                  'Bulk2' = 2,
                  'Bulk3' = 3,
                  'Bulk4' = 4,
                  'Transfer-Encoding' = chunked,
                  'Bulk5' = 5
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_response_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk ==
            [bulk1 = 1, bulk2 = 2, bulk3 = 3,
             bulk4 = 4, bulk5 = 5
            ]).

test(repeated_headers1) :-

   Headers = [accept_language = en,
              accept_language = ru
              ],
   Headers_Ref = ['Accept-Language' = en,
                  'Accept-Language' = ru
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(repeated_headers2) :-

   Headers = [accept_language = 'en, ru'],
   Headers_Ref = ['Accept-Language' = 'en, ru'],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(repeated_headers3) :-

   Headers = [accept_language = [en, ru]],
   Headers_Ref = ['Accept-Language' = [en, ru]],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

:- end_tests(http_headers_v).

:- begin_tests(http_headers_v).
:- use_module(http_headers_v).

test(list_to_http_headers_v1) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              transfer_encoding = chunked],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_general_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(list_to_http_headers_v2) :-

   Headers = ['DatE' = 'Tue, 03 Apr 2012 19:32:50 GMT',
              'Transfer-Encoding' = chunked],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_general_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(list_to_http_headers_v_functor_form) :-

   Headers = [date('Tue, 03 Apr 2012 19:32:50 GMT'),
              transfer_encoding(chunked)],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_general_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(list_to_http_headers_v_functor_form2) :-

   Headers = ['DatE'('Tue, 03 Apr 2012 19:32:50 GMT'),
              'Transfer-Encoding'(chunked)],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_general_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(list_to_http_request_headers_v1) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              accept = 'text/html',
              host = 'kogorta.dp.ua',
              transfer_encoding = chunked
              ],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Accept' = 'text/html',
                  'Host' = 'kogorta.dp.ua',
                  'Transfer-Encoding' = chunked
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1).

test(list_to_http_request_headers_v2) :-

   Headers = [accept = 'text/html',
              date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              host = 'kogorta.dp.ua',
              transfer_encoding = chunked
              ],
   Headers_Ref = ['Accept' = 'text/html',
                  'Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Host' = 'kogorta.dp.ua',
                  'Transfer-Encoding' = chunked
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1).

test(list_to_http_response_headers_v) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              location = 'http://kogorta.dp.ua/'
              ],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Location' = 'http://kogorta.dp.ua/'
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_response_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1).

test(list_to_http_invalid_mixed_headers_v) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              host = 'kogorta.dp.ua',
              location = 'http://kogorta.dp.ua/',
              transfer_encoding = chunked
              ],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Host' = 'kogorta.dp.ua',
                  'Location' = 'http://kogorta.dp.ua/',
                  'Transfer-Encoding' = chunked
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_response_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1).

test(list_to_http_invalid_bulk_headers_v1) :-

   Headers = [bulk1 = 1, '' = 3],
   Headers_Ref = ['Bulk1' = 1, '' = 3],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk == Headers).

test(list_to_http_invalid_bulk_headers_v2) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              bulk1 = 1,
              transfer_encoding = chunked],
   Headers_Ref = ['Date' ='Tue, 03 Apr 2012 19:32:50 GMT',
                  'Bulk1' = 1,
                  'Transfer-Encoding' = chunked],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk == [bulk1 = 1]).

test(list_to_http_invalid_bulk_headers_v3) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              accept = 'text/html',
              host = 'kogorta.dp.ua',
              transfer_encoding = chunked,
              bulk1 = 1
              ],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Accept' = 'text/html',
                  'Host' = 'kogorta.dp.ua',
                  'Transfer-Encoding' = chunked,
                  'Bulk1' = 1
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk == [bulk1 = 1]).

test(list_to_http_invalid_bulk_headers_v4) :-

   Headers = [bulk1 = 1,
              date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              accept = 'text/html',
              host = 'kogorta.dp.ua',
              transfer_encoding = chunked
              ],
   Headers_Ref = ['Bulk1' = 1,
                  'Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Accept' = 'text/html',
                  'Host' = 'kogorta.dp.ua',
                  'Transfer-Encoding' = chunked
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk == [bulk1 = 1]).

test(list_to_http_invalid_bulk_headers_v5) :-

   Headers = [bulk1 = 1,
              date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              bulk2 = 2,
              host = 'kogorta.dp.ua',
              bulk3 = 3,
              location = 'http://kogorta.dp.ua/',
              bulk4 = 4,
              transfer_encoding = chunked,
              bulk5 = 5
              ],
   Headers_Ref = ['Bulk1' = 1,
                  'Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Bulk2' = 2,
                  'Host' = 'kogorta.dp.ua',
                  'Bulk3' = 3,
                  'Location' = 'http://kogorta.dp.ua/',
                  'Bulk4' = 4,
                  'Transfer-Encoding' = chunked,
                  'Bulk5' = 5
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_response_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk ==
            [bulk1 = 1, bulk2 = 2, bulk3 = 3,
             bulk4 = 4, bulk5 = 5
            ]).

test(list_to_http_invalid_bulk_headers_v6) :-

   Headers = [date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              bulk1 = 1,
              bulk2 = 2,
              host = 'kogorta.dp.ua',
              bulk3 = 3,
              location = 'http://kogorta.dp.ua/',
              bulk4 = 4,
              transfer_encoding = chunked,
              bulk5 = 5
              ],
   Headers_Ref = ['Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Bulk1' = 1,
                  'Bulk2' = 2,
                  'Host' = 'kogorta.dp.ua',
                  'Bulk3' = 3,
                  'Location' = 'http://kogorta.dp.ua/',
                  'Bulk4' = 4,
                  'Transfer-Encoding' = chunked,
                  'Bulk5' = 5
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_response_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk ==
            [bulk1 = 1, bulk2 = 2, bulk3 = 3,
             bulk4 = 4, bulk5 = 5
            ]).

test(list_to_http_invalid_bulk_headers_v7) :-

   Headers = [
              date = 'Tue, 03 Apr 2012 19:32:50 GMT',
              host = 'kogorta.dp.ua',
              location = 'http://kogorta.dp.ua/',
              bulk1 = 1,
              bulk2 = 2,
              bulk3 = 3,
              bulk4 = 4,
              transfer_encoding = chunked,
              bulk5 = 5
              ],
   Headers_Ref = [
                  'Date' = 'Tue, 03 Apr 2012 19:32:50 GMT',
                  'Host' = 'kogorta.dp.ua',
                  'Location' = 'http://kogorta.dp.ua/',
                  'Bulk1' = 1,
                  'Bulk2' = 2,
                  'Bulk3' = 3,
                  'Bulk4' = 4,
                  'Transfer-Encoding' = chunked,
                  'Bulk5' = 5
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [
             http_invalid_bulk_headers_v,
             http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_response_headers_v,
             http_request_headers_v,
             http_general_headers_v,
             http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers20, Obj),
   msort(Headers20, Headers2),
   sort(Headers_Ref, Headers1),
   assertion(Headers2 == Headers1),
   obj_field(Obj, '@bulk', Bulk_Rev),
   reverse(Bulk_Rev, Bulk),
   assertion(Bulk ==
            [bulk1 = 1, bulk2 = 2, bulk3 = 3,
             bulk4 = 4, bulk5 = 5
            ]).

test(repeated_headers1) :-

   Headers = [accept_language = en,
              accept_language = ru
              ],
   Headers_Ref = ['Accept-Language' = en,
                  'Accept-Language' = ru
                 ],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(repeated_headers2) :-

   Headers = [accept_language = 'en, ru'],
   Headers_Ref = ['Accept-Language' = 'en, ru'],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

test(repeated_headers3) :-

   Headers = [accept_language = [en, ru]],
   Headers_Ref = ['Accept-Language' = [en, ru]],
   http_headers_list_obj(Headers, Obj),
   obj_parents(Obj, Parents),
   assertion(Parents ==
            [http_request_headers_v, http_headers_v,
             object_v, object_base_v]),
   http_headers_list_obj(Headers2, Obj),
   assertion(Headers2 == Headers_Ref).

:- end_tests(http_headers_v).


adjustments for graph14

adjustments for graph14

#!/usr/bin/env gnuplot

# graph of memory usage

# datafiles
ifnameh = "/tmp/lnxdiagd/mysql4gnuplot/sql14h.csv"
ifnamed = "/tmp/lnxdiagd/mysql4gnuplot/sql14d.csv"
ifnamew = "/tmp/lnxdiagd/mysql4gnuplot/sql14w.csv"
set output  "/tmp/lnxdiagd/site/img/day14.png"

# ******************************************************* General settings *****
set terminal png enhanced font "Vera,9" size 1280,320
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid front
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
if (GPVAL_VERSION == 4.6) {epoch_compensate = 946684800} else {if (GPVAL_VERSION == 5.0) {epoch_compensate = 0}}
# Positions of split between graphs
LMARG = 0.06
LMPOS = 0.40
MRPOS = 0.73
RMARG = 0.94

min(x,y) = (x < y) ? x : y
max(x,y) = (x > y) ? x : y

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 1 name "X" nooutput
Xh_min = X_min + utc_offset - epoch_compensate
Xh_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here of column 11 (Swap memory used)
stats ifnameh using 6 name "Yh" nooutput

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 1 name "X" nooutput
Xd_min = X_min + utc_offset - epoch_compensate
Xd_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here of column 11 (Swap memory used)
stats ifnameh using 6 name "Yd" nooutput

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 1 name "X" nooutput
Xw_min = X_min + utc_offset - epoch_compensate
Xw_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here of column 11 (Swap memory used)
stats ifnameh using 6 name "Yw" nooutput

Ymax = max(max(Yd_max, Yh_max), Yw_max) * -1

set multiplot layout 1, 3 title "Memory Usage ".strftime("( %Y-%m-%dT%H:%M:%S )", time(0)+utc_offset)

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Usage [%]"
set yrange [ Ymax : ]
set format y "%4.0s%c"

# ***************************************************************** Legend *****
set key opaque box inside top left
set key samplen 0.1
set key reverse horizontal Left
set key maxcols 4

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder

set lmargin at screen LMARG
set rmargin at screen LMPOS

# ***** PLOT *****
set style data boxes
set style fill solid noborder

plot ifnamew \
      using ($1+utc_offset):($2+$3+$4+$5) title "free"    fc rgb "#229922"  \
  ,'' using ($1+utc_offset):($2+$3+$4)    title "cached"  fc "yellow"       \
  ,'' using ($1+utc_offset):($2+$3)       title "buffers" fc "blue"         \
  ,'' using ($1+utc_offset):2             title "used"    fc rgb "#bb0000"  \
  ,'' using ($1+utc_offset):($6*-1)       title "swap"    fc rgb "#ee0000"  \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymax : ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($1+utc_offset):($2+$3+$4+$5) fc rgb "#229922"  \
  ,'' using ($1+utc_offset):($2+$3+$4)    fc "yellow"       \
  ,'' using ($1+utc_offset):($2+$3)       fc "blue"         \
  ,'' using ($1+utc_offset):2             fc rgb "#bb0000"  \
  ,'' using ($1+utc_offset):($6*-1)       fc rgb "#ee0000"  \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]
set xtics textcolor rgb "red"

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymax : ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen MRPOS+0.001
set rmargin at screen RMARG

# ***** PLOT *****
plot ifnameh \
      using ($1+utc_offset):($2+$3+$4+$5) fc rgb "#229922"  \
  ,'' using ($1+utc_offset):($2+$3+$4)    fc "yellow"       \
  ,'' using ($1+utc_offset):($2+$3)       fc "blue"         \
  ,'' using ($1+utc_offset):2             fc rgb "#bb0000"  \
  ,'' using ($1+utc_offset):($6*-1)      fc rgb "#ee0000"  \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot

#!/usr/bin/env gnuplot

# graph of memory usage

# datafiles
ifnameh = "/tmp/lnxdiagd/mysql4gnuplot/sql14h.csv"
ifnamed = "/tmp/lnxdiagd/mysql4gnuplot/sql14d.csv"
ifnamew = "/tmp/lnxdiagd/mysql4gnuplot/sql14w.csv"
set output  "/tmp/lnxdiagd/site/img/day14.png"

# ******************************************************* General settings *****
set terminal png enhanced font "Vera,9" size 1280,320
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid front
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
if (GPVAL_VERSION == 4.6) {epoch_compensate = 946684800} else {if (GPVAL_VERSION == 5.0) {epoch_compensate = 0}}
# Positions of split between graphs
LMARG = 0.06
LMPOS = 0.40
MRPOS = 0.73
RMARG = 0.94

min(x,y) = (x < y) ? x : y
max(x,y) = (x > y) ? x : y

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 2 name "X" nooutput
Xh_min = X_min + utc_offset - epoch_compensate
Xh_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here of column 11 (Swap memory used)
stats ifnameh using 11 name "Yh" nooutput

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 2 name "X" nooutput
Xd_min = X_min + utc_offset - epoch_compensate
Xd_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here of column 11 (Swap memory used)
stats ifnameh using 11 name "Yd" nooutput

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 2 name "X" nooutput
Xw_min = X_min + utc_offset - epoch_compensate
Xw_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here of column 11 (Swap memory used)
stats ifnameh using 11 name "Yw" nooutput

Ymax = max(max(Yd_max, Yh_max), Yw_max) * -1

set multiplot layout 1, 3 title "Memory Usage ".strftime("( %Y-%m-%dT%H:%M:%S )", time(0)+utc_offset)

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Usage [%]"
set yrange [ Ymax : ]
set format y "%4.0s%c"

# ***************************************************************** Legend *****
set key opaque box inside top left
set key samplen 0.1
set key reverse horizontal Left
set key maxcols 4

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder

set lmargin at screen LMARG
set rmargin at screen LMPOS

# ***** PLOT *****
set style data boxes
set style fill solid noborder

plot ifnamew \
      using ($2+utc_offset):($5+$6+$7+$8) title "free"    fc rgb "#229922"  \
  ,'' using ($2+utc_offset):($5+$6+$7)    title "cached"  fc "yellow"       \
  ,'' using ($2+utc_offset):($5+$6)       title "buffers" fc "blue"         \
  ,'' using ($2+utc_offset):5             title "used"    fc rgb "#bb0000"  \
  ,'' using ($2+utc_offset):($11*-1)      title "swap"    fc rgb "#ee0000"  \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymax : ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($2+utc_offset):($5+$6+$7+$8) fc rgb "#229922"  \
  ,'' using ($2+utc_offset):($5+$6+$7)    fc "yellow"       \
  ,'' using ($2+utc_offset):($5+$6)       fc "blue"         \
  ,'' using ($2+utc_offset):5             fc rgb "#bb0000"  \
  ,'' using ($2+utc_offset):($11*-1)      fc rgb "#ee0000"  \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]
set xtics textcolor rgb "red"

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymax : ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen MRPOS+0.001
set rmargin at screen RMARG

# ***** PLOT *****
plot ifnameh \
      using ($2+utc_offset):($5+$6+$7+$8) fc rgb "#229922"  \
  ,'' using ($2+utc_offset):($5+$6+$7)    fc "yellow"       \
  ,'' using ($2+utc_offset):($5+$6)       fc "blue"         \
  ,'' using ($2+utc_offset):5             fc rgb "#bb0000"  \
  ,'' using ($2+utc_offset):($11*-1)      fc rgb "#ee0000"  \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot


Improved CDF plot.

Improved CDF plot.

MPARM = 1
NPARM = 2
KPARM = 3
FLOPS = 8
MEMBW = 9

HIM = -1
HIN = HIM
HIK = HIM
MN = 23
PEAK = 0 #985.6

BASENAME = "cp2k"
FILENAME = system("sh -c \"echo ${FILENAME}\"")
if (FILENAME eq "") {
  FILENAME = BASENAME."-perf.pdf"
}

FILECOUNT = 1 # initial file number
# MULTI =-1: multiple files; no titles
# MULTI = 0: multiple files with titles
# MULTI = 1: single file with titles
MULTI = system("sh -c \"echo ${MULTI}\"")
if (MULTI eq "") {
  MULTI = 1
}

XFLOPS(M, N, K) = 2.0 * M * N * K
NFLOPS(M, N, K) = XFLOPS(column(M), column(N), column(K))
NBYTES(M, N, K, ELEMSIZE) = ELEMSIZE * (column(M) * column(K) + column(K) * column(N) + column(M) * column(N))
AI(M, N, K, ELEMSIZE) = NFLOPS(M, N, K) / NBYTES(M, N, K, ELEMSIZE)

stats BASENAME."-perf.dat" using (column(MPARM)*column(NPARM)*column(KPARM)) nooutput; MNK = STATS_stddev**(1.0/3.0); MAXMNK = int(STATS_max)
stats BASENAME."-perf.dat" using (log(column(FLOPS))) nooutput; GEO = exp(STATS_sum/STATS_records)
stats BASENAME."-perf.dat" using FLOPS nooutput; MED = STATS_median; MINFLOPS = STATS_min; MAXFLOPS = STATS_max
stats BASENAME."-perf.dat" using NPARM nooutput; XN = int(STATS_max)

MAX(A, B) = A < B ? B : A
ACC = sprintf("%%.%if", ceil(MAX(1.0 / log10(MED) - 1.0, 0)))

IX(I1, J1, NJ) = int(MAX(I1 - 1, 0) * NJ + MAX(J1 - 1, 0))
I1(IX, NJ) = int(IX / NJ) + 1
J1(IX, NJ) = int(IX) % NJ + 1

set table BASENAME."-perf-avg.dat"
plot BASENAME."-perf.dat" using (IX(column(MPARM), column(NPARM), XN)):FLOPS smooth unique
unset table
set table BASENAME."-perf-mbw.dat"
plot BASENAME."-perf.dat" using MEMBW:(1.0) smooth cumulative
unset table
set table BASENAME."-perf-cdf.dat"
plot BASENAME."-perf.dat" using FLOPS:(1.0) smooth cumulative
unset table
stats BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?($2):(1/0)) nooutput; FREQSUM = STATS_max; FREQN = STATS_records

if (MULTI==1) {
  set output FILENAME
}

FILEEXT = system("sh -c \"echo ".FILENAME." | sed 's/.\\+\\.\\(.\\+\\)/\\1/'\"")
set terminal FILEEXT
set termoption enhanced
#set termoption font ",12"
save_encoding = GPVAL_ENCODING
set encoding utf8

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance" }
set origin -0.03, 0
set pm3d interpolate 0, 0
#set colorbox horizontal user origin 0, 0.1 size 1, 0.1
#set autoscale fix
if (0<HIM) { set xrange [*:HIM] }
if (0<HIN) { set yrange [*:HIN] }
if (0<HIK) { set zrange [*:HIK] }
if (0>HIM) { set xrange [*:MNK] }
if (0>HIN) { set yrange [*:MNK] }
if (0>HIK) { set zrange [*:MNK] }
set xlabel "M"
set ylabel "N" offset -3.0
set zlabel "K" offset 1.0
set ticslevel 0
set cblabel "GFLOP/s" offset 1.5
set format x "%g"; set format y "%g"; set format z "%g"; set format cb "%g"
splot BASENAME."-perf.dat" using MPARM:NPARM:KPARM:FLOPS notitle with points pointtype 7 linetype palette

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance (K-Average)" }
set origin -0.02, 0
set dgrid3d #9, 9
set pm3d interpolate 0, 0 map
set autoscale fix
set xlabel "M"
set ylabel "N" offset -1.5
set cblabel "GFLOP/s" offset 0.5
set format x "%g"; set format y "%g"; set format cb "%g"
set mxtics 2
splot BASENAME."-perf-avg.dat" using (("".strcol(3)."" eq "i")?(I1($1, XN)):(1/0)):(("".strcol(3)."" eq "i")?(J1($1, XN)):(1/0)):2 notitle with pm3d

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance (Average per Bin)" }
set style fill solid 0.4 noborder
set boxwidth 0.5
set grid y2tics linecolor "grey"
unset key
unset xtics
set xtics ("MNK <= 13^3" 0, "13^3 < MNK <= 23^3" 1, "23^3 < MNK" 2) scale 0 offset 0, 0.2
set x2tics ("Small" 0, "Medium" 1, "Larger" 2) scale 0
set xlabel "Problem Size (MNK)"
set ytics format ""
set y2tics nomirror
set y2label "GFLOP/s"
set xrange [-0.5:2.5]
plot  BASENAME."-perf.dat" \
      using (0.0):((NFLOPS(MPARM,NPARM,KPARM)<=XFLOPS(13,13,13))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey", \
  ""  using (1.0):(((XFLOPS(13,13,13)<NFLOPS(MPARM,NPARM,KPARM))&&(NFLOPS(MPARM,NPARM,KPARM)<=XFLOPS(23,23,23)))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey", \
  ""  using (2.0):((XFLOPS(23,23,23)<NFLOPS(MPARM,NPARM,KPARM))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey"

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance and Memory Bandwidth (CDF)" }
set xlabel "Probability\n\nMin.: ".sprintf(ACC, MINFLOPS)." GFLOP/s  Geo. Mean: ".sprintf(ACC, GEO)." GFLOP/s  Median: ".sprintf(ACC, MED)." GFLOP/s  Max.: ".sprintf(ACC, MAXFLOPS)." GFLOP/s"
set ylabel "GB/s"
set y2label "GFLOP/s"
set format x "%g%%"
set format y "%g"
set format y2 "%g"
set ytics nomirror
set y2tics nomirror
set grid x y2 linecolor "grey"
set xrange [0:100]
set yrange [0:*]
set y2range [0:*]
set fit quiet
f(x) = b * x + a
fit f(x) BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 via a, b
g(x) = (x - a) / b
x50 = 0.5 * (100 + MAX(0, g(0)))
h(x) = d * x + c
dx = 100 / FREQN
fit [x50-1.5*dx:x50+1.5*dx] h(x) BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 via c, d
set arrow from x50, second h(x50) to x50, second 0 front
set arrow from x50, second h(x50) to 100, second h(x50) front
set label sprintf("%.0f%%", x50) at x50, second 0.5 * h(x50) left offset 1 front
set label sprintf(ACC." GFLOP/s", h(x50)) at 0.5 * (x50 + 100.0), second h(x50) centre offset 0, -1 front
set key left invert
plot  BASENAME."-perf-mbw.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 axes x1y1 title "Memory Bandwidth" with lines linecolor "grey", \
      BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 axes x1y2 title "Compute Performance" with lines linewidth 2

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance and Arithmetic Intensity" }
set grid x y2 linecolor "grey"
set key left #spacing 0.5
set ytics format ""
set y2tics nomirror
set y2label "GFLOP/s"
set xlabel "FLOPS/Byte"
plot  BASENAME."-perf.dat" using (AI(MPARM,NPARM,KPARM,8)):FLOPS notitle smooth sbezier with lines linecolor "grey", \
                        "" using (AI(MPARM,NPARM,KPARM,8)):FLOPS notitle smooth unique with points pointtype 7 pointsize 0.1

MPARM = 1
NPARM = 2
KPARM = 3
FLOPS = 8
MEMBW = 9

HIM = -1
HIN = HIM
HIK = HIM
MN = 23
PEAK = 0 #985.6

BASENAME = "cp2k"
FILENAME = system("sh -c \"echo ${FILENAME}\"")
if (FILENAME eq "") {
  FILENAME = BASENAME."-perf.pdf"
}

FILECOUNT = 1 # initial file number
# MULTI =-1: multiple files; no titles
# MULTI = 0: multiple files with titles
# MULTI = 1: single file with titles
MULTI = system("sh -c \"echo ${MULTI}\"")
if (MULTI eq "") {
  MULTI = 1
}

XFLOPS(M, N, K) = 2.0 * M * N * K
NFLOPS(M, N, K) = XFLOPS(column(M), column(N), column(K))
NBYTES(M, N, K, ELEMSIZE) = ELEMSIZE * (column(M) * column(K) + column(K) * column(N) + column(M) * column(N))
AI(M, N, K, ELEMSIZE) = NFLOPS(M, N, K) / NBYTES(M, N, K, ELEMSIZE)

stats BASENAME."-perf.dat" using (column(MPARM)*column(NPARM)*column(KPARM)) nooutput; MNK = STATS_stddev**(1.0/3.0); MAXMNK = int(STATS_max)
stats BASENAME."-perf.dat" using (log(column(FLOPS))) nooutput; GEO = exp(STATS_sum/STATS_records)
stats BASENAME."-perf.dat" using FLOPS nooutput; MED = STATS_median; MINFLOPS = STATS_min; MAXFLOPS = STATS_max
stats BASENAME."-perf.dat" using NPARM nooutput; XN = int(STATS_max)

MAX(A, B) = A < B ? B : A
ACC = sprintf("%%.%if", ceil(MAX(1.0 / log10(MED) - 1.0, 0)))

IX(I1, J1, NJ) = int(MAX(I1 - 1, 0) * NJ + MAX(J1 - 1, 0))
I1(IX, NJ) = int(IX / NJ) + 1
J1(IX, NJ) = int(IX) % NJ + 1

set table BASENAME."-perf-avg.dat"
plot BASENAME."-perf.dat" using (IX(column(MPARM), column(NPARM), XN)):FLOPS smooth unique
unset table
set table BASENAME."-perf-mbw.dat"
plot BASENAME."-perf.dat" using MEMBW:(1.0) smooth cumulative
unset table
set table BASENAME."-perf-cdf.dat"
plot BASENAME."-perf.dat" using FLOPS:(1.0) smooth cumulative
unset table
stats BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?($2):(1/0)) nooutput; FREQSUM = STATS_max; FREQN = STATS_records

if (MULTI==1) {
  set output FILENAME
}

FILEEXT = system("sh -c \"echo ".FILENAME." | sed 's/.\\+\\.\\(.\\+\\)/\\1/'\"")
set terminal FILEEXT
set termoption enhanced
#set termoption font ",12"
save_encoding = GPVAL_ENCODING
set encoding utf8

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance" }
set origin -0.03, 0
set pm3d interpolate 0, 0
#set colorbox horizontal user origin 0, 0.1 size 1, 0.1
#set autoscale fix
if (0<HIM) { set xrange [*:HIM] }
if (0<HIN) { set yrange [*:HIN] }
if (0<HIK) { set zrange [*:HIK] }
if (0>HIM) { set xrange [*:MNK] }
if (0>HIN) { set yrange [*:MNK] }
if (0>HIK) { set zrange [*:MNK] }
set xlabel "M"
set ylabel "N" offset -3.0
set zlabel "K" offset 1.0
set ticslevel 0
set cblabel "GFLOP/s" offset 1.5
set format x "%g"; set format y "%g"; set format z "%g"; set format cb "%g"
splot BASENAME."-perf.dat" using MPARM:NPARM:KPARM:FLOPS notitle with points pointtype 7 linetype palette

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance (K-Average)" }
set origin -0.02, 0
set dgrid3d #9, 9
set pm3d interpolate 0, 0 map
set autoscale fix
set xlabel "M"
set ylabel "N" offset -1.5
set cblabel "GFLOP/s" offset 0.5
set format x "%g"; set format y "%g"; set format cb "%g"
set mxtics 2
splot BASENAME."-perf-avg.dat" using (("".strcol(3)."" eq "i")?(I1($1, XN)):(1/0)):(("".strcol(3)."" eq "i")?(J1($1, XN)):(1/0)):2 notitle with pm3d

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance (Average per Bin)" }
set style fill solid 0.4 noborder
set boxwidth 0.5
set grid y2tics linecolor "grey"
unset key
unset xtics
set xtics ("MNK <= 13^3" 0, "13^3 < MNK <= 23^3" 1, "23^3 < MNK" 2) scale 0 offset 0, 0.2
set x2tics ("Small" 0, "Medium" 1, "Larger" 2) scale 0
set xlabel "Problem Size (MNK)"
set ytics format ""
set y2tics nomirror
set y2label "GFLOP/s"
set xrange [-0.5:2.5]
plot  BASENAME."-perf.dat" \
      using (0.0):((NFLOPS(MPARM,NPARM,KPARM)<=XFLOPS(13,13,13))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey", \
  ""  using (1.0):(((XFLOPS(13,13,13)<NFLOPS(MPARM,NPARM,KPARM))&&(NFLOPS(MPARM,NPARM,KPARM)<=XFLOPS(23,23,23)))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey", \
  ""  using (2.0):((XFLOPS(23,23,23)<NFLOPS(MPARM,NPARM,KPARM))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey"

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance and Memory Bandwidth (CDF)" }
set xlabel "Probability\n\nMin.: ".sprintf(ACC, MINFLOPS)." GFLOP/s  Geo. Mean: ".sprintf(ACC, GEO)." GFLOP/s  Median: ".sprintf(ACC, MED)." GFLOP/s  Max.: ".sprintf(ACC, MAXFLOPS)." GFLOP/s"
set ylabel "GB/s"
set y2label "GFLOP/s"
set format x "%g%%"
set format y "%g"
set format y2 "%g"
set ytics nomirror
set y2tics nomirror
set grid x y2 linecolor "grey"
set xrange [0:100]
set yrange [0:*]
set y2range [0:*]
set fit quiet
f(x) = b * x + a
fit f(x) BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 via a, b
g(x) = (x - a) / b
x50 = 0.5 * (100 + MAX(0, g(0)))
h(x) = d * x + c
dx = 100 / FREQN
fit [x50-1.5*dx:x50+1.5*dx] h(x) BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 via c, d
set arrow from x50, second h(x50) to x50, second 0 front
set arrow from x50, second h(x50) to 100, second h(x50) front
set label sprintf("%.0f%%", x50) at x50, second 0.5 * h(x50) left offset 1 front
set label sprintf(ACC." GFLOP/s", h(x50)) at 0.5 * (x50 + 100.0), second h(x50) centre offset 0, -1 front
plot  BASENAME."-perf-mbw.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 axes x1y1 notitle with lines linecolor "grey", \
      BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 axes x1y2 notitle with lines linewidth 2

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance and Arithmetic Intensity" }
set grid x y2 linecolor "grey"
set key left #spacing 0.5
set ytics format ""
set y2tics nomirror
set y2label "GFLOP/s"
set xlabel "FLOPS/Byte"
plot  BASENAME."-perf.dat" using (AI(MPARM,NPARM,KPARM,8)):FLOPS notitle smooth sbezier with lines linecolor "grey", \
                        "" using (AI(MPARM,NPARM,KPARM,8)):FLOPS notitle smooth unique with points pointtype 7 pointsize 0.1