15#if !defined(_PROCESSMEMORY_H_)
16#define _PROCESSMEMORY_H_
37#define PSYPROC_ERROR 0
38#define PSYPROC_CREATED 1
41#define PSYPROC_READY 4
42#define PSYPROC_ACTIVE 5
43#define PSYPROC_SHUTTING_DOWN 6
44#define PSYPROC_TERMINATED 7
78 std::string xmlIn, xmlOut;
80 const char* oldData = NULL;
83 for (n = 0; n < 10; n++) {
87 xmlIn += msg->
toXML();
92 for (n = 0; n < 10; n++) {
96 xmlOut += msg->
toXML();
103 return utils::StringFormat(
"<processstats msgincount=\"%llu\" msginbytes=\"%llu\" msgoutcount=\"%llu\" msgoutbytes=\"%llu\" time=\"%llu\" memusage=\"%llu\">\n<inmsg>\n%s</inmsg>\n<outmsg>\n%s</outmsg>\n</processstats>\n",
133 return utils::StringFormat(
"<space id=\"%u\" name=\"%s\" node=\"%u\" status=\"%u\" osid=\"%u\" commandline=\"%s\" created=\"%llu\" lastseen=\"%llu\">\n%s%s</space>",
153#define INITIALQSIZE sizeof(MessageQueueHeader) + 2048
158struct MessageQueueHeader {
170#define CHECKPROCESSMEMORYSERIAL if (serial != master->getProcessShmemSerial()) {if (!open()) {mutex->leave();return 0;}}
207 bool create(uint32 initialProcCount);
267 bool getQueueSizes(uint16 procID, uint64 &bytes, uint32 &count);
272 bool resize(uint64 newMemorySize);
273 bool setupNextAvailableQ(uint16& qID);
274 bool deleteQ(uint16
id);
275 bool resizeQ(uint16
id, uint64 newSize);
280 bool addToQ(uint16 procID, uint8 qType,
DataMessage* msg);
281 DataMessage* waitForQ(uint16 procID, uint8 qType, uint32 timeout);
HTML/URL helper utilities: entity encoding/decoding, MIME type lookup and URL component parsing.
Central shared-memory manager for a Psyclone node: master segment, per-subsystem shared maps and the ...
#define DRAFTMSGSIZE
Fixed byte size of the per-message draft slots used in the recent-message rings of ComponentStats / P...
#define MAXPROC4
Maximum queues per node (MAXPROC x 4 queue types).
#define MAXPROC
Maximum processes (spaces) per node.
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
#define THREAD_FUNCTION_CALL
#define MAXCOMMANDLINELEN
The central Psyclone data container: a self-contained binary message with typed, named user entries.
std::string toXML(std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
toXML()
const char * swapMessageData(const char *data)
swapMessageData(const char* data)
Handle to the node's master shared-memory segment (MemoryMasterStruct).
bool setProcessCommandLine(uint16 id, const char *cmdline)
Record the launch command line.
DataMessage * waitForCmdQ(uint16 procID, uint32 timeout)
Wait on the command queue.
static bool UnitTest()
Self-test.
bool addToCmdQ(uint16 procID, DataMessage *msg)
Enqueue on the command queue.
bool getProcessName(uint16 id, char *name, uint32 maxSize)
Copy the process name into name (max maxSize bytes).
uint32 getProcessOSID(uint16 id)
bool createNewProcess(const char *name, uint16 &id)
Register a new process (space) in the table.
uint32 getCmdQCount(uint16 procID)
bool addToReqQ(uint16 procID, DataMessage *msg)
Enqueue on the request queue.
bool addToMsgQ(uint16 procID, DataMessage *msg)
Enqueue on the data-message queue.
ProcessMemory(MasterMemory *master)
static bool PerfTest()
Queue throughput benchmark.
bool addLocalPerformanceStats(std::list< PerfStats > &perfStats)
Append PerfStats snapshots for all local processes to perfStats.
uint32 getSigQCount(uint16 procID)
AveragePerfStats getProcessPerfStats(uint16 procID)
bool addToAllSignalQs(DataMessage *msg)
Broadcast to every process's signal queue.
bool addToSigQ(uint16 procID, DataMessage *msg)
Enqueue on the signal queue.
bool addToAllSignalQsExcept(DataMessage *msg, uint16 except)
Broadcast to all signal queues except process except.
uint64 getProcessCreateTime(uint16 id)
uint32 getMsgQCount(uint16 procID)
DataMessage * waitForMsgQ(uint16 procID, uint32 timeout)
Wait on the data-message queue.
bool setProcessOSID(uint16 id, uint32 osid)
Record the OS pid.
bool setProcessStatus(uint16 id, uint8 status, uint64 currentCPUTicks=0)
Update status + heartbeat (and optionally CPU ticks) for process id.
bool getQueueSizes(uint16 procID, uint64 &bytes, uint32 &count)
Total queued bytes/messages across all four queues of procID.
uint8 getProcessStatus(uint16 id, uint64 &lastseen)
bool getMemoryUsage(uint64 &alloc, uint64 &usage)
Report allocation/usage of the process segment.
bool deleteProcess(uint16 id)
Remove a process entry and free its queues.
bool checkProcessHeartbeats(uint32 timeoutMS, std::list< ProcessInfoStruct > &procIssues)
Find processes whose heartbeat is older than timeoutMS.
bool getProcessID(const char *name, uint16 &id)
Look up a process id by name.
bool open()
Attach to the existing process segment.
bool addToProcessStats(uint16 id, DataMessage *inputMsg, DataMessage *outputMsg)
Add message traffic to the process's stats/rings.
DataMessage * waitForReqQ(uint16 procID, uint32 timeout)
Wait on the request queue.
uint32 getReqQCount(uint16 procID)
bool setProcessType(uint16 id, uint8 type)
Set type (0 = normal, 1 = inside node).
uint16 getProcessIDFromOSID(uint32 osid)
Map an OS pid to a Psyclone process id.
bool getProcessCommandLine(uint16 id, char *cmdline, uint32 maxSize)
Copy the launch command line.
std::vector< ProcessInfoStruct > * getAllProcesses()
Snapshot all process records.
DataMessage * waitForSigQ(uint16 procID, uint32 timeout)
Wait on the signal queue.
bool setProcessPerfStats(uint16 procID, AveragePerfStats &perfStruct)
Store new performance averages.
bool create(uint32 initialProcCount)
Create the process segment (master only).
Recursive mutual-exclusion lock, optionally named for cross-process use.
Counting semaphore, optionally named for cross-process use.
std::string EncodeHTML(std::string str)
Encode a plain string for safe embedding in HTML (e.g.
std::string StringFormat(const char *format,...)
printf into a std::string.
THREAD_RET THREAD_FUNCTION_CALL ProcessMemoryPerfTest(THREAD_ARG arg)
static THREAD_RET THREAD_FUNCTION_CALL QueueTest(THREAD_ARG arg)
Sliding-window averages derived from successive PerfStats snapshots.
One process (space) record in the shared process table.
uint16 cmdQID
Queue index of this process's command queue.
char commandline[MAXCOMMANDLINELEN+1]
Command line used to launch the process.
uint16 sigQID
Queue index of this process's signal queue.
uint64 createdTime
Creation timestamp (µs).
uint16 msgQID
Queue index of this process's data-message queue.
uint16 reqQID
Queue index of this process's request queue.
uint32 osID
OS process id (pid).
std::string toXML()
Serialize this record (including stats) as a <space> XML element.
char name[MAXKEYNAMELEN+1]
Process (space) name.
uint32 id
Process id; corresponds to the index in the table.
AveragePerfStats perfStats
Windowed performance averages.
uint64 lastseen
Last heartbeat/status update (µs); staleness implies a crashed space.
ProcessStats stats
Throughput counters and recent-message rings.
uint8 status
PSYPROC_* lifecycle status.
uint16 nodeID
Id of the node this process belongs to.
uint8 type
0: normal space process, 1: runs inside the node process.
Root header of the process-memory segment: fixed process table plus queue index.
ProcessInfoStruct processes[MAXPROC]
Fixed-size process table.
uint64 qIndex[MAXPROC *4]
Byte offsets of each process's four queues (0 = none).
uint64 usage
Bytes currently in use in the segment.
uint32 cid
Check/magic id validated on attach.
uint64 size
Total segment size in bytes.
uint32 count
Number of process entries in use.
Per-process throughput counters and recent-message rings, kept in shared memory.
uint64 msgOutBytes
Total bytes sent.
uint64 msgInBytes
Total bytes received.
char recentOutMsg[10 *DRAFTMSGSIZE]
Ring of the 10 most recent outbound message drafts.
uint64 time
Timestamp of the last update (µs).
uint64 msgOutCount
Total messages sent.
uint64 msgInCount
Total messages received.
char recentInMsg[10 *DRAFTMSGSIZE]
Ring of the 10 most recent inbound message drafts.
std::string toXML()
Serialize counters and recent messages as a <processstats> XML element.
uint64 currentCPUTicks
Cumulative CPU ticks consumed.
uint64 procMemUsage
Current process memory footprint in bytes.