forked from morganstanley/hobbes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support queries of reader/sender state in hog (morganstanley#217)
This change resolves morganstanley#209, so that connection/stats details are logged in the generated structured file (the pathname will be indicated in the stdout)
- Loading branch information
1 parent
cdf3f32
commit c75a57f
Showing
5 changed files
with
135 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "stat.H" | ||
|
||
#include <string> | ||
|
||
namespace hog { | ||
|
||
inline std::string statFilePrefix() { | ||
return hobbes::storage::defaultStoreDir() + "/hogstat"; | ||
} | ||
|
||
StatFile& StatFile::instance() { | ||
static StatFile statFile; | ||
return statFile; | ||
} | ||
|
||
StatFile::StatFile() : statFile(hobbes::fregion::uniqueFilename(statFilePrefix(), ".db")) {} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#ifndef HOG_STAT_H_INCLUDED | ||
#define HOG_STAT_H_INCLUDED | ||
|
||
#include <mutex> | ||
|
||
#include <hobbes/hobbes.H> | ||
#include <hobbes/reflect.H> | ||
#include <hobbes/storage.H> | ||
#include <hobbes/fregion.H> | ||
|
||
namespace hog { | ||
|
||
DEFINE_ENUM(ReaderStatus, | ||
(Started), | ||
(Closed) | ||
); | ||
|
||
DEFINE_STRUCT(ReaderState, | ||
(hobbes::datetimeT, datetime), | ||
(hobbes::storage::ProcThread, readerId), | ||
(ReaderStatus, status) | ||
); | ||
|
||
DEFINE_STRUCT(ReaderRegistration, | ||
(hobbes::datetimeT, datetime), | ||
(hobbes::storage::ProcThread, writerId), | ||
(hobbes::storage::ProcThread, readerId), | ||
(std::string, shmname) | ||
); | ||
|
||
DEFINE_ENUM(SenderStatus, | ||
(Suspended), | ||
(Started), | ||
(Closed) | ||
); | ||
|
||
DEFINE_STRUCT(SenderState, | ||
(hobbes::datetimeT, datetime), | ||
(hobbes::storage::ProcThread, id), | ||
(SenderStatus, status) | ||
); | ||
|
||
DEFINE_STRUCT(SenderRegistration, | ||
(hobbes::datetimeT, datetime), | ||
(hobbes::storage::ProcThread, readerId), | ||
(hobbes::storage::ProcThread, senderId), | ||
(std::string, directory), | ||
(std::vector<std::string>, senderqueue) | ||
); | ||
|
||
class StatFile { | ||
public: | ||
static StatFile& instance(); | ||
|
||
template <typename T> | ||
void log(T&& value) { | ||
std::lock_guard<decltype(mutex)> _{mutex}; | ||
statFile.series<T>(T::_hmeta_struct_type_name())(std::forward<T>(value)); | ||
} | ||
|
||
const std::string& filename() const { | ||
return statFile.fileData()->path; | ||
} | ||
|
||
private: | ||
StatFile(); | ||
~StatFile() = default; | ||
StatFile(const StatFile&) = delete; | ||
StatFile& operator=(const StatFile&) = delete; | ||
|
||
hobbes::fregion::writer statFile; | ||
std::mutex mutex; | ||
}; | ||
|
||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters