mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-29 15:44:02 +00:00
parent
062881a484
commit
758ba3855e
30
repos/gems/include/trace_recorder_policy/ctf.h
Normal file
30
repos/gems/include/trace_recorder_policy/ctf.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* \brief CTF event base type for the trace recorder
|
||||
* \author Johannes Schlatow
|
||||
* \date 2022-05-20
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 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 _TRACE_RECORDER_POLICY__CTF_H_
|
||||
#define _TRACE_RECORDER_POLICY__CTF_H_
|
||||
|
||||
#include <ctf/event_header.h>
|
||||
#include <trace_recorder_policy/event.h>
|
||||
|
||||
namespace Trace_recorder { struct Ctf_event; }
|
||||
|
||||
struct Trace_recorder::Ctf_event : Trace_event<Event_type::CTF>,
|
||||
Ctf::Event_header_base
|
||||
{
|
||||
static Event_type Type() { return Event_type::CTF; }
|
||||
|
||||
Ctf_event(Genode::uint8_t id) : Ctf::Event_header_base(id) { }
|
||||
} __attribute__((packed));
|
||||
|
||||
#endif /* _TRACE_RECORDER_POLICY__CTF_H_ */
|
116
repos/gems/include/trace_recorder_policy/ctf_stream0.h
Normal file
116
repos/gems/include/trace_recorder_policy/ctf_stream0.h
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* \brief Stream id 0
|
||||
* \author Johannes Schlatow
|
||||
* \date 2021-08-04
|
||||
*
|
||||
* Defines CTF events for our CTF stream with id 0. This must match the
|
||||
* metadata file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 _TRACE_RECORDER_POLICY__CTF_STREAM0_H_
|
||||
#define _TRACE_RECORDER_POLICY__CTF_STREAM0_H_
|
||||
|
||||
#include <base/fixed_stdint.h>
|
||||
|
||||
#include <ctf/events/named.h>
|
||||
#include <trace_recorder_policy/ctf.h>
|
||||
|
||||
namespace Ctf {
|
||||
struct Rpc_call;
|
||||
struct Rpc_returned;
|
||||
struct Rpc_dispatch;
|
||||
struct Rpc_reply;
|
||||
struct Signal_submit;
|
||||
struct Signal_receive;
|
||||
struct Checkpoint;
|
||||
}
|
||||
|
||||
|
||||
struct Ctf::Rpc_call : Trace_recorder::Ctf_event,
|
||||
Ctf::Named_event
|
||||
{
|
||||
Rpc_call(const char *name, size_t len)
|
||||
: Trace_recorder::Ctf_event(1),
|
||||
Named_event(name, len)
|
||||
{ }
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct Ctf::Rpc_returned : Trace_recorder::Ctf_event,
|
||||
Ctf::Named_event
|
||||
{
|
||||
Rpc_returned(const char *name, size_t len)
|
||||
: Trace_recorder::Ctf_event(2),
|
||||
Named_event(name, len)
|
||||
{ }
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct Ctf::Rpc_dispatch : Trace_recorder::Ctf_event,
|
||||
Ctf::Named_event
|
||||
{
|
||||
Rpc_dispatch(const char *name, size_t len)
|
||||
: Trace_recorder::Ctf_event(3),
|
||||
Named_event(name, len)
|
||||
{ }
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct Ctf::Rpc_reply : Trace_recorder::Ctf_event,
|
||||
Ctf::Named_event
|
||||
{
|
||||
Rpc_reply(const char *name, size_t len)
|
||||
: Trace_recorder::Ctf_event(4),
|
||||
Named_event(name, len)
|
||||
{ }
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct Ctf::Signal_submit : Trace_recorder::Ctf_event
|
||||
{
|
||||
uint32_t _number;
|
||||
|
||||
Signal_submit(uint32_t number)
|
||||
: Trace_recorder::Ctf_event(5),
|
||||
_number(number)
|
||||
{ }
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct Ctf::Signal_receive : Trace_recorder::Ctf_event
|
||||
{
|
||||
uint32_t _number;
|
||||
uint64_t _context;
|
||||
|
||||
Signal_receive(uint32_t number, void* context)
|
||||
: Trace_recorder::Ctf_event(6),
|
||||
_number(number),
|
||||
_context((uint64_t)context)
|
||||
{ }
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct Ctf::Checkpoint : Trace_recorder::Ctf_event
|
||||
{
|
||||
uint32_t _data;
|
||||
uint64_t _addr;
|
||||
uint8_t _type;
|
||||
Named_event _named;
|
||||
|
||||
Checkpoint(const char *name, size_t len, uint32_t data, void* addr, uint8_t type)
|
||||
: Trace_recorder::Ctf_event(7),
|
||||
_data(data),
|
||||
_addr((uint64_t)addr),
|
||||
_type(type),
|
||||
_named(name, len)
|
||||
{ }
|
||||
} __attribute__((packed));
|
||||
|
||||
#endif /* _TRACE_RECORDER_POLICY__CTF_STREAM0_H_ */
|
64
repos/gems/include/trace_recorder_policy/event.h
Normal file
64
repos/gems/include/trace_recorder_policy/event.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* \brief Wrapper type for trace events with sub-types
|
||||
* \author Johannes Schlatow
|
||||
* \date 2022-05-20
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 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 _TRACE_RECORDER_POLICY__EVENT_H_
|
||||
#define _TRACE_RECORDER_POLICY__EVENT_H_
|
||||
|
||||
#include <base/exception.h>
|
||||
|
||||
namespace Trace_recorder {
|
||||
enum Event_type { PCAPNG = 1, CTF };
|
||||
|
||||
struct Trace_event_base;
|
||||
|
||||
template <Event_type>
|
||||
struct Trace_event;
|
||||
}
|
||||
|
||||
|
||||
struct Trace_recorder::Trace_event_base
|
||||
{
|
||||
struct Cast_failed : Genode::Exception { };
|
||||
|
||||
const Event_type _type;
|
||||
|
||||
Trace_event_base(Event_type type)
|
||||
: _type(type)
|
||||
{ }
|
||||
|
||||
Event_type type() const { return _type; }
|
||||
|
||||
template <typename T>
|
||||
T const &event() const
|
||||
{
|
||||
if (_type != T::Type())
|
||||
throw Cast_failed();
|
||||
|
||||
return *reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
/* define placement new since construct_at in policy inflates policy size */
|
||||
void *operator new(__SIZE_TYPE__, void *p) { return p; }
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
template <Trace_recorder::Event_type TYPE>
|
||||
struct Trace_recorder::Trace_event : Trace_event_base
|
||||
{
|
||||
Trace_event()
|
||||
: Trace_event_base(TYPE)
|
||||
{ }
|
||||
|
||||
} __attribute__((packed));
|
||||
|
||||
#endif /* _TRACE_RECORDER_POLICY__EVENT_H_ */
|
135
repos/gems/include/trace_recorder_policy/pcapng.h
Normal file
135
repos/gems/include/trace_recorder_policy/pcapng.h
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* \brief Types used by trace policy for pcapng events
|
||||
* \author Johannes Schlatow
|
||||
* \date 2022-05-12
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 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 _TRACE_RECORDER_POLICY__PCAPNG_H_
|
||||
#define _TRACE_RECORDER_POLICY__PCAPNG_H_
|
||||
|
||||
#include <util/construct_at.h>
|
||||
#include <util/string.h>
|
||||
#include <trace/timestamp.h>
|
||||
#include <trace_recorder_policy/event.h>
|
||||
|
||||
namespace Pcapng {
|
||||
using namespace Genode;
|
||||
|
||||
/* Link type as defined in Interface Description Block */
|
||||
enum Link_type { ETHERNET = 1 };
|
||||
|
||||
struct Interface_name;
|
||||
struct Traced_packet;
|
||||
}
|
||||
|
||||
namespace Trace_recorder {
|
||||
using namespace Genode;
|
||||
|
||||
class Pcapng_event;
|
||||
};
|
||||
|
||||
|
||||
struct Pcapng::Interface_name
|
||||
{
|
||||
enum : uint8_t { MAX_NAME_LEN = 40 };
|
||||
|
||||
uint16_t const _link_type;
|
||||
uint8_t _name_len;
|
||||
char _name[0] { };
|
||||
|
||||
Interface_name(Link_type type, bool out, char const *cstr)
|
||||
: _link_type(type),
|
||||
_name_len((uint8_t)(Genode::Cstring(cstr, MAX_NAME_LEN-5).length() + 1))
|
||||
{
|
||||
copy_cstring(_name, cstr, _name_len);
|
||||
if (out) {
|
||||
copy_cstring(&_name[_name_len-1], "_out", 5);
|
||||
_name_len += 4;
|
||||
} else {
|
||||
copy_cstring(&_name[_name_len-1], "_in", 4);
|
||||
_name_len += 3;
|
||||
}
|
||||
}
|
||||
|
||||
/* length including null-termination */
|
||||
uint8_t data_length() const { return _name_len; }
|
||||
|
||||
char const *string() const { return _name; }
|
||||
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/**
|
||||
* Struct capturing a traced packet. Intended to be easily convertible into an Enhanced_packet_block.
|
||||
*/
|
||||
struct Pcapng::Traced_packet
|
||||
{
|
||||
uint32_t _captured_length;
|
||||
uint32_t _original_length;
|
||||
uint32_t _packet_data[0] { };
|
||||
|
||||
Traced_packet(uint32_t packet_size, void *packet_ptr, uint32_t max_captured_length)
|
||||
: _captured_length(min(max_captured_length, packet_size)),
|
||||
_original_length(packet_size)
|
||||
{ memcpy(_packet_data, packet_ptr, _captured_length); }
|
||||
|
||||
/* copy constructor */
|
||||
Traced_packet(Traced_packet const &packet)
|
||||
: _captured_length(packet._captured_length),
|
||||
_original_length(packet._original_length)
|
||||
{ memcpy(_packet_data, packet._packet_data, _captured_length); }
|
||||
|
||||
uint32_t data_length() const { return _captured_length; }
|
||||
|
||||
size_t total_length() const { return sizeof(Traced_packet) + _captured_length; }
|
||||
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/**
|
||||
* Struct used by trace policy, bundles Timestamp, Interface_name and Traced_packet.
|
||||
*/
|
||||
class Trace_recorder::Pcapng_event : public Trace_event<Event_type::PCAPNG>
|
||||
{
|
||||
private:
|
||||
using Interface_name = Pcapng::Interface_name;
|
||||
using Traced_packet = Pcapng::Traced_packet;
|
||||
|
||||
Trace::Timestamp const _timestamp { Trace::timestamp() };
|
||||
Interface_name const _interface;
|
||||
|
||||
/* _interface must be the last member since it has variable size */
|
||||
|
||||
void *_data() { return (void*)((addr_t)this + sizeof(Pcapng_event) + _interface.data_length()); }
|
||||
void const *_data() const { return (void*)((addr_t)this + sizeof(Pcapng_event) + _interface.data_length()); }
|
||||
|
||||
public:
|
||||
|
||||
static Event_type Type() { return Event_type::PCAPNG; }
|
||||
|
||||
static size_t max_size(size_t max_capture_len) {
|
||||
return sizeof(Pcapng_event) + Interface_name::MAX_NAME_LEN + sizeof(Traced_packet) + max_capture_len; }
|
||||
|
||||
Pcapng_event(Pcapng::Link_type type, char const *cstr, bool out, uint32_t packet_sz, void *packet_ptr, uint32_t max_captured_len)
|
||||
: _interface(type, out, cstr)
|
||||
{
|
||||
/* construct Traced_packet after Interface_name */
|
||||
construct_at<Traced_packet>(_data(), packet_sz, packet_ptr, max_captured_len);
|
||||
}
|
||||
|
||||
Traced_packet const &packet() const { return *reinterpret_cast<Traced_packet const*>(_data()); }
|
||||
Interface_name const &interface() const { return _interface; }
|
||||
Trace::Timestamp timestamp() const { return _timestamp; }
|
||||
size_t total_length() const {
|
||||
return sizeof(Pcapng_event) + _interface.data_length() + packet().total_length(); }
|
||||
|
||||
} __attribute__((packed));
|
||||
|
||||
#endif /* _TRACE_RECORDER_POLICY__PCAPNG_H_ */
|
8
repos/gems/recipes/api/trace_recorder_policy/content.mk
Normal file
8
repos/gems/recipes/api/trace_recorder_policy/content.mk
Normal file
@ -0,0 +1,8 @@
|
||||
content: include/trace_recorder_policy LICENSE
|
||||
|
||||
include/trace_recorder_policy:
|
||||
$(mirror_from_rep_dir)
|
||||
|
||||
LICENSE:
|
||||
cp $(GENODE_DIR)/LICENSE $@
|
||||
|
1
repos/gems/recipes/api/trace_recorder_policy/hash
Normal file
1
repos/gems/recipes/api/trace_recorder_policy/hash
Normal file
@ -0,0 +1 @@
|
||||
2022-05-17-e 58691b64af0e4c77ced434a0f40b00226f143767
|
Loading…
x
Reference in New Issue
Block a user