diff --git a/SConstruct b/SConstruct index b3cbfe5ce3b..45a6ae14737 100644 --- a/SConstruct +++ b/SConstruct @@ -864,6 +864,7 @@ if nix: if linux and has_option( "gcov" ): env.Append( CXXFLAGS=" -fprofile-arcs -ftest-coverage " ) + env.Append( CPPDEFINES=["MONGO_GCOV"] ) env.Append( LINKFLAGS=" -fprofile-arcs -ftest-coverage " ) if optBuild: diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 83f763fa06a..043ebe96173 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -75,6 +75,7 @@ #include "mongo/s/stale_exception.h" // for SendStaleConfigException #include "mongo/util/fail_point_service.h" #include "mongo/util/file_allocator.h" +#include "mongo/util/gcov.h" #include "mongo/util/goodies.h" #include "mongo/util/mongoutils/str.h" #include "mongo/util/time_support.h" @@ -1168,6 +1169,8 @@ namespace mongo { /* not using log() herein in case we are already locked */ NOINLINE_DECL void dbexit( ExitCode rc, const char *why ) { + flushForGcov(); + Client * c = currentClient.get(); { scoped_lock lk( exitMutex ); diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp index c2f24f6cb18..de8ac8d8a7e 100644 --- a/src/mongo/dbtests/dbtests.cpp +++ b/src/mongo/dbtests/dbtests.cpp @@ -27,6 +27,7 @@ #include "mongo/dbtests/dbtests.h" #include "mongo/dbtests/framework.h" #include "mongo/util/exception_filter_win32.h" +#include "mongo/util/gcov.h" #include "mongo/util/startup_test.h" #include "mongo/util/text.h" @@ -60,6 +61,7 @@ int wmain(int argc, wchar_t* argvW[], wchar_t* envpW[]) { #else int main(int argc, char* argv[], char** envp) { int exitCode = dbtestsMain(argc, argv, envp); + flushForGcov(); ::_exit(exitCode); } #endif diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 22369d8b5c3..fec01840b6b 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -62,6 +62,7 @@ #include "mongo/util/concurrency/task.h" #include "mongo/util/concurrency/thread_name.h" #include "mongo/util/exception_filter_win32.h" +#include "mongo/util/gcov.h" #include "mongo/util/log.h" #include "mongo/util/net/message.h" #include "mongo/util/net/message_server.h" @@ -656,5 +657,6 @@ void mongo::dbexit( ExitCode rc, const char *why ) { << " rc:" << rc << " " << ( why ? why : "" ) << endl; + flushForGcov(); ::_exit(rc); } diff --git a/src/mongo/util/gcov.h b/src/mongo/util/gcov.h new file mode 100644 index 00000000000..2d0350cc2f2 --- /dev/null +++ b/src/mongo/util/gcov.h @@ -0,0 +1,36 @@ +/** + * Copyright (C) 2013 10gen Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects + * for all of the code used other than as permitted herein. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you do not + * wish to do so, delete this exception statement from your version. If you + * delete this exception statement from all source files in the program, + * then also delete it in the license file. + */ + +#pragma once + +#ifdef MONGO_GCOV +extern "C" { void __gcov_flush(); } +inline void flushForGcov() { __gcov_flush(); } +#else +inline void flushForGcov() {} +#endif