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
3 changes: 1 addition & 2 deletions PerformanceMonitor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ find_package(CompileSettingsDebug CONFIG REQUIRED)

add_library(${MODULE_NAME} SHARED
Module.cpp
PerformanceMonitor.cpp
PerformanceMonitorJsonRpc.cpp)
PerformanceMonitor.cpp)

set_target_properties(${MODULE_NAME} PROPERTIES
CXX_STANDARD 11
Expand Down
91 changes: 33 additions & 58 deletions PerformanceMonitor/PerformanceMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,94 +45,69 @@ namespace Plugin {
ASSERT(service != nullptr);
_skipURL = static_cast<uint8_t>(service->WebPrefix().length());

Exchange::JPerformance::Register(*this, this);
Exchange::JPerformanceStatistics::Register(*this, this);

return string();
}

/* virtual */ void PerformanceMonitor::Deinitialize(PluginHost::IShell* service VARIABLE_IS_NOT_USED)
{
Exchange::JPerformance::Unregister(*this);
Exchange::JPerformanceStatistics::Unregister(*this);
}

/* virtual */ string PerformanceMonitor::Information() const
{
// No additional info to report.
return ((_T("The purpose of this plugin is provide ability to collect performance values of JSONRPC communication")));
}
uint32_t PerformanceMonitor::RetrieveInfo(const uint32_t packageSize, JsonData::PerformanceMonitor::MeasurementData& measurementData) const {
const PluginHost::PerformanceAdministrator::Statistics& statistics(PluginHost::PerformanceAdministrator::Instance().Retrieve(packageSize));

Measurement(statistics.Serialization(), measurementData.Serialization);
Measurement(statistics.Deserialization(), measurementData.Deserialization);
Measurement(statistics.Execution(), measurementData.Execution);
Measurement(statistics.ThreadPool(), measurementData.Threadpool);
Measurement(statistics.Communication(), measurementData.Communication);
Measurement(statistics.Total(), measurementData.Total);

return Core::ERROR_NONE;
}

uint32_t PerformanceMonitor::Send(const JsonData::PerformanceMonitor::BufferInfo& data, Core::JSON::DecUInt32& result)
Core::hresult PerformanceMonitor::Send(const uint16_t /* sendSize */, const uint8_t* /* buffer */)
{
uint16_t length = static_cast<uint16_t>(((data.Data.Value().length() * 6) + 7) / 8);
uint8_t* buffer = static_cast<uint8_t*>(ALLOCA(length));
Core::FromString(data.Data.Value(), buffer, length);
result = length;

return Core::ERROR_NONE;
return (Core::ERROR_NONE);
}

uint32_t PerformanceMonitor::Receive(const Core::JSON::DecUInt32& maxSize, JsonData::PerformanceMonitor::BufferInfo& data)
Core::hresult PerformanceMonitor::Receive(uint16_t& bufferSize, uint8_t buffer[]) const
{
string convertedBuffer;

uint32_t length = maxSize.Value();
uint8_t* buffer = static_cast<uint8_t*>(ALLOCA(length));

static uint8_t pattern[] = { 0x00, 0x66, 0xBB, 0xEE };
uint8_t pattern[] = { 0x00, 0x66, 0xBB, 0xEE };
uint8_t patternLength = sizeof(pattern);
uint32_t index = 0;
uint8_t patternIndex = 0;

while (index < length) {

buffer[index++] = pattern[patternIndex++];

patternIndex %= (patternLength - 1);
}
FillBuffer(bufferSize, buffer, patternLength, pattern);

Core::ToString(buffer, length, false, convertedBuffer);
data.Data = convertedBuffer;
data.Length = static_cast<uint16_t>(convertedBuffer.length());
data.Duration = static_cast<uint16_t>(convertedBuffer.length()) + 1; //Dummy

return Core::ERROR_NONE;
return (Core::ERROR_NONE);
}

uint32_t PerformanceMonitor::Exchange(const JsonData::PerformanceMonitor::BufferInfo& data, JsonData::PerformanceMonitor::BufferInfo& result)
Core::hresult PerformanceMonitor::Exchange(uint16_t& /* bufferSize */, uint8_t buffer[], const uint16_t maxBufferSize)
{
string convertedBuffer;
uint8_t pattern[] = { 0x00, 0x77, 0xCC, 0x88 };
uint8_t patternLength = sizeof(pattern);

uint16_t length = static_cast<uint16_t>(data.Data.Value().length());
uint8_t* buffer = static_cast<uint8_t*>(ALLOCA(length));
Core::FromString(data.Data.Value(), buffer, length);
FillBuffer(maxBufferSize, buffer, patternLength, pattern);

static uint8_t pattern[] = { 0x00, 0x77, 0xCC, 0x88 };
uint8_t patternLength = sizeof(pattern);
uint16_t index = 0;
uint8_t patternIndex = 0;
return (Core::ERROR_NONE);
}

while (index < data.Length.Value()) {
Core::hresult PerformanceMonitor::Measurement(const uint32_t index, Exchange::IPerformanceStatistics::Measurements& measurement) const
{
const PluginHost::PerformanceAdministrator::Statistics& statistics(PluginHost::PerformanceAdministrator::Instance().Retrieve(index));

buffer[index++] = pattern[patternIndex++];
Measurement(statistics.Serialization(), measurement.serialization);
Measurement(statistics.Deserialization(), measurement.deserialization);
Measurement(statistics.Execution(), measurement.execution);
Measurement(statistics.ThreadPool(), measurement.threadPool);
Measurement(statistics.Communication(), measurement.communication);
Measurement(statistics.Total(), measurement.total);

patternIndex %= (patternLength - 1);
}
return (Core::ERROR_NONE);
}

Core::ToString(buffer, length, false, convertedBuffer);
result.Data = convertedBuffer;
result.Length = static_cast<uint16_t>(convertedBuffer.length());
result.Duration = static_cast<uint16_t>(convertedBuffer.length()) + 1; //Dummy
Core::hresult PerformanceMonitor::Reset()
{
PluginHost::PerformanceAdministrator::Instance().Clear();

return Core::ERROR_NONE;
return (Core::ERROR_NONE);
}

} // namespace Plugin
} // namespace Thunder
70 changes: 41 additions & 29 deletions PerformanceMonitor/PerformanceMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,31 @@
#pragma once

#include "Module.h"

#include <interfaces/json/JsonData_PerformanceMonitor.h>
#include <interfaces/IPerformance.h>
#include <interfaces/json/JPerformance.h>
#include <interfaces/json/JPerformanceStatistics.h>

namespace Thunder {
namespace Plugin {

class PerformanceMonitor : public PluginHost::IPlugin, public PluginHost::JSONRPC {
class PerformanceMonitor : public Exchange::IPerformance
, public Exchange::IPerformanceStatistics
, public PluginHost::IPlugin
, public PluginHost::JSONRPC {
public:
PerformanceMonitor(const PerformanceMonitor&) = delete;
PerformanceMonitor& operator=(const PerformanceMonitor&) = delete;

public:
PerformanceMonitor()
: _skipURL(0)
{
RegisterAll();
: _skipURL(0) {
}

~PerformanceMonitor() override
{
UnregisterAll();
}
~PerformanceMonitor() override = default;

BEGIN_INTERFACE_MAP(PerformanceMonitor)
INTERFACE_ENTRY(Exchange::IPerformance)
INTERFACE_ENTRY(Exchange::IPerformanceStatistics)
INTERFACE_ENTRY(PluginHost::IPlugin)
INTERFACE_ENTRY(PluginHost::IDispatcher)
END_INTERFACE_MAP
Expand All @@ -55,25 +56,36 @@ namespace Plugin {
string Information() const override;

private:
void RegisterAll();
void UnregisterAll();
uint32_t endpoint_clear();
uint32_t endpoint_send(const JsonData::PerformanceMonitor::BufferInfo& params, Core::JSON::DecUInt32& response);
uint32_t endpoint_receive(const Core::JSON::DecUInt32& params, JsonData::PerformanceMonitor::BufferInfo& response);
uint32_t endpoint_exchange(const JsonData::PerformanceMonitor::BufferInfo& params, JsonData::PerformanceMonitor::BufferInfo& response);
uint32_t get_measurement(const string& index, JsonData::PerformanceMonitor::MeasurementData& response) const;

uint32_t RetrieveInfo(const uint32_t packageSize, JsonData::PerformanceMonitor::MeasurementData& measurementData) const;
uint32_t Send(const JsonData::PerformanceMonitor::BufferInfo& data, Core::JSON::DecUInt32& result);
uint32_t Receive(const Core::JSON::DecUInt32& maxSize, JsonData::PerformanceMonitor::BufferInfo& data);
uint32_t Exchange(const JsonData::PerformanceMonitor::BufferInfo& data, JsonData::PerformanceMonitor::BufferInfo& result);

inline void Measurement(const PluginHost::PerformanceAdministrator::Statistics::Tuple& statistics, JsonData::PerformanceMonitor::MeasurementData::StatisticsData& statisticsData) const {

statisticsData.Minimum = statistics.Minimum();
statisticsData.Maximum = statistics.Maximum();
statisticsData.Average = statistics.Average();
statisticsData.Count = statistics.Count();
// IPerformance methods - a majority of the code for performance measurement is provided by the generators
// -------------------------------------------------------------------------------------------------------
Core::hresult Send(const uint16_t sendSize, const uint8_t buffer[]) override;
Core::hresult Receive(uint16_t& bufferSize, uint8_t buffer[]) const override;
Core::hresult Exchange(uint16_t& bufferSize, uint8_t buffer[], const uint16_t maxBufferSize) override;

// IPerformanceStatistics methods
// -------------------------------------------------------------------------------------------------------
Core::hresult Measurement(const uint32_t index, Exchange::IPerformanceStatistics::Measurements& measurement) const override;
Core::hresult Reset() override;

inline void Measurement(const PluginHost::PerformanceAdministrator::Statistics::Tuple& statistics, Exchange::IPerformanceStatistics::Statistics& statisticsData) const
{
statisticsData.minimum = statistics.Minimum();
statisticsData.maximum = statistics.Maximum();
statisticsData.average = statistics.Average();
statisticsData.count = statistics.Count();
}

inline void FillBuffer(const uint16_t& bufferSize, uint8_t buffer[], const uint8_t patternLength, const uint8_t pattern[]) const
{
uint32_t index = 0;
uint8_t patternIndex = 0;

while (index < bufferSize) {

buffer[index++] = pattern[patternIndex++];

patternIndex %= (patternLength - 1);
}
}

private:
Expand Down
94 changes: 0 additions & 94 deletions PerformanceMonitor/PerformanceMonitorJsonRpc.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion PerformanceMonitor/PerformanceMonitorPlugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"version": "1.0"
},
"interface": {
"$ref": "{interfacedir}/PerformanceMonitor.json#"
"$ref": "{cppinterfacedir}/IPerformance.h"
}
}
Loading
Loading