Skip to content

Commit

Permalink
[C++]: for #480. Update C++ API for CnC file changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontgomery committed Mar 12, 2018
1 parent 0533f15 commit 5513dd3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 27 additions & 1 deletion aeron-client/src/main/cpp/CncFileDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@ using namespace aeron::concurrent;
* | Client Liveness Timeout |
* | |
* +---------------------------------------------------------------+
* | Driver Start Timestamp |
* | |
* +---------------------------------------------------------------+
* | Driver PID |
* | |
* +---------------------------------------------------------------+
* </pre>
*/
namespace CncFileDescriptor {

static const std::string CNC_FILE = "cnc.dat";

static const std::int32_t CNC_VERSION = 12;
static const std::int32_t CNC_VERSION = 13;

#pragma pack(push)
#pragma pack(4)
Expand All @@ -85,6 +91,8 @@ struct MetaDataDefn
std::int32_t counterValuesBufferLength;
std::int32_t errorLogBufferLength;
std::int64_t clientLivenessTimeout;
std::int64_t startTimestamp;
std::int64_t pid;
};
#pragma pack(pop)

Expand Down Expand Up @@ -170,6 +178,24 @@ inline static std::int64_t clientLivenessTimeout(MemoryMappedFile::ptr_t cncFile
return metaData.clientLivenessTimeout;
}

inline static std::int64_t startTimestamp(MemoryMappedFile::ptr_t cncFile)
{
AtomicBuffer metaDataBuffer(cncFile->getMemoryPtr(), convertSizeToIndex(cncFile->getMemorySize()));

const MetaDataDefn& metaData = metaDataBuffer.overlayStruct<MetaDataDefn>(0);

return metaData.startTimestamp;
}

inline static std::int64_t pid(MemoryMappedFile::ptr_t cncFile)
{
AtomicBuffer metaDataBuffer(cncFile->getMemoryPtr(), convertSizeToIndex(cncFile->getMemorySize()));

const MetaDataDefn& metaData = metaDataBuffer.overlayStruct<MetaDataDefn>(0);

return metaData.pid;
}

}

}
Expand Down
6 changes: 4 additions & 2 deletions aeron-samples/src/main/cpp/AeronStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ int main (int argc, char** argv)
}

const std::int64_t clientLivenessTimeoutNs = CncFileDescriptor::clientLivenessTimeout(cncFile);
const std::int64_t startTimestamp = CncFileDescriptor::startTimestamp(cncFile);
const std::int64_t pid = CncFileDescriptor::pid(cncFile);

AtomicBuffer metadataBuffer = CncFileDescriptor::createCounterMetadataBuffer(cncFile);
AtomicBuffer valuesBuffer = CncFileDescriptor::createCounterValuesBuffer(cncFile);
Expand All @@ -110,8 +112,8 @@ int main (int argc, char** argv)
std::printf("\033[H\033[2J");

std::printf(
"%s - Aeron Stat (CnC v%" PRId32 "), client liveness %s ns\n",
currentTime, cncVersion, toStringWithCommas(clientLivenessTimeoutNs).c_str());
"%s - Aeron Stat (CnC v%" PRId32 "), pid %" PRId64 ", client liveness %s ns\n",
currentTime, cncVersion, pid, toStringWithCommas(clientLivenessTimeoutNs).c_str());
std::printf("===========================\n");

counters.forEach([&](std::int32_t counterId, std::int32_t, const AtomicBuffer&, const std::string& l)
Expand Down

0 comments on commit 5513dd3

Please sign in to comment.