You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by zu...@apache.org on 2017/02/05 22:03:46 UTC
[48/72] [partial] incubator-quickstep git commit: Make the third
party directory leaner.
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/src/string_util.cc
----------------------------------------------------------------------
diff --git a/third_party/benchmark/src/string_util.cc b/third_party/benchmark/src/string_util.cc
deleted file mode 100644
index 8a8ddd9..0000000
--- a/third_party/benchmark/src/string_util.cc
+++ /dev/null
@@ -1,164 +0,0 @@
-#include "string_util.h"
-
-#include <cmath>
-#include <cstdarg>
-#include <cstdio>
-#include <array>
-#include <memory>
-#include <sstream>
-
-#include "arraysize.h"
-
-// NetBSD's libc has vsnprintf, but it doesn't show up in the std namespace
-// for C++.
-#ifndef __NetBSD__
-using std::vsnprintf;
-#endif
-
-namespace benchmark {
-namespace {
-
-// kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta.
-const char kBigSIUnits[] = "kMGTPEZY";
-// Kibi, Mebi, Gibi, Tebi, Pebi, Exbi, Zebi, Yobi.
-const char kBigIECUnits[] = "KMGTPEZY";
-// milli, micro, nano, pico, femto, atto, zepto, yocto.
-const char kSmallSIUnits[] = "munpfazy";
-
-// We require that all three arrays have the same size.
-static_assert(arraysize(kBigSIUnits) == arraysize(kBigIECUnits),
- "SI and IEC unit arrays must be the same size");
-static_assert(arraysize(kSmallSIUnits) == arraysize(kBigSIUnits),
- "Small SI and Big SI unit arrays must be the same size");
-
-static const int kUnitsSize = arraysize(kBigSIUnits);
-
-} // end anonymous namespace
-
-void ToExponentAndMantissa(double val, double thresh, int precision,
- double one_k, std::string* mantissa,
- int* exponent) {
- std::stringstream mantissa_stream;
-
- if (val < 0) {
- mantissa_stream << "-";
- val = -val;
- }
-
- // Adjust threshold so that it never excludes things which can't be rendered
- // in 'precision' digits.
- const double adjusted_threshold =
- std::max(thresh, 1.0 / std::pow(10.0, precision));
- const double big_threshold = adjusted_threshold * one_k;
- const double small_threshold = adjusted_threshold;
-
- if (val > big_threshold) {
- // Positive powers
- double scaled = val;
- for (size_t i = 0; i < arraysize(kBigSIUnits); ++i) {
- scaled /= one_k;
- if (scaled <= big_threshold) {
- mantissa_stream << scaled;
- *exponent = i + 1;
- *mantissa = mantissa_stream.str();
- return;
- }
- }
- mantissa_stream << val;
- *exponent = 0;
- } else if (val < small_threshold) {
- // Negative powers
- double scaled = val;
- for (size_t i = 0; i < arraysize(kSmallSIUnits); ++i) {
- scaled *= one_k;
- if (scaled >= small_threshold) {
- mantissa_stream << scaled;
- *exponent = -i - 1;
- *mantissa = mantissa_stream.str();
- return;
- }
- }
- mantissa_stream << val;
- *exponent = 0;
- } else {
- mantissa_stream << val;
- *exponent = 0;
- }
- *mantissa = mantissa_stream.str();
-}
-
-std::string ExponentToPrefix(int exponent, bool iec) {
- if (exponent == 0) return "";
-
- const int index = (exponent > 0 ? exponent - 1 : -exponent - 1);
- if (index >= kUnitsSize) return "";
-
- const char* array =
- (exponent > 0 ? (iec ? kBigIECUnits : kBigSIUnits) : kSmallSIUnits);
- if (iec)
- return array[index] + std::string("i");
- else
- return std::string(1, array[index]);
-}
-
-std::string ToBinaryStringFullySpecified(double value, double threshold,
- int precision) {
- std::string mantissa;
- int exponent;
- ToExponentAndMantissa(value, threshold, precision, 1024.0, &mantissa,
- &exponent);
- return mantissa + ExponentToPrefix(exponent, false);
-}
-
-void AppendHumanReadable(int n, std::string* str) {
- std::stringstream ss;
- // Round down to the nearest SI prefix.
- ss << "/" << ToBinaryStringFullySpecified(n, 1.0, 0);
- *str += ss.str();
-}
-
-std::string HumanReadableNumber(double n) {
- // 1.1 means that figures up to 1.1k should be shown with the next unit down;
- // this softens edge effects.
- // 1 means that we should show one decimal place of precision.
- return ToBinaryStringFullySpecified(n, 1.1, 1);
-}
-
-std::string StringPrintFImp(const char *msg, va_list args)
-{
- // we might need a second shot at this, so pre-emptivly make a copy
- va_list args_cp;
- va_copy(args_cp, args);
-
- // TODO(ericwf): use std::array for first attempt to avoid one memory
- // allocation guess what the size might be
- std::array<char, 256> local_buff;
- std::size_t size = local_buff.size();
- auto ret = vsnprintf(local_buff.data(), size, msg, args_cp);
-
- va_end(args_cp);
-
- // handle empty expansion
- if (ret == 0)
- return std::string{};
- if (static_cast<std::size_t>(ret) < size)
- return std::string(local_buff.data());
-
- // we did not provide a long enough buffer on our first attempt.
- // add 1 to size to account for null-byte in size cast to prevent overflow
- size = static_cast<std::size_t>(ret) + 1;
- auto buff_ptr = std::unique_ptr<char[]>(new char[size]);
- ret = vsnprintf(buff_ptr.get(), size, msg, args);
- return std::string(buff_ptr.get());
-}
-
-std::string StringPrintF(const char* format, ...)
-{
- va_list args;
- va_start(args, format);
- std::string tmp = StringPrintFImp(format, args);
- va_end(args);
- return tmp;
-}
-
-} // end namespace benchmark
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/src/string_util.h
----------------------------------------------------------------------
diff --git a/third_party/benchmark/src/string_util.h b/third_party/benchmark/src/string_util.h
deleted file mode 100644
index 6d35da2..0000000
--- a/third_party/benchmark/src/string_util.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#ifndef BENCHMARK_STRING_UTIL_H_
-#define BENCHMARK_STRING_UTIL_H_
-
-#include <string>
-#include <sstream>
-#include <utility>
-
-namespace benchmark {
-
-void AppendHumanReadable(int n, std::string* str);
-
-std::string HumanReadableNumber(double n);
-
-std::string StringPrintF(const char* format, ...);
-
-inline std::ostream&
-StringCatImp(std::ostream& out) noexcept
-{
- return out;
-}
-
-template <class First, class ...Rest>
-inline std::ostream&
-StringCatImp(std::ostream& out, First&& f, Rest&&... rest)
-{
- out << std::forward<First>(f);
- return StringCatImp(out, std::forward<Rest>(rest)...);
-}
-
-template<class ...Args>
-inline std::string StrCat(Args&&... args)
-{
- std::ostringstream ss;
- StringCatImp(ss, std::forward<Args>(args)...);
- return ss.str();
-}
-
-} // end namespace benchmark
-
-#endif // BENCHMARK_STRING_UTIL_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/src/sysinfo.cc
----------------------------------------------------------------------
diff --git a/third_party/benchmark/src/sysinfo.cc b/third_party/benchmark/src/sysinfo.cc
deleted file mode 100644
index ee3c238..0000000
--- a/third_party/benchmark/src/sysinfo.cc
+++ /dev/null
@@ -1,354 +0,0 @@
-// Copyright 2015 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "sysinfo.h"
-
-#include <fcntl.h>
-#include <sys/resource.h>
-#include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
-#include <sys/sysctl.h>
-#include <sys/time.h>
-#include <unistd.h>
-
-#include <cerrno>
-#include <cstdio>
-#include <cstdint>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <limits>
-#include <mutex>
-
-#include "arraysize.h"
-#include "check.h"
-#include "cycleclock.h"
-#include "internal_macros.h"
-#include "sleep.h"
-
-namespace benchmark {
-namespace {
-std::once_flag cpuinfo_init;
-double cpuinfo_cycles_per_second = 1.0;
-int cpuinfo_num_cpus = 1; // Conservative guess
-std::mutex cputimens_mutex;
-
-#if !defined OS_MACOSX
-const int64_t estimate_time_ms = 1000;
-
-// Helper function estimates cycles/sec by observing cycles elapsed during
-// sleep(). Using small sleep time decreases accuracy significantly.
-int64_t EstimateCyclesPerSecond() {
- const int64_t start_ticks = cycleclock::Now();
- SleepForMilliseconds(estimate_time_ms);
- return cycleclock::Now() - start_ticks;
-}
-#endif
-
-#if defined OS_LINUX || defined OS_CYGWIN
-// Helper function for reading an int from a file. Returns true if successful
-// and the memory location pointed to by value is set to the value read.
-bool ReadIntFromFile(const char* file, long* value) {
- bool ret = false;
- int fd = open(file, O_RDONLY);
- if (fd != -1) {
- char line[1024];
- char* err;
- memset(line, '\0', sizeof(line));
- CHECK(read(fd, line, sizeof(line) - 1));
- const long temp_value = strtol(line, &err, 10);
- if (line[0] != '\0' && (*err == '\n' || *err == '\0')) {
- *value = temp_value;
- ret = true;
- }
- close(fd);
- }
- return ret;
-}
-#endif
-
-void InitializeSystemInfo() {
-#if defined OS_LINUX || defined OS_CYGWIN
- char line[1024];
- char* err;
- long freq;
-
- bool saw_mhz = false;
-
- // If the kernel is exporting the tsc frequency use that. There are issues
- // where cpuinfo_max_freq cannot be relied on because the BIOS may be
- // exporintg an invalid p-state (on x86) or p-states may be used to put the
- // processor in a new mode (turbo mode). Essentially, those frequencies
- // cannot always be relied upon. The same reasons apply to /proc/cpuinfo as
- // well.
- if (!saw_mhz &&
- ReadIntFromFile("/sys/devices/system/cpu/cpu0/tsc_freq_khz", &freq)) {
- // The value is in kHz (as the file name suggests). For example, on a
- // 2GHz warpstation, the file contains the value "2000000".
- cpuinfo_cycles_per_second = freq * 1000.0;
- saw_mhz = true;
- }
-
- // If CPU scaling is in effect, we want to use the *maximum* frequency,
- // not whatever CPU speed some random processor happens to be using now.
- if (!saw_mhz &&
- ReadIntFromFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq",
- &freq)) {
- // The value is in kHz. For example, on a 2GHz warpstation, the file
- // contains the value "2000000".
- cpuinfo_cycles_per_second = freq * 1000.0;
- saw_mhz = true;
- }
-
- // Read /proc/cpuinfo for other values, and if there is no cpuinfo_max_freq.
- const char* pname = "/proc/cpuinfo";
- int fd = open(pname, O_RDONLY);
- if (fd == -1) {
- perror(pname);
- if (!saw_mhz) {
- cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
- }
- return;
- }
-
- double bogo_clock = 1.0;
- bool saw_bogo = false;
- long max_cpu_id = 0;
- int num_cpus = 0;
- line[0] = line[1] = '\0';
- size_t chars_read = 0;
- do { // we'll exit when the last read didn't read anything
- // Move the next line to the beginning of the buffer
- const size_t oldlinelen = strlen(line);
- if (sizeof(line) == oldlinelen + 1) // oldlinelen took up entire line
- line[0] = '\0';
- else // still other lines left to save
- memmove(line, line + oldlinelen + 1, sizeof(line) - (oldlinelen + 1));
- // Terminate the new line, reading more if we can't find the newline
- char* newline = strchr(line, '\n');
- if (newline == NULL) {
- const size_t linelen = strlen(line);
- const size_t bytes_to_read = sizeof(line) - 1 - linelen;
- CHECK(bytes_to_read > 0); // because the memmove recovered >=1 bytes
- chars_read = read(fd, line + linelen, bytes_to_read);
- line[linelen + chars_read] = '\0';
- newline = strchr(line, '\n');
- }
- if (newline != NULL) *newline = '\0';
-
- // When parsing the "cpu MHz" and "bogomips" (fallback) entries, we only
- // accept postive values. Some environments (virtual machines) report zero,
- // which would cause infinite looping in WallTime_Init.
- if (!saw_mhz && strncasecmp(line, "cpu MHz", sizeof("cpu MHz") - 1) == 0) {
- const char* freqstr = strchr(line, ':');
- if (freqstr) {
- cpuinfo_cycles_per_second = strtod(freqstr + 1, &err) * 1000000.0;
- if (freqstr[1] != '\0' && *err == '\0' && cpuinfo_cycles_per_second > 0)
- saw_mhz = true;
- }
- } else if (strncasecmp(line, "bogomips", sizeof("bogomips") - 1) == 0) {
- const char* freqstr = strchr(line, ':');
- if (freqstr) {
- bogo_clock = strtod(freqstr + 1, &err) * 1000000.0;
- if (freqstr[1] != '\0' && *err == '\0' && bogo_clock > 0)
- saw_bogo = true;
- }
- } else if (strncasecmp(line, "processor", sizeof("processor") - 1) == 0) {
- num_cpus++; // count up every time we see an "processor :" entry
- const char* freqstr = strchr(line, ':');
- if (freqstr) {
- const long cpu_id = strtol(freqstr + 1, &err, 10);
- if (freqstr[1] != '\0' && *err == '\0' && max_cpu_id < cpu_id)
- max_cpu_id = cpu_id;
- }
- }
- } while (chars_read > 0);
- close(fd);
-
- if (!saw_mhz) {
- if (saw_bogo) {
- // If we didn't find anything better, we'll use bogomips, but
- // we're not happy about it.
- cpuinfo_cycles_per_second = bogo_clock;
- } else {
- // If we don't even have bogomips, we'll use the slow estimation.
- cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
- }
- }
- if (num_cpus == 0) {
- fprintf(stderr, "Failed to read num. CPUs correctly from /proc/cpuinfo\n");
- } else {
- if ((max_cpu_id + 1) != num_cpus) {
- fprintf(stderr,
- "CPU ID assignments in /proc/cpuinfo seems messed up."
- " This is usually caused by a bad BIOS.\n");
- }
- cpuinfo_num_cpus = num_cpus;
- }
-
-#elif defined OS_FREEBSD
-// For this sysctl to work, the machine must be configured without
-// SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0
-// and later. Before that, it's a 32-bit quantity (and gives the
-// wrong answer on machines faster than 2^32 Hz). See
-// http://lists.freebsd.org/pipermail/freebsd-i386/2004-November/001846.html
-// But also compare FreeBSD 7.0:
-// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG70#L223
-// 231 error = sysctl_handle_quad(oidp, &freq, 0, req);
-// To FreeBSD 6.3 (it's the same in 6-STABLE):
-// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG6#L131
-// 139 error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
-#if __FreeBSD__ >= 7
- uint64_t hz = 0;
-#else
- unsigned int hz = 0;
-#endif
- size_t sz = sizeof(hz);
- const char* sysctl_path = "machdep.tsc_freq";
- if (sysctlbyname(sysctl_path, &hz, &sz, NULL, 0) != 0) {
- fprintf(stderr, "Unable to determine clock rate from sysctl: %s: %s\n",
- sysctl_path, strerror(errno));
- cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
- } else {
- cpuinfo_cycles_per_second = hz;
- }
-// TODO: also figure out cpuinfo_num_cpus
-
-#elif defined OS_WINDOWS
-#pragma comment(lib, "shlwapi.lib") // for SHGetValue()
- // In NT, read MHz from the registry. If we fail to do so or we're in win9x
- // then make a crude estimate.
- OSVERSIONINFO os;
- os.dwOSVersionInfoSize = sizeof(os);
- DWORD data, data_size = sizeof(data);
- if (GetVersionEx(&os) && os.dwPlatformId == VER_PLATFORM_WIN32_NT &&
- SUCCEEDED(
- SHGetValueA(HKEY_LOCAL_MACHINE,
- "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
- "~MHz", NULL, &data, &data_size)))
- cpuinfo_cycles_per_second = (int64)data * (int64)(1000 * 1000); // was mhz
- else
- cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
-// TODO: also figure out cpuinfo_num_cpus
-
-#elif defined OS_MACOSX
- // returning "mach time units" per second. the current number of elapsed
- // mach time units can be found by calling uint64 mach_absolute_time();
- // while not as precise as actual CPU cycles, it is accurate in the face
- // of CPU frequency scaling and multi-cpu/core machines.
- // Our mac users have these types of machines, and accuracy
- // (i.e. correctness) trumps precision.
- // See cycleclock.h: CycleClock::Now(), which returns number of mach time
- // units on Mac OS X.
- mach_timebase_info_data_t timebase_info;
- mach_timebase_info(&timebase_info);
- double mach_time_units_per_nanosecond =
- static_cast<double>(timebase_info.denom) /
- static_cast<double>(timebase_info.numer);
- cpuinfo_cycles_per_second = mach_time_units_per_nanosecond * 1e9;
-
- int num_cpus = 0;
- size_t size = sizeof(num_cpus);
- int numcpus_name[] = {CTL_HW, HW_NCPU};
- if (::sysctl(numcpus_name, arraysize(numcpus_name), &num_cpus, &size, 0, 0) ==
- 0 &&
- (size == sizeof(num_cpus)))
- cpuinfo_num_cpus = num_cpus;
-
-#else
- // Generic cycles per second counter
- cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
-#endif
-}
-} // end namespace
-
-#ifndef OS_WINDOWS
-// getrusage() based implementation of MyCPUUsage
-static double MyCPUUsageRUsage() {
- struct rusage ru;
- if (getrusage(RUSAGE_SELF, &ru) == 0) {
- return (static_cast<double>(ru.ru_utime.tv_sec) +
- static_cast<double>(ru.ru_utime.tv_usec) * 1e-6 +
- static_cast<double>(ru.ru_stime.tv_sec) +
- static_cast<double>(ru.ru_stime.tv_usec) * 1e-6);
- } else {
- return 0.0;
- }
-}
-
-static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
- static int cputime_fd = -1;
- if (cputime_fd == -1) {
- cputime_fd = open("/proc/self/cputime_ns", O_RDONLY);
- if (cputime_fd < 0) {
- cputime_fd = -1;
- return false;
- }
- }
- char buff[64];
- memset(buff, 0, sizeof(buff));
- if (pread(cputime_fd, buff, sizeof(buff) - 1, 0) <= 0) {
- close(cputime_fd);
- cputime_fd = -1;
- return false;
- }
- unsigned long long result = strtoull(buff, NULL, 0);
- if (result == (std::numeric_limits<unsigned long long>::max)()) {
- close(cputime_fd);
- cputime_fd = -1;
- return false;
- }
- *cputime = static_cast<double>(result) / 1e9;
- return true;
-}
-
-double MyCPUUsage() {
- {
- std::lock_guard<std::mutex> l(cputimens_mutex);
- static bool use_cputime_ns = true;
- if (use_cputime_ns) {
- double value;
- if (MyCPUUsageCPUTimeNsLocked(&value)) {
- return value;
- }
- // Once MyCPUUsageCPUTimeNsLocked fails once fall back to getrusage().
- std::cout << "Reading /proc/self/cputime_ns failed. Using getrusage().\n";
- use_cputime_ns = false;
- }
- }
- return MyCPUUsageRUsage();
-}
-
-double ChildrenCPUUsage() {
- struct rusage ru;
- if (getrusage(RUSAGE_CHILDREN, &ru) == 0) {
- return (static_cast<double>(ru.ru_utime.tv_sec) +
- static_cast<double>(ru.ru_utime.tv_usec) * 1e-6 +
- static_cast<double>(ru.ru_stime.tv_sec) +
- static_cast<double>(ru.ru_stime.tv_usec) * 1e-6);
- } else {
- return 0.0;
- }
-}
-#endif // OS_WINDOWS
-
-double CyclesPerSecond(void) {
- std::call_once(cpuinfo_init, InitializeSystemInfo);
- return cpuinfo_cycles_per_second;
-}
-
-int NumCPUs(void) {
- std::call_once(cpuinfo_init, InitializeSystemInfo);
- return cpuinfo_num_cpus;
-}
-} // end namespace benchmark
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/src/sysinfo.h
----------------------------------------------------------------------
diff --git a/third_party/benchmark/src/sysinfo.h b/third_party/benchmark/src/sysinfo.h
deleted file mode 100644
index f9f63ee..0000000
--- a/third_party/benchmark/src/sysinfo.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef BENCHMARK_SYSINFO_H_
-#define BENCHMARK_SYSINFO_H_
-
-namespace benchmark {
-double MyCPUUsage();
-double ChildrenCPUUsage();
-int NumCPUs();
-double CyclesPerSecond();
-} // end namespace benchmark
-
-#endif // BENCHMARK_SYSINFO_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/src/walltime.cc
----------------------------------------------------------------------
diff --git a/third_party/benchmark/src/walltime.cc b/third_party/benchmark/src/walltime.cc
deleted file mode 100644
index 39c0497..0000000
--- a/third_party/benchmark/src/walltime.cc
+++ /dev/null
@@ -1,191 +0,0 @@
-// Copyright 2015 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "walltime.h"
-
-#include <sys/time.h>
-
-#include <cstdio>
-#include <cstdint>
-#include <cstring>
-#include <ctime>
-
-#include <atomic>
-#include <limits>
-#include <type_traits>
-
-#include "check.h"
-#include "cycleclock.h"
-#include "sysinfo.h"
-
-namespace benchmark {
-namespace walltime {
-namespace {
-
-bool SplitTimezone(WallTime value, bool local, struct tm* t,
- double* subsecond) {
- memset(t, 0, sizeof(*t));
- if ((value < 0) || (value > std::numeric_limits<time_t>::max())) {
- *subsecond = 0.0;
- return false;
- }
- const time_t whole_time = static_cast<time_t>(value);
- *subsecond = value - whole_time;
- if (local)
- localtime_r(&whole_time, t);
- else
- gmtime_r(&whole_time, t);
- return true;
-}
-
-} // end anonymous namespace
-
-
-namespace {
-
-class WallTimeImp
-{
-public:
- WallTime Now();
-
- static WallTimeImp& GetWallTimeImp() {
- static WallTimeImp imp;
-#if __cplusplus >= 201103L
- static_assert(std::is_trivially_destructible<WallTimeImp>::value,
- "WallTimeImp must be trivially destructible to prevent "
- "issues with static destruction");
-#endif
- return imp;
- }
-
-private:
- WallTimeImp();
- // Helper routines to load/store a float from an AtomicWord. Required because
- // g++ < 4.7 doesn't support std::atomic<float> correctly. I cannot wait to
- // get rid of this horror show.
- void SetDrift(float f) {
- int32_t w;
- memcpy(&w, &f, sizeof(f));
- std::atomic_store(&drift_adjust_, w);
- }
-
- float GetDrift() const {
- float f;
- int32_t w = std::atomic_load(&drift_adjust_);
- memcpy(&f, &w, sizeof(f));
- return f;
- }
-
- WallTime Slow() const {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_sec + tv.tv_usec * 1e-6;
- }
-
-private:
- static_assert(sizeof(float) <= sizeof(int32_t),
- "type sizes don't allow the drift_adjust hack");
-
- static constexpr double kMaxErrorInterval = 100e-6;
-
- WallTime base_walltime_;
- int64_t base_cycletime_;
- int64_t cycles_per_second_;
- double seconds_per_cycle_;
- uint32_t last_adjust_time_;
- std::atomic<int32_t> drift_adjust_;
- int64_t max_interval_cycles_;
-
- BENCHMARK_DISALLOW_COPY_AND_ASSIGN(WallTimeImp);
-};
-
-
-WallTime WallTimeImp::Now() {
- WallTime now = 0.0;
- WallTime result = 0.0;
- int64_t ct = 0;
- uint32_t top_bits = 0;
- do {
- ct = cycleclock::Now();
- int64_t cycle_delta = ct - base_cycletime_;
- result = base_walltime_ + cycle_delta * seconds_per_cycle_;
-
- top_bits = static_cast<uint32_t>(uint64_t(ct) >> 32);
- // Recompute drift no more often than every 2^32 cycles.
- // I.e., @2GHz, ~ every two seconds
- if (top_bits == last_adjust_time_) { // don't need to recompute drift
- return result + GetDrift();
- }
-
- now = Slow();
- } while (cycleclock::Now() - ct > max_interval_cycles_);
- // We are now sure that "now" and "result" were produced within
- // kMaxErrorInterval of one another.
-
- SetDrift(now - result);
- last_adjust_time_ = top_bits;
- return now;
-}
-
-
-WallTimeImp::WallTimeImp()
- : base_walltime_(0.0), base_cycletime_(0),
- cycles_per_second_(0), seconds_per_cycle_(0.0),
- last_adjust_time_(0), drift_adjust_(0),
- max_interval_cycles_(0) {
- cycles_per_second_ = static_cast<int64_t>(CyclesPerSecond());
- CHECK(cycles_per_second_ != 0);
- seconds_per_cycle_ = 1.0 / cycles_per_second_;
- max_interval_cycles_ =
- static_cast<int64_t>(cycles_per_second_ * kMaxErrorInterval);
- do {
- base_cycletime_ = cycleclock::Now();
- base_walltime_ = Slow();
- } while (cycleclock::Now() - base_cycletime_ > max_interval_cycles_);
- // We are now sure that "base_walltime" and "base_cycletime" were produced
- // within kMaxErrorInterval of one another.
-
- SetDrift(0.0);
- last_adjust_time_ = static_cast<uint32_t>(uint64_t(base_cycletime_) >> 32);
-}
-
-} // end anonymous namespace
-
-
-WallTime Now()
-{
- static WallTimeImp& imp = WallTimeImp::GetWallTimeImp();
- return imp.Now();
-}
-
-std::string Print(WallTime time, const char* format, bool local,
- int* remainder_us) {
- char storage[32];
- struct tm split;
- double subsecond;
- if (!SplitTimezone(time, local, &split, &subsecond)) {
- snprintf(storage, sizeof(storage), "Invalid time: %f", time);
- } else {
- if (remainder_us != NULL) {
- *remainder_us = static_cast<int>((subsecond * 1000000) + 0.5);
- if (*remainder_us > 999999) *remainder_us = 999999;
- if (*remainder_us < 0) *remainder_us = 0;
- }
- strftime(storage, sizeof(storage), format, &split);
- }
- return std::string(storage);
-}
-
-} // end namespace walltime
-} // end namespace benchmark
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/src/walltime.h
----------------------------------------------------------------------
diff --git a/third_party/benchmark/src/walltime.h b/third_party/benchmark/src/walltime.h
deleted file mode 100644
index d4a4fce..0000000
--- a/third_party/benchmark/src/walltime.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef BENCHMARK_WALLTIME_H_
-#define BENCHMARK_WALLTIME_H_
-
-#include <string>
-
-namespace benchmark {
-typedef double WallTime;
-
-namespace walltime {
-WallTime Now();
-
-// GIVEN: walltime, generic format string (as understood by strftime),
-// a boolean flag specifying if the time is local or UTC (true=local).
-// RETURNS: the formatted string. ALSO RETURNS: the remaining number of
-// microseconds (never printed in the string since strftime does not understand
-// it)
-std::string Print(WallTime time, const char *format, bool local,
- int *remainder_us);
-} // end namespace walltime
-} // end namespace benchmark
-
-#endif // BENCHMARK_WALLTIME_H_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/third_party/benchmark/test/CMakeLists.txt b/third_party/benchmark/test/CMakeLists.txt
deleted file mode 100644
index 5d4721b..0000000
--- a/third_party/benchmark/test/CMakeLists.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-# Enable the tests
-
-find_package(Threads REQUIRED)
-
-macro(compile_benchmark_test name)
- add_executable(${name} "${name}.cc")
- target_link_libraries(${name} benchmark ${CMAKE_THREAD_LIBS_INIT})
-endmacro(compile_benchmark_test)
-
-# Demonstration executable
-compile_benchmark_test(benchmark_test)
-add_test(benchmark benchmark_test --benchmark_min_time=0.1)
-
-compile_benchmark_test(filter_test)
-add_test(filter_simple filter_test --benchmark_filter=Calculate 16)
-add_test(filter_suffix filter_test --benchmark_filter=Calculate* 16)
-add_test(filter_regex_all filter_test --benchmark_filter=.* 16)
-add_test(filter_regex_blank filter_test --benchmark_filter= 16)
-add_test(filter_regex_none filter_test --benchmark_filter=monkey 0)
-add_test(filter_regex_wildcard filter_test --benchmark_filter=.*Calculate.* 16)
-add_test(filter_regex_begin filter_test --benchmark_filter=^BM_Calculate.* 16)
-add_test(filter_regex_end filter_test --benchmark_filter=.*Pi$ 8)
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/test/benchmark_test.cc
----------------------------------------------------------------------
diff --git a/third_party/benchmark/test/benchmark_test.cc b/third_party/benchmark/test/benchmark_test.cc
deleted file mode 100644
index 2ce1001..0000000
--- a/third_party/benchmark/test/benchmark_test.cc
+++ /dev/null
@@ -1,169 +0,0 @@
-#include "benchmark/benchmark.h"
-
-#include <assert.h>
-#include <math.h>
-#include <stdint.h>
-
-#include <iostream>
-#include <limits>
-#include <list>
-#include <map>
-#include <mutex>
-#include <set>
-#include <sstream>
-#include <string>
-#include <vector>
-
-#if defined(__GNUC__)
-# define BENCHMARK_NOINLINE __attribute__((noinline))
-#else
-# define BENCHMARK_NOINLINE
-#endif
-
-namespace {
-
-int BENCHMARK_NOINLINE Factorial(uint32_t n) {
- return (n == 1) ? 1 : n * Factorial(n - 1);
-}
-
-double CalculatePi(int depth) {
- double pi = 0.0;
- for (int i = 0; i < depth; ++i) {
- double numerator = static_cast<double>(((i % 2) * 2) - 1);
- double denominator = static_cast<double>((2 * i) - 1);
- pi += numerator / denominator;
- }
- return (pi - 1.0) * 4;
-}
-
-std::set<int> ConstructRandomSet(int size) {
- std::set<int> s;
- for (int i = 0; i < size; ++i)
- s.insert(i);
- return s;
-}
-
-std::mutex test_vector_mu;
-std::vector<int>* test_vector = nullptr;
-
-} // end namespace
-
-static void BM_Factorial(benchmark::State& state) {
- int fac_42 = 0;
- while (state.KeepRunning())
- fac_42 = Factorial(8);
- // Prevent compiler optimizations
- std::cout << fac_42;
-}
-BENCHMARK(BM_Factorial);
-
-static void BM_FactorialRealTime(benchmark::State& state) {
- benchmark::UseRealTime();
-
- int fac_42 = 0;
- while (state.KeepRunning())
- fac_42 = Factorial(8);
- // Prevent compiler optimizations
- std::cout << fac_42;
-}
-BENCHMARK(BM_FactorialRealTime);
-
-static void BM_CalculatePiRange(benchmark::State& state) {
- double pi = 0.0;
- while (state.KeepRunning())
- pi = CalculatePi(state.range_x());
- std::stringstream ss;
- ss << pi;
- state.SetLabel(ss.str());
-}
-BENCHMARK_RANGE(BM_CalculatePiRange, 1, 1024 * 1024);
-
-static void BM_CalculatePi(benchmark::State& state) {
- static const int depth = 1024;
- double pi BENCHMARK_UNUSED = 0.0;
- while (state.KeepRunning()) {
- pi = CalculatePi(depth);
- }
-}
-BENCHMARK(BM_CalculatePi)->Threads(8);
-BENCHMARK(BM_CalculatePi)->ThreadRange(1, 32);
-BENCHMARK(BM_CalculatePi)->ThreadPerCpu();
-
-static void BM_SetInsert(benchmark::State& state) {
- while (state.KeepRunning()) {
- state.PauseTiming();
- std::set<int> data = ConstructRandomSet(state.range_x());
- state.ResumeTiming();
- for (int j = 0; j < state.range_y(); ++j)
- data.insert(rand());
- }
- state.SetItemsProcessed(state.iterations() * state.range_y());
- state.SetBytesProcessed(state.iterations() * state.range_y() * sizeof(int));
-}
-BENCHMARK(BM_SetInsert)->RangePair(1<<10,8<<10, 1,10);
-
-template<typename Q>
-static void BM_Sequential(benchmark::State& state) {
- typename Q::value_type v = 42;
- while (state.KeepRunning()) {
- Q q;
- for (int i = state.range_x(); --i; )
- q.push_back(v);
- }
- const int64_t items_processed =
- static_cast<int64_t>(state.iterations()) * state.range_x();
- state.SetItemsProcessed(items_processed);
- state.SetBytesProcessed(items_processed * sizeof(v));
-}
-BENCHMARK_TEMPLATE(BM_Sequential, std::vector<int>)->Range(1 << 0, 1 << 10);
-BENCHMARK_TEMPLATE(BM_Sequential, std::list<int>)->Range(1 << 0, 1 << 10);
-
-static void BM_StringCompare(benchmark::State& state) {
- std::string s1(state.range_x(), '-');
- std::string s2(state.range_x(), '-');
- int r = 0;
- while (state.KeepRunning())
- r |= s1.compare(s2);
- // Prevent compiler optimizations
- assert(r != std::numeric_limits<int>::max());
-}
-BENCHMARK(BM_StringCompare)->Range(1, 1<<20);
-
-static void BM_SetupTeardown(benchmark::State& state) {
- if (state.thread_index == 0) {
- // No need to lock test_vector_mu here as this is running single-threaded.
- test_vector = new std::vector<int>();
- }
- int i = 0;
- while (state.KeepRunning()) {
- std::lock_guard<std::mutex> l(test_vector_mu);
- if (i%2 == 0)
- test_vector->push_back(i);
- else
- test_vector->pop_back();
- ++i;
- }
- if (state.thread_index == 0) {
- delete test_vector;
- }
-}
-BENCHMARK(BM_SetupTeardown)->ThreadPerCpu();
-
-static void BM_LongTest(benchmark::State& state) {
- double tracker = 0.0;
- while (state.KeepRunning())
- for (int i = 0; i < state.range_x(); ++i)
- tracker += i;
- assert(tracker != 0.0);
-}
-BENCHMARK(BM_LongTest)->Range(1<<16,1<<28);
-
-int main(int argc, const char* argv[]) {
- benchmark::Initialize(&argc, argv);
-
- assert(Factorial(8) == 40320);
- assert(CalculatePi(1) == 0.0);
-
- benchmark::RunSpecifiedBenchmarks();
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9661f956/third_party/benchmark/test/filter_test.cc
----------------------------------------------------------------------
diff --git a/third_party/benchmark/test/filter_test.cc b/third_party/benchmark/test/filter_test.cc
deleted file mode 100644
index 00c2955..0000000
--- a/third_party/benchmark/test/filter_test.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-#include "benchmark/benchmark.h"
-
-#include <assert.h>
-#include <math.h>
-#include <stdint.h>
-
-#include <iostream>
-#include <sstream>
-#include <string>
-
-namespace {
-
-double CalculatePi(int depth) {
- double pi = 0.0;
- for (int i = 0; i < depth; ++i) {
- double numerator = static_cast<double>(((i % 2) * 2) - 1);
- double denominator = static_cast<double>((2 * i) - 1);
- pi += numerator / denominator;
- }
- return (pi - 1.0) * 4;
-}
-
-class TestReporter : public benchmark::internal::ConsoleReporter {
- public:
- virtual bool ReportContext(const Context& context) const {
- return ConsoleReporter::ReportContext(context);
- };
-
- virtual void ReportRuns(const std::vector<Run>& report) const {
- ++count_;
- ConsoleReporter::ReportRuns(report);
- };
-
- TestReporter() : count_(0) {}
-
- virtual ~TestReporter() {}
-
- size_t GetCount() const {
- return count_;
- }
-
- private:
- mutable size_t count_;
-};
-
-} // end namespace
-
-static void BM_CalculatePiRange(benchmark::State& state) {
- double pi = 0.0;
- while (state.KeepRunning())
- pi = CalculatePi(state.range_x());
- std::stringstream ss;
- ss << pi;
- state.SetLabel(ss.str());
-}
-BENCHMARK_RANGE(BM_CalculatePiRange, 1, 1024 * 1024);
-
-static void BM_CalculatePi(benchmark::State& state) {
- static const int depth = 1024;
- double pi BENCHMARK_UNUSED = 0.0;
- while (state.KeepRunning()) {
- pi = CalculatePi(depth);
- }
-}
-BENCHMARK(BM_CalculatePi)->Threads(8);
-BENCHMARK(BM_CalculatePi)->ThreadRange(1, 32);
-BENCHMARK(BM_CalculatePi)->ThreadPerCpu();
-
-int main(int argc, const char* argv[]) {
- benchmark::Initialize(&argc, argv);
-
- assert(CalculatePi(1) == 0.0);
-
- TestReporter test_reporter;
- benchmark::RunSpecifiedBenchmarks(&test_reporter);
-
- // Make sure we ran all of the tests
- const size_t count = test_reporter.GetCount();
- const size_t expected = (argc == 2) ? std::stoul(argv[1]) : count;
- if (count != expected) {
- std::cerr << "ERROR: Expected " << expected << " tests to be ran but only "
- << count << " completed" << std::endl;
- return -1;
- }
-}
-