Skip to content

Commit 1444787

Browse files
committed
added getDetailedStats(Stats)
1 parent 0269793 commit 1444787

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/MemoryPagesPool.cxx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,27 @@ std::string MemoryPagesPool::getDetailedStats() {
589589
return report;
590590
}
591591

592+
void MemoryPagesPool::getDetailedStats(Stats &s) {
593+
s.id = id;
594+
s.t0 = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count()/1000000.0;
595+
auto now = std::chrono::steady_clock::now();
596+
std::unique_lock<std::mutex> lock(pagesAvailableMutexPush);
597+
s.states.resize(pages.size());
598+
for(unsigned int ix = 0 ; ix < pages.size(); ix++) {
599+
auto ps = pages[ix].currentPageState;
600+
s.states[ix].state = ps;
601+
double t = 0;
602+
if (ps != MemoryPage::PageState::Undefined) {
603+
if (pages[ix].pageStateTimes[(int)ps].t0IsValid) {
604+
t = (std::chrono::duration<double>(now - pages[ix].pageStateTimes[(int)ps].t0)).count();
605+
}
606+
}
607+
s.states[ix].timeInCurrentState = t;
608+
}
609+
s.t1 = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count()/1000000.0;
610+
}
611+
612+
592613
// todo:
593614
// add FMQ release rate
594615
// start/stop/start -> reorder pages in pool FIFO

src/MemoryPagesPool.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ class MemoryPagesPool
131131
std::string getStats(); // return a string summarizing memory pool usage statistics
132132
std::string getDetailedStats(); // return detailed stats
133133

134+
struct PageStat {
135+
MemoryPage::PageState state; // the current state of given page
136+
float timeInCurrentState; //the time (seconds) since the page is in current state
137+
};
138+
139+
struct Stats {
140+
int id; // pool id
141+
double t0; // beginning of query
142+
double t1; // end of query
143+
std::vector<PageStat> states; // state of each page
144+
};
145+
146+
void getDetailedStats(Stats &s); // get detailed stats
147+
134148
// an optional user-provided logging function for all memory pool related ops (including warnings on low)
135149
typedef std::function<void(const std::string &)> LogCallback;
136150

0 commit comments

Comments
 (0)