Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions rdkperf/rdk_perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include "rdk_perf_process.h"
#include "rdk_perf_tree.h" // Needs to come after rdk_perf_process because of forward declaration of PerfTree
#include "rdk_perf.h"
#ifdef PERF_SHOW_CPU
#include "rdk_perf_clock.h"
#endif

#include <unistd.h>

Expand Down Expand Up @@ -296,15 +299,20 @@ RDKPerfInProc::~RDKPerfInProc()
RDKPerfRemote::RDKPerfRemote(const char* szName)
: m_szName(szName)
, m_nThresholdInUS(0)
, m_EndTime(0)
{
#ifndef PERF_SHOW_CPU
m_StartTime = PerfRecord::TimeStamp();

#endif
// Send enter event
#ifdef PERF_REMOTE
if(s_pQueue == NULL) s_pQueue = PerfMsgQueue::GetQueue(RDK_PERF_MSG_QUEUE_NAME, false);
if(s_pQueue != NULL) {
#ifdef PERF_SHOW_CPU
PerfClock::Now(&m_clock, PerfClock::Marker);
s_pQueue->SendMessage(eEntry, m_szName, NULL, m_nThresholdInUS);
#else
s_pQueue->SendMessage(eEntry, m_szName, m_StartTime, m_nThresholdInUS);
#endif
}
else {
LOG(eError, "Could not get Message Queue to send perf events\n");
Expand All @@ -316,13 +324,19 @@ RDKPerfRemote::RDKPerfRemote(const char* szName, uint32_t nThresholdInUS)
: m_szName(szName)
, m_nThresholdInUS(nThresholdInUS)
{
#ifndef PERF_SHOW_CPU
m_StartTime = PerfRecord::TimeStamp();
#endif
// Send enter event
#ifdef PERF_REMOTE
if(s_pQueue == NULL) s_pQueue = PerfMsgQueue::GetQueue(RDK_PERF_MSG_QUEUE_NAME, false);
if(s_pQueue != NULL) {
#ifdef PERF_SHOW_CPU
PerfClock::Now(&m_clock, PerfClock::Marker);
s_pQueue->SendMessage(eEntry, m_szName, NULL, nThresholdInUS);
#else
s_pQueue->SendMessage(eEntry, m_szName, m_StartTime, nThresholdInUS);
#endif
}
else {
LOG(eError, "Could not get Message Queue to send perf events\n");
Expand All @@ -344,12 +358,16 @@ void RDKPerfRemote::SetThreshhold(uint32_t nThresholdInUS)

RDKPerfRemote::~RDKPerfRemote()
{
m_EndTime = PerfRecord::TimeStamp();

// Send close event
#ifdef PERF_REMOTE
if(s_pQueue != NULL) {
s_pQueue->SendMessage(eExit, m_szName, m_EndTime - m_StartTime);
#ifdef PERF_SHOW_CPU
PerfClock::Now(&m_clock, PerfClock::Elapsed);
s_pQueue->SendMessage(eExit, m_szName, &m_clock.GetTimeStamp(), m_nThresholdInUS);
#else
const uint64_t endTime = PerfRecord::TimeStamp();
s_pQueue->SendMessage(eExit, m_szName, endTime - m_StartTime);
#endif
}
else {
LOG(eError, "Could not get Message Queue to send perf events\n");
Expand Down
8 changes: 7 additions & 1 deletion rdkperf/rdk_perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

#include "rdk_perf_record.h"
//#include "rdk_perf_node.h"
#ifdef PERF_SHOW_CPU
#include "rdk_perf_clock.h"
#endif

#define FUNC_METRICS_START(depth) \
{ \
Expand Down Expand Up @@ -95,8 +98,11 @@ class RDKPerfRemote
private:
const char* m_szName;
uint32_t m_nThresholdInUS;
#ifdef PERF_SHOW_CPU
PerfClock m_clock;
#else
uint64_t m_StartTime;
uint64_t m_EndTime;
#endif
};


Expand Down
48 changes: 40 additions & 8 deletions service/perfservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>

#include "rdk_perf_logging.h"
#include "rdk_perf_msgqueue.h"
Expand Down Expand Up @@ -56,9 +57,10 @@ PerfTree* GetTree(pid_t pID, pthread_t tID, char* szName, bool bCreate = false)
if(pTree == NULL) {
if(bCreate) {
pTree = pProcess->NewTree(tID);
LOG(eError, "Tree created %X\n", tID);
}
else {
LOG(eError, "Tree not found %x but create not enabled\n", tID);
LOG(eError, "Tree not found %X but create not enabled\n", tID);
}
}

Expand All @@ -83,7 +85,12 @@ bool HandleEntry(PerfMessage* pMsg)
PerfNode* pNode = pTree->AddNode(szName,
tID,
szThreadName,
pMsg->msg_data.entry.nTimeStamp);
#ifdef PERF_SHOW_CPU
0
#else
pMsg->msg_data.entry.nTimeStamp
#endif
);
if(pMsg->msg_data.entry.nThresholdInUS > 0) {
pNode->SetThreshold(pMsg->msg_data.entry.nThresholdInUS);
}
Expand Down Expand Up @@ -135,7 +142,14 @@ bool HandleExit(PerfMessage* pMsg)
PerfNode* pNode = pTree->GetStack()->top();
if(pNode != NULL &&
pNode->GetName().compare(szName) == 0) {
#ifdef PERF_SHOW_CPU
PerfClock deltaClock(&pMsg->msg_data.exit.clkTimeStamp);
pNode->IncrementData(deltaClock.GetWallClock(),
deltaClock.GetUserCPU(),
deltaClock.GetSystemCPU());
#else
pNode->IncrementData(pMsg->msg_data.exit.nTimeStamp, 0, 0);
#endif
pNode->CloseNode();
retVal = true;
}
Expand Down Expand Up @@ -250,6 +264,7 @@ bool HandleMessage(PerfMessage* pMsg)

return retVal;
}

void RunLoop(PerfMsgQueue* pQueue)
{
bool bContinue = true;
Expand All @@ -261,7 +276,7 @@ void RunLoop(PerfMsgQueue* pQueue)
pQueue->ReceiveMessage(&msg, MESSAGE_TIMEOUT);
//TEST
if(msg.type == eExitQueue || msg.type == eMaxType) {
// Exit loop
LOG(eWarning, "Exit loop\n");
bContinue = false;
}
else if(msg.type == eNoMessage) {
Expand All @@ -286,26 +301,43 @@ void RunLoop(PerfMsgQueue* pQueue)
LOG(eWarning, "RunLoop exiting\n");
return;
}

static PerfMsgQueue* s_pQueue = NULL;

static void ctrlc_handler_callback(int, siginfo_t* ,void* contex)
{
LOG(eWarning, "Ctrl+C pressed\n");
if(s_pQueue != NULL) {
s_pQueue->SendMessage(eExitQueue, NULL, 0, 0);
}
}

int main(int argc, char *argv[])
{
LOG(eWarning, "Enter perfservice app %s\n", __DATE__);

// Register Ctrl+C handler
struct sigaction sa;
sa.sa_sigaction = ctrlc_handler_callback;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGINT, &sa, NULL);

RDKPerf_InitializeMap();

// // Does the queue exist
if(PerfMsgQueue::IsQueueCreated(RDK_PERF_MSG_QUEUE_NAME)) {
// Queue exists, service is a duplicate
LOG(eError, "Queue exists, service is a duplicate\n");
exit(-1);
}

// Create Queue
PerfMsgQueue* pQueue = PerfMsgQueue::GetQueue(RDK_PERF_MSG_QUEUE_NAME, true);
if(pQueue != NULL) {
s_pQueue = PerfMsgQueue::GetQueue(RDK_PERF_MSG_QUEUE_NAME, true);
if(s_pQueue != NULL) {
// Have Queue, start retrieven messages
RunLoop(pQueue);
RunLoop(s_pQueue);

// RunLoop exited, cleanup
pQueue->Release();
s_pQueue->Release();
}

RDKPerf_DeleteMap();
Expand Down
5 changes: 5 additions & 0 deletions src/rdk_perf_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,8 @@ PerfClock* PerfClock::Now()

return retVal;
}

const TimeStamp& PerfClock::GetTimeStamp() const
{
return m_timeStamp;
}
15 changes: 8 additions & 7 deletions src/rdk_perf_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
#include <string.h>
#include <sys/time.h> // time_t

typedef struct _TimeStamp
{
uint64_t wallClock;
uint64_t userCPU;
uint64_t systemCPU;
} TimeStamp;

class PerfClock
{
Expand All @@ -38,13 +44,6 @@ class PerfClock
microsecond = 1,
millisecond = 1000,
} TimeUnit;

typedef struct _TimeStamp
{
uint64_t wallClock;
uint64_t userCPU;
uint64_t systemCPU;
} TimeStamp;

PerfClock(TimeStamp* pTS);
PerfClock();
Expand All @@ -64,6 +63,8 @@ class PerfClock
static PerfClock* Now();
static void Now(PerfClock* pClock, Operation operation = Marker);

const TimeStamp& GetTimeStamp() const;

private:
uint64_t ConvertToUS(time_t sec, time_t usec);

Expand Down
Loading