Skip to content

Commit

Permalink
Merge pull request #186 from code-mancers/add-cpu-sampling-event
Browse files Browse the repository at this point in the history
Add cpu sampling event
  • Loading branch information
iffyuva committed Jul 16, 2015
2 parents f9c982f + 826a6bd commit 4367ea9
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 2 deletions.
1 change: 0 additions & 1 deletion rbkit-lib/mpparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ RBKit::ObjectDetail& operator>>(msgpack::object obj, RBKit::ObjectDetail& object
return object;
}


RBKit::ObjectDetailPtr& operator>>(msgpack::object obj, RBKit::ObjectDetailPtr& ptr)
{
if (obj.type != msgpack::type::MAP) { throw msgpack::type_error(); }
Expand Down
4 changes: 4 additions & 0 deletions rbkit-lib/rbeventparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ RBKit::EventParser::eventFromMsgpackObject(const msgpack::object& object) const
event = new RBKit::EvtHandshake(timestamp, eventType, payload.as<QVariantMap>());
break;

case RBKit::EtCpuSample:
event = new RBKit::EvtCpuSample(timestamp, eventType, payload.as<QList<QMap<int, QVariant>>>());
break;

default:
qDebug() << "Unable to parse event of type: " << eventType;
}
Expand Down
11 changes: 11 additions & 0 deletions rbkit-lib/rbevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@ void RBKit::EvtHandshake::process(Subscriber &processor) const
{
processor.processEvent(*this);
}

RBKit::EvtCpuSample::EvtCpuSample(QDateTime ts, RBKit::EventType eventType, QList<QMap<int, QVariant> > payload)
: EventDataBase(ts, eventType)
{
qDebug() << payload;
}

void RBKit::EvtCpuSample::process(Subscriber &processor) const
{
processor.processEvent(*this);
}
10 changes: 9 additions & 1 deletion rbkit-lib/rbevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace RBKit
EtObjectSpaceDump = 5,
EtGcStats = 6,
EtEventCollection = 7,
EtHandshake = 8
EtHandshake = 8,
EtCpuSample = 9
};


Expand Down Expand Up @@ -128,6 +129,13 @@ namespace RBKit
quint32 pid;
bool tracingFlag;
};

class EvtCpuSample : public EventDataBase
{
public:
EvtCpuSample(QDateTime ts, EventType eventType, QList<QMap<int, QVariant>> payload);
void process(Subscriber& processor) const;
};
}


Expand Down
4 changes: 4 additions & 0 deletions rbkit-lib/subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ void Subscriber::processEvent(const RBKit::EvtHandshake &handShake)
qDebug() << "Should not have come here";
}

void Subscriber::processEvent(const RBKit::EvtCpuSample &cpuSample) {
qDebug() << cpuSample.eventType << "===";
}

void Subscriber::performHandshake()
{
context->start();
Expand Down
1 change: 1 addition & 0 deletions rbkit-lib/subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Subscriber : public QObject
void processEvent(const RBKit::EvtObjectDump&);
void processEvent(const RBKit::EvtCollection&);
void processEvent(const RBKit::EvtHandshake&handShake);
void processEvent(const RBKit::EvtCpuSample&);
void performHandshake();
void handShakeCompleted();
void emitConnectionError(QString message);
Expand Down
Binary file added tests/msgpack/cpusample
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/testrbevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,19 @@ void TestRbEvents::testParseObjectDumpEvent()
EvtObjectDump* event = dynamic_cast<EvtObjectDump*>(collection->events[0].data());
QVERIFY(event);
}


void TestRbEvents::testParseCpuSampleEvent()
{
QByteArray data = msgpackDataFromFile(":/tests/msgpack/cpusample");
RBKit::EventParser eventParser(data);

auto base = eventParser.parseEvent();
QVERIFY(base);

auto collection = dynamic_cast<EvtCollection*>(base);
QVERIFY(collection);

EvtCpuSample* event = dynamic_cast<EvtCpuSample*>(collection->events[0].data());
QVERIFY(event);
}
1 change: 1 addition & 0 deletions tests/testrbevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private slots:
void testParseGcStatsEvent();
void testParseGCStartEvent();
void testParseObjectDumpEvent();
void testParseCpuSampleEvent();
};

#endif // TEST_RBKIT_EVENTS_H
1 change: 1 addition & 0 deletions tests/tests.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<file>msgpack/objectdump</file>
<file>msgpack/hugedump</file>
<file>msgpack/split_dump</file>
<file>msgpack/cpusample</file>
</qresource>
<qresource prefix="/"/>
</RCC>

0 comments on commit 4367ea9

Please sign in to comment.