From 8698e693d59b7fb43df7ee0c59eb27bf498f6126 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 6 Mar 2023 17:12:18 +0100 Subject: [PATCH] trace_logger: replace Avl_string by Dictionary Issue #4780 --- repos/os/src/app/trace_logger/main.cc | 25 ++++---- repos/os/src/app/trace_logger/policy.cc | 43 +------------ repos/os/src/app/trace_logger/policy.h | 81 +++---------------------- 3 files changed, 22 insertions(+), 127 deletions(-) diff --git a/repos/os/src/app/trace_logger/main.cc b/repos/os/src/app/trace_logger/main.cc index 607265ce78..fbb0abdb67 100644 --- a/repos/os/src/app/trace_logger/main.cc +++ b/repos/os/src/app/trace_logger/main.cc @@ -67,8 +67,9 @@ class Main Monitor_tree _monitors_0 { }; Monitor_tree _monitors_1 { }; bool _monitors_switch { false }; - Policy_tree _policies { }; - Policy _default_policy { _env, _trace, _config.default_policy_name }; + Policy_dict _policies { }; + Policy _default_policy { _env, _trace, _policies, + _config.default_policy_name }; unsigned long _report_id { 0 }; static void _print_monitors(Allocator &alloc, Monitor_tree const &, @@ -181,15 +182,15 @@ class Main Policy_name const policy_name = session_policy.attribute_value("policy", _config.default_policy_name); - try { - _trace.trace(id.id, _policies.find_by_name(policy_name).id(), buffer_sz); - - } - catch (Policy_tree::No_match) { - Policy &policy = *new (_heap) Policy(_env, _trace, policy_name); - _policies.insert(policy); - _trace.trace(id.id, policy.id(), buffer_sz); - } + _policies.with_element(policy_name, + [&] (Policy const &policy) { + _trace.trace(id.id, policy.id(), buffer_sz); + }, + [&] /* no match */ { + Policy &policy = *new (_heap) Policy(_env, _trace, _policies, policy_name); + _trace.trace(id.id, policy.id(), buffer_sz); + } + ); monitors.insert(new (_heap) Monitor(_trace, _env.rm(), id)); } catch (Trace::Source_is_dead ) { warn_msg("Source_is_dead" ); return; } @@ -215,8 +216,6 @@ class Main Main(Env &env) : _env(env) { - _policies.insert(_default_policy); - _update_monitors(); } }; diff --git a/repos/os/src/app/trace_logger/policy.cc b/repos/os/src/app/trace_logger/policy.cc index ac48619084..918e5d639b 100644 --- a/repos/os/src/app/trace_logger/policy.cc +++ b/repos/os/src/app/trace_logger/policy.cc @@ -17,24 +17,10 @@ using namespace Genode; -/*********************** - ** Policy_avl_member ** - ***********************/ - -Policy_avl_member::Policy_avl_member(Policy_name const &name, - ::Policy &policy) +Policy::Policy(Env &env, Trace::Connection &trace, Policy_dict &dict, + Policy_name const &name) : - Avl_string_base(name.string()), _policy(policy) -{ } - - -/************ - ** Policy ** - ************/ - -Policy::Policy(Env &env, Trace::Connection &trace, Policy_name const &name) -: - Policy_base(name), _avl_member(_name, *this), _env(env), _trace(trace) + Policy_dict::Element(dict, name), _env(env), _trace(trace) { Dataspace_capability dst_ds = _trace.policy(_id); void *dst = _env.rm().attach(dst_ds); @@ -43,26 +29,3 @@ Policy::Policy(Env &env, Trace::Connection &trace, Policy_name const &name) _env.rm().detach(dst); _env.rm().detach(src); } - - -/***************** - ** Policy_tree ** - *****************/ - -Policy &Policy_tree::policy(Avl_string_base const &node) -{ - return static_cast(&node)->policy(); -} - - -Policy &Policy_tree::find_by_name(Policy_name name) -{ - if (name == Policy_name() || !first()) { - throw No_match(); } - - Avl_string_base *node = first()->find_by_name(name.string()); - if (!node) { - throw No_match(); } - - return policy(*node); -} diff --git a/repos/os/src/app/trace_logger/policy.h b/repos/os/src/app/trace_logger/policy.h index 46921a4be8..9876b91a9b 100644 --- a/repos/os/src/app/trace_logger/policy.h +++ b/repos/os/src/app/trace_logger/policy.h @@ -18,103 +18,36 @@ #include #include #include -#include - -using Policy_name = Genode::String<40>; +#include class Policy; - -/** - * Member of a policy that allows the policy to be managed in a tree - */ -class Policy_avl_member : public Genode::Avl_string_base -{ - private: - - ::Policy &_policy; - - public: - - Policy_avl_member(Policy_name const &name, - ::Policy &policy); - - - /*************** - ** Accessors ** - ***************/ - - ::Policy &policy() const { return _policy; } -}; - - -/** - * Ensure that policy name is constructed before it is used as tree index - */ -class Policy_base -{ - protected: - - Policy_name const _name; - - Policy_base(Policy_name const &name) : _name(name) { } -}; +using Policy_name = Genode::String<40>; +using Policy_dict = Genode::Dictionary; /** * Installs and maintains a tracing policy */ -class Policy : public Policy_base +class Policy : public Policy_dict::Element { private: - Policy_avl_member _avl_member; Genode::Env &_env; Genode::Trace::Connection &_trace; - Genode::Rom_connection _rom { _env, _name.string() }; + Genode::Rom_connection _rom { _env, name }; Genode::Rom_dataspace_capability const _ds { _rom.dataspace() }; Genode::size_t const _size { Genode::Dataspace_client(_ds).size() }; Genode::Trace::Policy_id const _id { _trace.alloc_policy(_size) }; public: - Policy(Genode::Env &env, Genode::Trace::Connection &trace, + Policy_dict &dict, Policy_name const &name); - - /*************** - ** Accessors ** - ***************/ - - Genode::Trace::Policy_id id() const { return _id; } - Policy_avl_member &avl_member() { return _avl_member; } + Genode::Trace::Policy_id id() const { return _id; } }; - -/** - * AVL tree of policies with their name as index - */ -struct Policy_tree : Genode::Avl_tree -{ - using Avl_tree = Genode::Avl_tree; - - struct No_match : Genode::Exception { }; - - static ::Policy &policy(Genode::Avl_string_base const &node); - - ::Policy &find_by_name(Policy_name name); - - template - void for_each(FUNC && functor) const { - Avl_tree::for_each([&] (Genode::Avl_string_base const &node) { - functor(policy(node)); - }); - } - - void insert(::Policy &policy) { Avl_tree::insert(&policy.avl_member()); } -}; - - #endif /* _POLICY_H_ */