You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/03/15 17:51:34 UTC
[33/34] geode-native git commit: GEODE-2552: Replaced NanoTimer with
std::chrono.
GEODE-2552: Replaced NanoTimer with std::chrono.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/c0d0c2a2
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/c0d0c2a2
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/c0d0c2a2
Branch: refs/heads/feature/GEODE-2602
Commit: c0d0c2a2035d7b8241311fb018ff1f156352dc65
Parents: bb5d430
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Sat Feb 25 14:02:58 2017 -0800
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Wed Mar 15 10:44:24 2017 -0700
----------------------------------------------------------------------
src/cppcache/src/statistics/HostStatSampler.cpp | 7 +--
src/cppcache/src/statistics/HostStatSampler.hpp | 8 ++-
.../src/statistics/StatArchiveWriter.cpp | 51 +++++++++++---------
.../src/statistics/StatArchiveWriter.hpp | 12 +++--
4 files changed, 46 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0d0c2a2/src/cppcache/src/statistics/HostStatSampler.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatSampler.cpp b/src/cppcache/src/statistics/HostStatSampler.cpp
index ab3811b..c68a6c4 100644
--- a/src/cppcache/src/statistics/HostStatSampler.cpp
+++ b/src/cppcache/src/statistics/HostStatSampler.cpp
@@ -134,8 +134,7 @@ HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
m_archiver = NULL;
m_samplerStats = new StatSamplerStats();
- ACE_Time_Value startTimeValue = ACE_OS::gettimeofday();
- m_startTime = startTimeValue.msec();
+ m_startTime = system_clock::now();
m_pid = ACE_OS::getpid();
m_statMngr = statMngr;
@@ -343,7 +342,9 @@ std::vector<Statistics*>& HostStatSampler::getNewStatistics() {
int64_t HostStatSampler::getSystemId() { return m_pid; }
-int64_t HostStatSampler::getSystemStartTime() { return m_startTime; }
+system_clock::time_point HostStatSampler::getSystemStartTime() {
+ return m_startTime;
+}
std::string HostStatSampler::getSystemDirectoryPath() {
ACE_utsname u;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0d0c2a2/src/cppcache/src/statistics/HostStatSampler.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatSampler.hpp b/src/cppcache/src/statistics/HostStatSampler.hpp
index a393815..7723799 100644
--- a/src/cppcache/src/statistics/HostStatSampler.hpp
+++ b/src/cppcache/src/statistics/HostStatSampler.hpp
@@ -22,6 +22,7 @@
#include <string>
#include <vector>
+#include <chrono>
#include <ace/Task.h>
#include <ace/Recursive_Thread_Mutex.h>
#include <geode/geode_globals.hpp>
@@ -50,6 +51,8 @@ namespace apache {
namespace geode {
namespace statistics {
+using std::chrono::system_clock;
+
class StatArchiveWriter;
class StatisticsManager;
/**
@@ -145,7 +148,7 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
/**
* Returns the time this sampler's system was started.
*/
- int64_t getSystemStartTime();
+ system_clock::time_point getSystemStartTime();
/**
* Returns the path to this sampler's system directory; if it has one.
*/
@@ -212,7 +215,8 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
StatisticsManager* m_statMngr;
int64_t m_pid;
- int64_t m_startTime;
+ system_clock::time_point m_startTime;
+
std::string initStatFileWithExt();
/**
* The archiveFile, after it exceeds archiveFileSizeLimit should be rolled
http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0d0c2a2/src/cppcache/src/statistics/StatArchiveWriter.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatArchiveWriter.cpp b/src/cppcache/src/statistics/StatArchiveWriter.cpp
index 7c0a42c..51950b6 100644
--- a/src/cppcache/src/statistics/StatArchiveWriter.cpp
+++ b/src/cppcache/src/statistics/StatArchiveWriter.cpp
@@ -26,10 +26,16 @@
#include "StatArchiveWriter.hpp"
#include "GeodeStatisticsFactory.hpp"
-#include <NanoTimer.hpp>
-using namespace apache::geode::client;
-using namespace apache::geode::statistics;
+namespace apache {
+namespace geode {
+namespace statistics {
+
+using std::chrono::steady_clock;
+using std::chrono::system_clock;
+using std::chrono::duration_cast;
+using std::chrono::milliseconds;
+using std::chrono::nanoseconds;
// Constructor and Member functions of StatDataOutput class
@@ -320,20 +326,19 @@ StatArchiveWriter::StatArchiveWriter(std::string outfile,
this->sampler = samplerArg;
// write the time, system property etc.
- this->previousTimeStamp = NanoTimer::now();
- this->previousTimeStamp += NANOS_PER_MILLI / 2;
- this->previousTimeStamp /= NANOS_PER_MILLI;
- ACE_Time_Value now = ACE_OS::gettimeofday();
- int64_t epochsec = now.sec();
- int64_t initialDate = epochsec * 1000;
+ this->previousTimeStamp = steady_clock::now();
this->dataBuffer->writeByte(HEADER_TOKEN);
this->dataBuffer->writeByte(ARCHIVE_VERSION);
- this->dataBuffer->writeLong(initialDate);
+ this->dataBuffer->writeLong(
+ duration_cast<milliseconds>(system_clock::now().time_since_epoch())
+ .count());
int64_t sysId = sampler->getSystemId();
this->dataBuffer->writeLong(sysId);
- int64_t sysStartTime = sampler->getSystemStartTime();
- this->dataBuffer->writeLong(sysStartTime);
+ this->dataBuffer->writeLong(
+ duration_cast<milliseconds>(
+ sampler->getSystemStartTime().time_since_epoch())
+ .count());
int32_t tzOffset = ACE_OS::timezone();
// offset in milli seconds
tzOffset = tzOffset * -1 * 1000;
@@ -341,7 +346,7 @@ StatArchiveWriter::StatArchiveWriter(std::string outfile,
struct tm *tm_val;
time_t clock = ACE_OS::time();
- tm_val = localtime(&clock);
+ tm_val = ACE_OS::localtime(&clock);
char buf[512] = {0};
ACE_OS::strftime(buf, sizeof(buf), "%Z", tm_val);
std::string tzId(buf);
@@ -388,7 +393,7 @@ int64_t StatArchiveWriter::bytesWritten() { return bytesWrittenToFile; }
int64_t StatArchiveWriter::getSampleSize() { return m_samplesize; }
-void StatArchiveWriter::sample(int64_t timeStamp) {
+void StatArchiveWriter::sample(const steady_clock::time_point &timeStamp) {
ACE_Guard<ACE_Recursive_Thread_Mutex> guard(sampler->getStatListMutex());
m_samplesize = dataBuffer->getBytesWritten();
@@ -407,10 +412,7 @@ void StatArchiveWriter::sample(int64_t timeStamp) {
m_samplesize = dataBuffer->getBytesWritten() - m_samplesize;
}
-void StatArchiveWriter::sample() {
- int64_t timestamp = NanoTimer::now();
- sample(timestamp);
-}
+void StatArchiveWriter::sample() { sample(steady_clock::now()); }
void StatArchiveWriter::close() {
sample();
@@ -511,13 +513,13 @@ void StatArchiveWriter::resampleResources() {
}
}
-void StatArchiveWriter::writeTimeStamp(int64_t timeStamp) {
- timeStamp += NANOS_PER_MILLI / 2;
- timeStamp /= NANOS_PER_MILLI;
- int64_t delta = timeStamp - this->previousTimeStamp;
+void StatArchiveWriter::writeTimeStamp(
+ const steady_clock::time_point &timeStamp) {
+ int32_t delta =
+ duration_cast<milliseconds>(timeStamp - this->previousTimeStamp).count();
if (delta > MAX_SHORT_TIMESTAMP) {
dataBuffer->writeShort(static_cast<int16_t>(INT_TIMESTAMP_TOKEN));
- dataBuffer->writeInt(static_cast<int32_t>(delta));
+ dataBuffer->writeInt(delta);
} else {
dataBuffer->writeShort(static_cast<uint16_t>(delta));
}
@@ -614,3 +616,6 @@ void StatArchiveWriter::writeResourceInst(StatDataOutput *dataOut,
dataOut->writeByte(static_cast<int8_t>(instId));
}
}
+} // namespace statistics
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0d0c2a2/src/cppcache/src/statistics/StatArchiveWriter.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatArchiveWriter.hpp b/src/cppcache/src/statistics/StatArchiveWriter.hpp
index b41d8e7..f4158de 100644
--- a/src/cppcache/src/statistics/StatArchiveWriter.hpp
+++ b/src/cppcache/src/statistics/StatArchiveWriter.hpp
@@ -33,6 +33,7 @@
#include <geode/Log.hpp>
#include <geode/DataOutput.hpp>
#include <NonCopyable.hpp>
+#include <chrono>
using namespace apache::geode::client;
@@ -54,7 +55,6 @@ const int16_t ILLEGAL_RESOURCE_INST_ID_TOKEN = -1;
const int32_t MAX_SHORT_RESOURCE_INST_ID = 65535;
const int32_t MAX_SHORT_TIMESTAMP = 65534;
const int32_t INT_TIMESTAMP_TOKEN = 65535;
-const int64_t NANOS_PER_MILLI = 1000000;
/** @file
*/
@@ -62,6 +62,10 @@ const int64_t NANOS_PER_MILLI = 1000000;
namespace apache {
namespace geode {
namespace statistics {
+
+using std::chrono::system_clock;
+using std::chrono::steady_clock;
+
/**
* Some of the classes which are used by the StatArchiveWriter Class
* 1. StatDataOutput // Just a wrapper around DataOutput so that the number of
@@ -200,7 +204,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
private:
HostStatSampler *sampler;
StatDataOutput *dataBuffer;
- int64_t previousTimeStamp;
+ steady_clock::time_point previousTimeStamp;
int32_t resourceTypeId;
int32_t resourceInstId;
int32_t statResourcesModCount;
@@ -215,7 +219,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
void sampleResources();
void resampleResources();
void writeResourceInst(StatDataOutput *, int32_t);
- void writeTimeStamp(int64_t timeStamp);
+ void writeTimeStamp(const steady_clock::time_point &timeStamp);
void writeStatValue(StatisticDescriptor *f, int64_t v, DataOutput dataOut);
ResourceType *getResourceType(Statistics *);
bool resourceInstMapHas(Statistics *sp);
@@ -232,7 +236,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
* Archives a sample snapshot at the given timeStamp.
* @param timeStamp a value obtained using NanoTimer::now.
*/
- void sample(int64_t timeStamp);
+ void sample(const steady_clock::time_point &timeStamp);
/**
* Archives a sample snapshot at the current time.
*/