From 7bbc7c314f4ebb1e7fe882a0a2aae5a5655f2972 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Fri, 23 Oct 2015 13:07:36 -0400 Subject: Add option for microsecond precision in debug.log --- src/utiltime.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/utiltime.cpp') diff --git a/src/utiltime.cpp b/src/utiltime.cpp index d31628899..3202c47f1 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -40,6 +40,14 @@ int64_t GetTimeMicros() boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds(); } +/** Return a time useful for the debug log */ +int64_t GetLogTimeMicros() +{ + if (nMockTime) return nMockTime*1000000; + + return GetTimeMicros(); +} + void MilliSleep(int64_t n) { -- cgit v1.2.3 From 1bb289fe1b7d240e0d58ef13da30e45590231078 Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Tue, 24 Nov 2015 18:39:19 -0800 Subject: Assert now > 0 in GetTime GetTimeMillis GetTimeMicros Previously all of these functions could return negative values (for different readons). Large portions of the codebase currently assume that these functions return positive values. --- src/utiltime.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/utiltime.cpp') diff --git a/src/utiltime.cpp b/src/utiltime.cpp index 3202c47f1..7d9f6210e 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -20,7 +20,9 @@ int64_t GetTime() { if (nMockTime) return nMockTime; - return time(NULL); + time_t now = time(NULL); + assert(now > 0); + return now; } void SetMockTime(int64_t nMockTimeIn) @@ -30,14 +32,18 @@ void SetMockTime(int64_t nMockTimeIn) int64_t GetTimeMillis() { - return (boost::posix_time::microsec_clock::universal_time() - - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds(); + int64_t now = (boost::posix_time::microsec_clock::universal_time() - + boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds(); + assert(now > 0); + return now; } int64_t GetTimeMicros() { - return (boost::posix_time::microsec_clock::universal_time() - - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds(); + int64_t now = (boost::posix_time::microsec_clock::universal_time() - + boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds(); + assert(now > 0); + return now; } /** Return a time useful for the debug log */ -- cgit v1.2.3 From fa24439ff3d8ab5b9efaf66ef4dae6713b88cb35 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 13 Dec 2015 17:58:29 +0100 Subject: Bump copyright headers to 2015 --- src/utiltime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utiltime.cpp') diff --git a/src/utiltime.cpp b/src/utiltime.cpp index 7d9f6210e..91b40d999 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2009-2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From fada0c422c081ba53a324aaf63c0a750cb56498e Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 3 Apr 2016 11:49:36 +0200 Subject: [doc] Fix doxygen comments for members --- src/utiltime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utiltime.cpp') diff --git a/src/utiltime.cpp b/src/utiltime.cpp index 91b40d999..da590f888 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -14,7 +14,7 @@ using namespace std; -static int64_t nMockTime = 0; //! For unit testing +static int64_t nMockTime = 0; //!< For unit testing int64_t GetTime() { -- cgit v1.2.3 From 507145d78595e052ce13368e122f72c85093992c Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 27 Nov 2016 15:11:49 -0800 Subject: Fix race when accessing std::locale::classic() See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78552 --- src/utiltime.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/utiltime.cpp') diff --git a/src/utiltime.cpp b/src/utiltime.cpp index da590f888..51d545ef8 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -74,8 +74,9 @@ void MilliSleep(int64_t n) std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime) { + static std::locale classic(std::locale::classic()); // std::locale takes ownership of the pointer - std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat)); + std::locale loc(classic, new boost::posix_time::time_facet(pszFormat)); std::stringstream ss; ss.imbue(loc); ss << boost::posix_time::from_time_t(nTime); -- cgit v1.2.3 From 27765b6403cece54320374b37afb01a0cfe571c3 Mon Sep 17 00:00:00 2001 From: isle2983 Date: Sat, 31 Dec 2016 11:01:21 -0700 Subject: Increment MIT Licence copyright header year on files modified in 2016 Edited via: $ contrib/devtools/copyright_header.py update . --- src/utiltime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utiltime.cpp') diff --git a/src/utiltime.cpp b/src/utiltime.cpp index 51d545ef8..7c5ee7726 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2015 The Bitcoin Core developers +// Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From 99464bc38e9575ff47f8e33223b252dcea2055e3 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Thu, 19 Jan 2017 13:01:18 -0500 Subject: net: Consistently use GetTimeMicros() for inactivity checks The use of mocktime in test logic means that comparisons between GetTime() and GetTimeMicros()/1000000 are unreliable since the former can use mocktime values while the latter always gets the system clock; this changes the networking code's inactivity checks to consistently use the system clock for inactivity comparisons. Also remove some hacks from setmocktime() that are no longer needed, now that we're using the system clock for nLastSend and nLastRecv. --- src/utiltime.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/utiltime.cpp') diff --git a/src/utiltime.cpp b/src/utiltime.cpp index 7c5ee7726..87a25866e 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -46,6 +46,11 @@ int64_t GetTimeMicros() return now; } +int64_t GetSystemTimeInSeconds() +{ + return GetTimeMicros()/1000000; +} + /** Return a time useful for the debug log */ int64_t GetLogTimeMicros() { -- cgit v1.2.3 From cc16d99f1dc8305b1b255f1cc0f2b1516aa77ed0 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Wed, 18 Jan 2017 16:15:37 +0100 Subject: [trivial] Fix typos in comments --- src/utiltime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utiltime.cpp') diff --git a/src/utiltime.cpp b/src/utiltime.cpp index 87a25866e..c7b3e4f16 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -63,7 +63,7 @@ void MilliSleep(int64_t n) { /** - * Boost's sleep_for was uninterruptable when backed by nanosleep from 1.50 + * Boost's sleep_for was uninterruptible when backed by nanosleep from 1.50 * until fixed in 1.52. Use the deprecated sleep method for the broken case. * See: https://svn.boost.org/trac/boost/ticket/7238 */ -- cgit v1.2.3