Example fails to run (std::system_error)
DaimonPl opened this issue · 15 comments
Tried to run first example (master @ d750144) and got following result:
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
As I checked any of following lines (even when run alone) cause that problem:
benchmark::Initialize(&argc, (const char **) argv);
benchmark::RunSpecifiedBenchmarks();
Full file for reference:
#include <string>
#include "benchmark/benchmark.h"
static void BM_StringCreation(benchmark::State& state) {
while (state.KeepRunning())
std::string empty_string;
}
// Register the function as a benchmark
BENCHMARK(BM_StringCreation);
// Define another benchmark
static void BM_StringCopy(benchmark::State& state) {
std::string x = "hello";
while (state.KeepRunning())
std::string copy(x);
}
BENCHMARK(BM_StringCopy);
// Augment the main() program to invoke benchmarks if specified
// via the --benchmarks command line flag. E.g.,
// my_unittest --benchmark_filter=all
// my_unittest --benchmark_filter=BM_StringCreation
// my_unittest --benchmark_filter=String
// my_unittest --benchmark_filter='Copy|Creation'
int main(int argc, char** argv) {
benchmark::Initialize(&argc, (const char **) argv);
benchmark::RunSpecifiedBenchmarks();
return 0;
}
I believe this is also fixed along with the fix for #65.
If you are still seeing it, please let me know the platform and compiler, and if you can attach a debugger for a stack trace, even better :)
Problem is still happening. I'm also using gtest library in exactly same setup and works without any problems. If you need more information please let me know.
Compiled with CLANG 3.5 in C++11 mode, 64bit, ubuntu 14.04
Stack trace:
Thread [1] 32222 [core: 1] (Suspended : Signal : SIGABRT:Aborted)
__GI_raise() at raise.c:56 0x7ffff722abb9
__GI_abort() at abort.c:89 0x7ffff722dfc8
__gnu_cxx::__verbose_terminate_handler() at 0x7ffff7b366b5
0x7ffff7b34836
std::terminate() at 0x7ffff7b34863
__cxa_throw() at 0x7ffff7b34aa2
std::__throw_system_error() at 0x7ffff7b86990
void std::call_once<void (&)()> at 0x4137e4
benchmark::CyclesPerSecond() at 0x41367c
benchmark::walltime::Initialize() at 0x413b22
benchmark::Initialize() at 0x408569
main() at main.cc:26 0x4031e6
BTW: libbenchmark was compiled using cmake, so most likely G++ was used for that part
Let me know if it will be tracked here or new issue is required
Tracking here is fine. Thanks so much for the detailed stack.
Interestingly I'm on exactly the same system and compiler and don't see the same issue.
As I checked code it looks to be some problem in sysinfo.cc or related calls - so might be related to my library building and/or environment.
Here's output from cmake:
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Performing Test HAVE_FLAG_CXX_14
-- Performing Test HAVE_FLAG_CXX_14 - Failed
-- Performing Test HAVE_FLAG_CXX_11
-- Performing Test HAVE_FLAG_CXX_11 - Success
-- Performing Test HAVE_FLAG_CXX_0X
-- Performing Test HAVE_FLAG_CXX_0X - Success
-- Performing Test HAVE_WALL
-- Performing Test HAVE_WALL - Success
-- Performing Test HAVE_WSHADOW
-- Performing Test HAVE_WSHADOW - Success
-- Performing Test HAVE_WERROR
-- Performing Test HAVE_WERROR - Success
-- Performing Test HAVE_PEDANTIC_ERRORS
-- Performing Test HAVE_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_FNO_STRICT_ALIASING
-- Performing Test HAVE_FNO_STRICT_ALIASING - Success
-- git Version: v0.0.0
-- Version: 0.0.0
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX -- compiled but failed to run
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- success
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
Here's output from make:
Scanning dependencies of target googletest
[ 5%] Creating directories for 'googletest'
[ 11%] Performing download step (download, verify and extract) for 'googletest'
-- downloading...
src='https://googletest.googlecode.com/files/gtest-1.7.0.zip'
dst='/home/damian/benchmark/third_party/src/gtest-1.7.0.zip'
timeout='none'
-- downloading... done
-- verifying file...
file='/home/damian/benchmark/third_party/src/gtest-1.7.0.zip'
-- verifying file... done
-- extracting...
src='/home/damian/benchmark/third_party/src/gtest-1.7.0.zip'
dst='/home/damian/benchmark/third_party/gtest'
-- extracting... [tar xfz]
-- extracting... [analysis]
-- extracting... [rename]
-- extracting... [clean up]
-- extracting... done
[ 16%] No patch step for 'googletest'
[ 22%] No update step for 'googletest'
[ 27%] Performing configure step for 'googletest'
-- Configuring done
-- Generating done
-- Build files have been written to: /home/damian/benchmark/third_party/src/googletest-build
[ 33%] Performing build step for 'googletest'
[ 50%] Built target gtest
[100%] Built target gtest_main
[ 38%] No install step for 'googletest'
[ 44%] Completed 'googletest'
[ 44%] Built target googletest
Scanning dependencies of target benchmark
[ 50%] Building CXX object src/CMakeFiles/benchmark.dir/benchmark.cc.o
[ 55%] Building CXX object src/CMakeFiles/benchmark.dir/colorprint.cc.o
[ 61%] Building CXX object src/CMakeFiles/benchmark.dir/commandlineflags.cc.o
[ 66%] Building CXX object src/CMakeFiles/benchmark.dir/sleep.cc.o
[ 72%] Building CXX object src/CMakeFiles/benchmark.dir/sysinfo.cc.o
[ 77%] Building CXX object src/CMakeFiles/benchmark.dir/walltime.cc.o
[ 83%] Building CXX object src/CMakeFiles/benchmark.dir/re_posix.cc.o
Linking CXX static library libbenchmark.a
[ 83%] Built target benchmark
Scanning dependencies of target benchmark_re
[ 88%] Building CXX object src/CMakeFiles/benchmark_re.dir/re_posix.cc.o
Linking CXX static library libbenchmark_re.a
[ 88%] Built target benchmark_re
[ 94%] Building CXX object test/CMakeFiles/benchmark_test.dir/benchmark_test.cc.o
Linking CXX executable benchmark_test
[ 94%] Built target benchmark_test
[100%] Building CXX object test/CMakeFiles/re_test.dir/re_test.cc.o
Linking CXX executable re_test
[100%] Built target re_test
If you have some idea about info you need, let me know. Reverting back to previous question - now it's confirmed that example was compiled with clang, but library itself with gnu
I also tried compiling library with export CXX=/usr/bin/clang++; export CC=/usr/bin/clang but result is exactly the same (i mean error during runtime)
Are you using the stock Ubuntu 14.04 libc?
ldd --version
ldd (Ubuntu EGLIBC 2.19-0ubuntu6.3) 2.19
If this is what you are asking for :) I did not do any standard library variations, except of installing libc++ but AFAIK it's not being used by default
If the example is compiled with clang and the library with g++ you're going to have issues.
If you change the compiler, you may have to reconfigure (rerun cmake) from a clean setup. Can you try that please?
That's exactly what I did when I mentioned exporting CXX with clang value (make clean, removed cmake files, run cmake, make)
Unfortunately result is the same. Have no idea what can be the problem, gtest works just fine so it looks to be specific to some library which benchmark depends on
I've tested this in Debug and Release on the following system:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"
$ cmake --version
cmake version 2.8.12.2
$ echo $CXX ':' $CC
clang++ : clang
$ clang++ --version
Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix
cmake output (from clean):
$ cmake .
-- The C compiler identification is Clang 3.5.0
-- The CXX compiler identification is Clang 3.5.0
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Ninja
-- Check for working CXX compiler using: Ninja -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Performing Test HAVE_FLAG_CXX_14
-- Performing Test HAVE_FLAG_CXX_14 - Failed
-- Performing Test HAVE_FLAG_CXX_11
-- Performing Test HAVE_FLAG_CXX_11 - Success
-- Performing Test HAVE_FLAG_CXX_0X
-- Performing Test HAVE_FLAG_CXX_0X - Success
-- Performing Test HAVE_WALL
-- Performing Test HAVE_WALL - Success
-- Performing Test HAVE_WSHADOW
-- Performing Test HAVE_WSHADOW - Success
-- Performing Test HAVE_WERROR
-- Performing Test HAVE_WERROR - Success
-- Performing Test HAVE_PEDANTIC_ERRORS
-- Performing Test HAVE_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_FNO_STRICT_ALIASING
-- Performing Test HAVE_FNO_STRICT_ALIASING - Success
-- git Version: v0.0.0-dirty
-- Version: 0.0.0
-- Performing Test HAVE_STD_REGEX
-- Performing Test HAVE_STD_REGEX -- compiled but failed to run
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- success
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dominic/git/benchmark
and ninja (i don't use make, though i doubt it would matter) doesn't have any output really.
then:
$ test/67_test
Reading /proc/self/cputime_ns failed. Using getrusage().
Benchmarking on 4 X 2501 MHz CPUs
2014/11/14-21:43:00
CPU scaling is enabled: Benchmark timings may be noisy.
DEBUG: Benchmark Time(ns) CPU(ns) Iterations
---------------------------------------------------------
DEBUG: BM_StringCreation 2 22 23032372
DEBUG: BM_StringCopy 12 32 15833581
where 67_test is:
$ cat test/67_test.cc
#include <string>
#include "benchmark/benchmark.h"
static void BM_StringCreation(benchmark::State& state) {
while (state.KeepRunning())
std::string empty_string;
}
// Register the function as a benchmark
BENCHMARK(BM_StringCreation);
// Define another benchmark
static void BM_StringCopy(benchmark::State& state) {
std::string x = "hello";
while (state.KeepRunning())
std::string copy(x);
}
BENCHMARK(BM_StringCopy);
// Augment the main() program to invoke benchmarks if specified
// via the --benchmarks command line flag. E.g.,
// my_unittest --benchmark_filter=all
// my_unittest --benchmark_filter=BM_StringCreation
// my_unittest --benchmark_filter=String
// my_unittest --benchmark_filter='Copy|Creation'
int main(int argc, char** argv) {
benchmark::Initialize(&argc, (const char **) argv);
benchmark::RunSpecifiedBenchmarks();
return 0;
}
I don't know what else to suggest. What version of g++ do you have installed? Just in case it's using the std lib from there and it's old (pre 4.6 or something)?
$ g++ --version
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
I had the same problem, running Ubuntu 14.04 and using g++ 4.8.2:
What did the trick, at least for me, was linking against lpthread:
g++ -o google_benchmark google_benchmark.cpp -Wall -Wextra --std=c++11 -lbenchmark -lpthread
Ah yes, the std::thread needs pthread issue. I will add something to the documentation.
g++ -o google_benchmark google_benchmark.cpp -Wall -Wextra --std=c++11 -lbenchmark -lpthread
worked but
g++ -o google_benchmark google_benchmark.cpp -Wall -Wextra --std=c++11 -lpthread -lbenchmark
did not... apparently if you link pthreads BEFORE benchmark bad things happen.