Commit 729cd427 authored by Frediano Ziglio's avatar Frediano Ziglio

Add support log logging statistics from plugins

Allows the plugins to add information to the log.
Signed-off-by: Frediano Ziglio's avatarFrediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin's avatarUri Lublin <uril@redhat.com>
parent fead67ba
Pipeline #34549 passed with stage
in 7 minutes and 38 seconds
......@@ -28,7 +28,7 @@ class FrameCapture;
* where MM is major and mm is the minor, can be easily expanded
* using more bits in the future
*/
enum Constants : unsigned { PluginVersion = 0x100u };
enum Constants : unsigned { PluginVersion = 0x101u };
enum Ranks : unsigned {
/// this plugin should not be used
......@@ -116,6 +116,11 @@ public:
* \todo passing options to entry point instead?
*/
virtual const ConfigureOption* Options() const = 0;
/*!
* Write something in the log.
*/
__attribute__ ((format (printf, 2, 3)))
virtual void LogStat(const char* format, ...) = 0;
};
typedef bool PluginInitFunc(spice::streaming_agent::Agent* agent);
......
......@@ -5,13 +5,15 @@
*/
#include <config.h>
#include "concrete-agent.hpp"
#include "frame-log.hpp"
#include <algorithm>
#include <syslog.h>
#include <glob.h>
#include <dlfcn.h>
#include <string>
#include "concrete-agent.hpp"
#include <cstdarg>
using namespace spice::streaming_agent;
......@@ -25,8 +27,9 @@ static inline unsigned MinorVersion(unsigned version)
return version & 0xffu;
}
ConcreteAgent::ConcreteAgent(const std::vector<ConcreteConfigureOption> &options):
options(options)
ConcreteAgent::ConcreteAgent(const std::vector<ConcreteConfigureOption> &options, FrameLog *logger):
options(options),
logger(logger)
{
this->options.push_back(ConcreteConfigureOption(nullptr, nullptr));
}
......@@ -140,3 +143,13 @@ FrameCapture *ConcreteAgent::GetBestFrameCapture(const std::set<SpiceVideoCodecT
}
return nullptr;
}
void ConcreteAgent::LogStat(const char* format, ...)
{
if (logger) {
va_list ap;
va_start(ap, format);
logger->log_statv(format, ap);
va_end(ap);
}
}
......@@ -14,6 +14,8 @@
namespace spice {
namespace streaming_agent {
class FrameLog;
struct ConcreteConfigureOption: ConfigureOption
{
ConcreteConfigureOption(const char *name, const char *value)
......@@ -26,16 +28,20 @@ struct ConcreteConfigureOption: ConfigureOption
class ConcreteAgent final : public Agent
{
public:
ConcreteAgent(const std::vector<ConcreteConfigureOption> &options);
ConcreteAgent(const std::vector<ConcreteConfigureOption> &options,
FrameLog *logger=nullptr);
void Register(const std::shared_ptr<Plugin>& plugin) override;
const ConfigureOption* Options() const override;
void LoadPlugins(const std::string &directory);
FrameCapture *GetBestFrameCapture(const std::set<SpiceVideoCodecType>& codecs);
__attribute__ ((format (printf, 2, 3)))
void LogStat(const char* format, ...) override;
private:
bool PluginVersionIsCompatible(unsigned pluginVersion) const;
void LoadPlugin(const std::string &plugin_filename);
std::vector<std::shared_ptr<Plugin>> plugins;
std::vector<ConcreteConfigureOption> options;
FrameLog *const logger = nullptr;
};
}} // namespace spice::streaming_agent
......
......@@ -41,13 +41,18 @@ FrameLog::~FrameLog()
}
void FrameLog::log_stat(const char* format, ...)
{
va_list ap;
va_start(ap, format);
log_statv(format, ap);
va_end(ap);
}
void FrameLog::log_statv(const char* format, va_list ap)
{
if (log_file && !log_binary) {
fprintf(log_file, "%" PRIu64 ": ", get_time());
va_list ap;
va_start(ap, format);
vfprintf(log_file, format, ap);
va_end(ap);
fputc('\n', log_file);
}
}
......
......@@ -24,6 +24,8 @@ public:
__attribute__ ((format (printf, 2, 3)))
void log_stat(const char* format, ...);
__attribute__ ((format (printf, 2, 0)))
void log_statv(const char* format, va_list ap);
void log_frame(const void* buffer, size_t buffer_size);
static uint64_t get_time();
......
......@@ -401,15 +401,15 @@ int main(int argc, char* argv[])
register_interrupts();
try {
ConcreteAgent agent(options);
FrameLog frame_log(log_filename, log_binary, log_frames);
ConcreteAgent agent(options, &frame_log);
// register built-in plugins
MjpegPlugin::Register(&agent);
agent.LoadPlugins(pluginsdir);
FrameLog frame_log(log_filename, log_binary, log_frames);
for (const std::string& arg: old_args) {
frame_log.log_stat("Args: %s", arg.c_str());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment