From 7587e07bd3e393bc89a62c568a87735cafa5fda7 Mon Sep 17 00:00:00 2001 From: Ethereal Date: Thu, 24 Feb 2011 13:58:48 -0700 Subject: [PATCH] Added support for loading new marshallers in InformerMarshal. --- include/informer/PacketFormat.h | 37 ++++++++++++++++++ include/monitor/InformerMarshal.h | 2 + modules/informer/src/collector/Informer.c | 10 +++-- src/monitor/InformerMarshal.cpp | 65 +++++++++++++++++++++++++++++++ src/monitor/Marshal.cpp | 32 +++++++++++++++ src/monitor/MarshalList.cpp | 44 +++++++++++++++++++++ 6 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 include/informer/PacketFormat.h create mode 100644 src/monitor/InformerMarshal.cpp create mode 100644 src/monitor/Marshal.cpp create mode 100644 src/monitor/MarshalList.cpp diff --git a/include/informer/PacketFormat.h b/include/informer/PacketFormat.h new file mode 100644 index 0000000..aa0c55c --- /dev/null +++ b/include/informer/PacketFormat.h @@ -0,0 +1,37 @@ +/** Aesalon, a tool to visualize program behaviour in real time. + Copyright (C) 2009-2011, Aesalon development team. + + Aesalon is distributed under the terms of the GNU GPLv3. See + the included file LICENSE for more information. + + @file informer/PacketFormat.h +*/ + +#ifndef AesalonInformerPacketFormat_H +#define AesalonInformerPacketFormat_H + +#ifdef __cplusplus +namespace Informer { +#endif + +/** Describes an Informer packet's type. + General transmission format is one byte describing the packet type, then the rest as type-specific. +*/ +enum PacketType { + /** A module was just loaded; find the corresponding shared library and load it. + Format: + - id: ModuleID type. + - name: 8-bit ASCII string. (length specified by packet header's dataSize - sizeof(ModuleID) - 1). + */ + ModuleLoaded, + NewThread, + NewProcess, + ThreadExiting, + ProcessExiting +}; + +#ifdef __cplusplus +} // namespace Informer +#endif + +#endif diff --git a/include/monitor/InformerMarshal.h b/include/monitor/InformerMarshal.h index 72c9098..d13fe3f 100644 --- a/include/monitor/InformerMarshal.h +++ b/include/monitor/InformerMarshal.h @@ -21,6 +21,8 @@ public: virtual ~InformerMarshal(); virtual Comm::Packet *marshal(Comm::Packet *packet); +private: + void moduleLoaded(Comm::Packet *packet); }; } // namespace Monitor diff --git a/modules/informer/src/collector/Informer.c b/modules/informer/src/collector/Informer.c index c6b0b79..4c33043 100644 --- a/modules/informer/src/collector/Informer.c +++ b/modules/informer/src/collector/Informer.c @@ -19,6 +19,7 @@ #include "Config.h" #include "informer/Informer.h" +#include "informer/PacketFormat.h" #include "shm/PacketHeader.h" #include "shm/ZoneHeader.h" #include "util/StringToBool.h" @@ -70,7 +71,6 @@ void AI_SetupSHM() { } void *AI_MapSHM(uint32_t start, uint32_t size) { - if(AI_InformerData.shmHeader != NULL) printf("Overall size: %i\n", AI_InformerData.shmHeader->shmSize); if(AI_InformerData.shmHeader != NULL && AI_InformerData.shmHeader->shmSize < (start+size)) { sem_wait(&AI_InformerData.shmHeader->resizeSemaphore); @@ -109,13 +109,10 @@ static void *AI_SetupZone() { sem_post(&AI_InformerData.shmHeader->resizeSemaphore); } - printf("Allocated zones: %i\n", AI_InformerData.shmHeader->zonesAllocated); - uint32_t i; for(i = 0; i < AI_InformerData.shmHeader->zonesAllocated; i ++) { if((AI_InformerData.zoneUseData[i/8] & (0x01 << (i % 8))) == 0) break; } - printf("Zone ID#: %i\n", i); if(i == AI_InformerData.shmHeader->zonesAllocated) { /* Something went pretty seriously wrong. Perhaps another target jumped in and took the spot first? */ printf("Something very wrong occurred. Trying again . . .\n"); @@ -206,6 +203,11 @@ void __attribute__((constructor)) AI_Construct() { AI_ContinueCollection(self); AI_StartPacket(0); + *(uint8_t *)AI_PacketSpace(1) = ModuleLoaded; + *(ModuleID *)AI_PacketSpace(sizeof(ModuleID)) = 0; + char *name = AI_PacketSpace(16); + strcpy(name, "Informer Module"); + AI_EndPacket(); } diff --git a/src/monitor/InformerMarshal.cpp b/src/monitor/InformerMarshal.cpp new file mode 100644 index 0000000..dee216a --- /dev/null +++ b/src/monitor/InformerMarshal.cpp @@ -0,0 +1,65 @@ +/** Aesalon, a tool to visualize program behaviour in real time. + Copyright (C) 2009-2011, Aesalon development team. + + Aesalon is distributed under the terms of the GNU GPLv3. See + the included file LICENSE for more information. + + @file src/monitor/InformerMarshal.cpp +*/ + +#include "monitor/InformerMarshal.h" +#include "util/MessageSystem.h" +#include "informer/PacketFormat.h" +#include "monitor/MarshalList.h" +#include "monitor/Coordinator.h" + +namespace Monitor { + +InformerMarshal::InformerMarshal() { + +} + +InformerMarshal::~InformerMarshal() { + +} + +Comm::Packet *InformerMarshal::marshal(Comm::Packet *packet) { + Informer::PacketType type = static_cast(packet->data()[0]); + + switch(type) { + case Informer::ModuleLoaded: { + moduleLoaded(packet); + break; + } + case Informer::NewProcess: { + Message(Fatal, "Informer::NewProcess handling NYI."); + break; + } + case Informer::NewThread: { + Message(Fatal, "Informer::NewThread handling NYI."); + break; + } + case Informer::ThreadExiting: { + Message(Fatal, "Informer::ThreadExiting handling NYI."); + break; + } + case Informer::ProcessExiting: { + Message(Fatal, "Informer::ProcessExiting handling NYI."); + break; + } + } + + return packet; +} + +void InformerMarshal::moduleLoaded(Comm::Packet *packet) { + ModuleID id = *(reinterpret_cast(packet->data() + 1)); + std::string name = reinterpret_cast(packet->data() + 1 + sizeof(ModuleID)); + MarshalList *list = Coordinator::instance()->marshalList(); + + Message(Debug, "Trying to load a marshal for ID#" << id << " with name \"" << name << "\""); + + list->loadMarshal(id, name); +} + +} // namespace Monitor diff --git a/src/monitor/Marshal.cpp b/src/monitor/Marshal.cpp new file mode 100644 index 0000000..2371eae --- /dev/null +++ b/src/monitor/Marshal.cpp @@ -0,0 +1,32 @@ +/** Aesalon, a tool to visualize program behaviour in real time. + Copyright (C) 2009-2011, Aesalon development team. + + Aesalon is distributed under the terms of the GNU GPLv3. See + the included file LICENSE for more information. + + @file src/monitor/Marshal.cpp +*/ + +#include "monitor/Marshal.h" + + + +namespace Monitor { + +Marshal::Marshal(const std::string &moduleName) : m_interface(NULL), m_moduleHandle(NULL) { + +} + +Marshal::Marshal(Marshaller::Interface *interface) : m_interface(interface) { + +} + +Marshal::~Marshal() { + +} + +void Marshal::load(const std::string &moduleName) { + +} + +} // namespace Monitor diff --git a/src/monitor/MarshalList.cpp b/src/monitor/MarshalList.cpp new file mode 100644 index 0000000..b2f192a --- /dev/null +++ b/src/monitor/MarshalList.cpp @@ -0,0 +1,44 @@ +/** Aesalon, a tool to visualize program behaviour in real time. + Copyright (C) 2009-2011, Aesalon development team. + + Aesalon is distributed under the terms of the GNU GPLv3. See + the included file LICENSE for more information. + + @file src/monitor/MarshalList.cpp +*/ + +#include "monitor/MarshalList.h" +#include "util/MessageSystem.h" +#include "monitor/InformerMarshal.h" + +namespace Monitor { + +MarshalList::MarshalList() { + Marshal *marshal = new Marshal(new InformerMarshal()); + m_marshalVector.push_back(marshal); +} + +MarshalList::~MarshalList() { + +} + +Marshal *MarshalList::marshal(ModuleID moduleID) { + if(moduleID >= m_marshalVector.size()) { + return NULL; + } + return m_marshalVector[moduleID]; +} + +void MarshalList::loadMarshal(ModuleID moduleID, const std::string &name) { + Marshal *marshal = new Marshal(name); + if(marshal->interface() == NULL) { + Message(Warning, "Could not load marshal for module " << name); + delete marshal; + } + else { + if(moduleID >= m_marshalVector.size()) m_marshalVector.resize(moduleID+1); + m_marshalVector[moduleID] = marshal; + } +} + +} // namespace Monitor -- 2.11.4.GIT