mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-11 13:35:27 +00:00
parent
ab7c0b40f2
commit
4fd1b52d1f
@ -14,32 +14,33 @@
|
|||||||
#ifndef _BACKEND_H_
|
#ifndef _BACKEND_H_
|
||||||
#define _BACKEND_H_
|
#define _BACKEND_H_
|
||||||
|
|
||||||
|
/* Genode includes */
|
||||||
|
#include <util/dictionary.h>
|
||||||
|
|
||||||
/* local includes */
|
/* local includes */
|
||||||
#include <named_registry.h>
|
|
||||||
#include <writer.h>
|
#include <writer.h>
|
||||||
|
|
||||||
namespace Trace_recorder {
|
namespace Trace_recorder {
|
||||||
class Backend_base;
|
class Backend_base;
|
||||||
|
|
||||||
using Backends = Named_registry<Backend_base>;
|
using Backend_name = Genode::String<64>;
|
||||||
|
using Backends = Genode::Dictionary<Backend_base, Backend_name>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Trace_recorder::Backend_base : Backends::Element
|
class Trace_recorder::Backend_base : Backends::Element
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
friend class Backends::Element;
|
friend class Genode::Dictionary<Backend_base, Backend_name>;
|
||||||
friend class Avl_node<Backend_base>;
|
friend class Genode::Avl_node<Backend_base>;
|
||||||
friend class Avl_tree<Backend_base>;
|
friend class Genode::Avl_tree<Backend_base>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
using Name = Backend_name;
|
||||||
using Name = Backends::Element::Name;
|
|
||||||
using Backends::Element::name;
|
using Backends::Element::name;
|
||||||
using Backends::Element::Element;
|
|
||||||
|
|
||||||
Backend_base(Backends & registry, Name const &name)
|
Backend_base(Backends & backends, Name const &name)
|
||||||
: Backends::Element(registry, name)
|
: Backends::Element(backends, name)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual ~Backend_base() { }
|
virtual ~Backend_base() { }
|
||||||
|
@ -104,11 +104,14 @@ void Trace_recorder::Monitor::start(Xml_node config)
|
|||||||
|
|
||||||
/* find and assign policy; create/insert if not present */
|
/* find and assign policy; create/insert if not present */
|
||||||
Policy::Name const policy_name = session_policy.attribute_value("policy", Policy::Name());
|
Policy::Name const policy_name = session_policy.attribute_value("policy", Policy::Name());
|
||||||
bool create = true;
|
bool const create =
|
||||||
_policies.apply(policy_name, [&] (Policy & policy) {
|
_policies.with_element(policy_name,
|
||||||
_trace.trace(id, policy.id(), buffer_sz);
|
[&] /* match */ (Policy & policy) {
|
||||||
create = false;
|
_trace.trace(id, policy.id(), buffer_sz);
|
||||||
});
|
return false;
|
||||||
|
},
|
||||||
|
[&] /* no_match */ { return true; }
|
||||||
|
);
|
||||||
|
|
||||||
/* create policy if it did not exist */
|
/* create policy if it did not exist */
|
||||||
if (create) {
|
if (create) {
|
||||||
@ -128,14 +131,17 @@ void Trace_recorder::Monitor::start(Xml_node config)
|
|||||||
|
|
||||||
/* create and register writers at trace buffer */
|
/* create and register writers at trace buffer */
|
||||||
session_policy.for_each_sub_node([&] (Xml_node & node) {
|
session_policy.for_each_sub_node([&] (Xml_node & node) {
|
||||||
bool present = false;
|
bool const present =
|
||||||
_backends.apply(node.type(), [&] (Backend_base &backend) {
|
_backends.with_element(node.type(),
|
||||||
backend.create_writer(_alloc,
|
[&] /* match */ (Backend_base &backend) {
|
||||||
buffer.writers(),
|
backend.create_writer(_alloc,
|
||||||
_trace_directory->root(),
|
buffer.writers(),
|
||||||
_trace_directory->subject_path(buffer.info()));
|
_trace_directory->root(),
|
||||||
present = true;
|
_trace_directory->subject_path(buffer.info()));
|
||||||
});
|
return true;
|
||||||
|
},
|
||||||
|
[&] /* no_match */ { return false; }
|
||||||
|
);
|
||||||
|
|
||||||
if (!present)
|
if (!present)
|
||||||
error("No writer available for <", node.type(), "/>.");
|
error("No writer available for <", node.type(), "/>.");
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* \brief Utility for finding objecs by name
|
|
||||||
* \author Norman Feske
|
|
||||||
* \date 2021-11-11
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2021 Genode Labs GmbH
|
|
||||||
*
|
|
||||||
* This file is part of the Genode OS framework, which is distributed
|
|
||||||
* under the terms of the GNU Affero General Public License version 3.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _NAMED_REGISTRY_H_
|
|
||||||
#define _NAMED_REGISTRY_H_
|
|
||||||
|
|
||||||
#include <util/string.h>
|
|
||||||
#include <util/avl_tree.h>
|
|
||||||
#include <util/noncopyable.h>
|
|
||||||
|
|
||||||
namespace Trace_recorder {
|
|
||||||
using namespace Genode;
|
|
||||||
|
|
||||||
template <typename T> class Named_registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class Trace_recorder::Named_registry : Noncopyable
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
|
|
||||||
Avl_tree<T> _tree { };
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
class Element : private Avl_node<T>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
using Name = Genode::String<64>;
|
|
||||||
Name const name;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Named_registry<T> &_registry;
|
|
||||||
|
|
||||||
bool higher(T const *other) const { return name > other->name; }
|
|
||||||
|
|
||||||
friend class Avl_tree<T>;
|
|
||||||
friend class Avl_node<T>;
|
|
||||||
friend class Named_registry<T>;
|
|
||||||
|
|
||||||
static T *_matching_sub_tree(T &curr, Name const &name)
|
|
||||||
{
|
|
||||||
typename Avl_node<T>::Side side = (curr.name > name);
|
|
||||||
|
|
||||||
return curr.Avl_node<T>::child(side);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Element(Named_registry ®istry, Name const &name)
|
|
||||||
:
|
|
||||||
name(name), _registry(registry)
|
|
||||||
{
|
|
||||||
_registry._tree.insert(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~Element()
|
|
||||||
{
|
|
||||||
_registry._tree.remove(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename FN>
|
|
||||||
void apply(typename Element::Name const &name, FN && fn)
|
|
||||||
{
|
|
||||||
T *curr_ptr = _tree.first();
|
|
||||||
for (;;) {
|
|
||||||
if (!curr_ptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (curr_ptr->name == name) {
|
|
||||||
fn(*curr_ptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
curr_ptr = Element::_matching_sub_tree(*curr_ptr, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename FN>
|
|
||||||
void for_each(FN && fn) { _tree.for_each(fn); }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* _NAMED_REGISTRY_H_ */
|
|
@ -19,9 +19,9 @@ using namespace Genode;
|
|||||||
Trace_recorder::Policy::Policy(Env &env,
|
Trace_recorder::Policy::Policy(Env &env,
|
||||||
Trace::Connection &trace,
|
Trace::Connection &trace,
|
||||||
Policy::Name const &name,
|
Policy::Name const &name,
|
||||||
Policies ®istry)
|
Policies &policies)
|
||||||
:
|
:
|
||||||
Policies::Element(registry, name),
|
Policies::Element(policies, name),
|
||||||
_env(env), _trace(trace), _rom(env, name.string())
|
_env(env), _trace(trace), _rom(env, name.string())
|
||||||
{
|
{
|
||||||
Dataspace_capability dst_ds = _trace.policy(_id);
|
Dataspace_capability dst_ds = _trace.policy(_id);
|
||||||
|
@ -14,10 +14,8 @@
|
|||||||
#ifndef _POLICY_H_
|
#ifndef _POLICY_H_
|
||||||
#define _POLICY_H_
|
#define _POLICY_H_
|
||||||
|
|
||||||
/* local includes */
|
|
||||||
#include <named_registry.h>
|
|
||||||
|
|
||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
|
#include <util/dictionary.h>
|
||||||
#include <rom_session/connection.h>
|
#include <rom_session/connection.h>
|
||||||
#include <trace_session/connection.h>
|
#include <trace_session/connection.h>
|
||||||
#include <dataspace/client.h>
|
#include <dataspace/client.h>
|
||||||
@ -25,7 +23,8 @@
|
|||||||
namespace Trace_recorder {
|
namespace Trace_recorder {
|
||||||
class Policy;
|
class Policy;
|
||||||
|
|
||||||
using Policies = Named_registry<Policy>;
|
using Policy_name = Genode::String<64>;
|
||||||
|
using Policies = Genode::Dictionary<Policy, Policy_name>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ namespace Trace_recorder {
|
|||||||
class Trace_recorder::Policy : Policies::Element
|
class Trace_recorder::Policy : Policies::Element
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
friend class Policies::Element;
|
friend class Genode::Dictionary<Policy, Policy_name>;
|
||||||
friend class Genode::Avl_node<Policy>;
|
friend class Genode::Avl_node<Policy>;
|
||||||
friend class Genode::Avl_tree<Policy>;
|
friend class Genode::Avl_tree<Policy>;
|
||||||
|
|
||||||
@ -48,14 +47,13 @@ class Trace_recorder::Policy : Policies::Element
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Name = Policies::Element::Name;
|
using Name = Policy_name;
|
||||||
using Policies::Element::name;
|
using Policies::Element::name;
|
||||||
using Policies::Element::Element;
|
|
||||||
|
|
||||||
Policy(Genode::Env &env,
|
Policy(Genode::Env &env,
|
||||||
Genode::Trace::Connection &trace,
|
Genode::Trace::Connection &trace,
|
||||||
Name const &name,
|
Name const &name,
|
||||||
Policies ®istry);
|
Policies &policies);
|
||||||
|
|
||||||
|
|
||||||
/***************
|
/***************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user