2008-03-05 09:52:00 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// File: Monitoring.cpp
|
|
|
|
//
|
2008-11-17 18:29:00 -05:00
|
|
|
// Note: Kernel & Process
|
2008-03-05 09:52:00 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "hal.h"
|
2008-11-17 18:29:00 -05:00
|
|
|
#include "eventing.h"
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
#define MONITORING_BUFFER_SIZE (6 * 1024 * 1024)
|
|
|
|
#define MONITORING_TEXT_SIZE (2 * 1024 * 1024)
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
UIntPtr MonitoringStorageHandle = 0;
|
|
|
|
PSOURCE_DESCRIPTOR MonitoringSource = NULL;
|
|
|
|
UIntPtr MonitoringTypeHandle = 0;
|
|
|
|
|
|
|
|
const UINT32 Monitoring_ControlFlag_Active = 0x00010000;
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
void
|
|
|
|
Class_Microsoft_Singularity_Monitoring::
|
|
|
|
g_Initialize()
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
#if SINGULARITY_KERNEL
|
|
|
|
|
|
|
|
g_InitPages((UIntPtr)(MONITORING_BUFFER_SIZE));
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
if (c_buffer != NULL) {
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
MonitoringStorageHandle = Class_Microsoft_Singularity_Eventing_MemoryStorage::
|
|
|
|
g_MemoryStorageCreateImpl(MEMORY_STORAGE_FLAGS_RECYCLE_MEMORY,
|
|
|
|
(uint8 *)c_buffer,
|
|
|
|
(uint32)MONITORING_BUFFER_SIZE,
|
|
|
|
0);
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
if (MonitoringStorageHandle) {
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
UIntPtr sourceHandle = RegisterNativeSource("Monitoring",
|
|
|
|
MonitoringStorageHandle,
|
|
|
|
Monitoring_ControlFlag_Active);
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
MonitoringSource = GetSourceFromHandle(sourceHandle);
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
#elif SINGULARITY_PROCESS
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
Struct_Microsoft_Singularity_V1_Services_ProcessService::
|
|
|
|
g_GetSharedSourceHandles(Class_Microsoft_Singularity_Eventing_Controller_MonitoringInfo,
|
|
|
|
&MonitoringStorageHandle,
|
|
|
|
(UIntPtr *)&MonitoringSource,
|
|
|
|
&MonitoringTypeHandle);
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
#else
|
|
|
|
#error "File should be compiled with SINGULARITY_KERNEL or SINGULARITY_PROCESS"
|
|
|
|
#endif
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
bool GetMonitoringHandles(UIntPtr * storageHandle,
|
|
|
|
UIntPtr * sourceHandle,
|
|
|
|
UIntPtr * eventTypeHandle)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
*storageHandle = MonitoringStorageHandle;
|
|
|
|
*sourceHandle = (UIntPtr)MonitoringSource;
|
|
|
|
*eventTypeHandle = MonitoringTypeHandle;
|
|
|
|
return true;
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
bool __inline IsMonitoringEnabled()
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
return ((MonitoringSource != NULL) &&
|
|
|
|
(MonitoringSource->ControlFlags & Monitoring_ControlFlag_Active));
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
|
|
|
|
void Class_Microsoft_Singularity_Monitoring::
|
|
|
|
g_Log(uint16 provider, uint16 type)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
if (IsMonitoringEnabled()) {
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
Struct_Microsoft_Singularity_ThreadContext *threadContext =
|
|
|
|
Class_Microsoft_Singularity_Processor::g_GetCurrentThreadContext();
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
MONITORING_ENTRY entry = {threadContext->processId, provider,type,0,0,0,0,0,0};
|
|
|
|
InternalLogFixedRecord(MonitoringStorageHandle,
|
|
|
|
MonitoringSource->ControlFlags,
|
|
|
|
MonitoringTypeHandle,
|
|
|
|
&entry,
|
|
|
|
sizeof(entry));
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Class_Microsoft_Singularity_Monitoring::
|
|
|
|
g_Log(uint16 provider, uint16 type, uint16 version,
|
|
|
|
uint32 a0, uint32 a1, uint32 a2, uint32 a3, uint32 a4)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
if (IsMonitoringEnabled()) {
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
Struct_Microsoft_Singularity_ThreadContext *threadContext =
|
|
|
|
Class_Microsoft_Singularity_Processor::g_GetCurrentThreadContext();
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
MONITORING_ENTRY entry = {threadContext->processId, provider,type,version,a0,a1,a2,a3,a4};
|
|
|
|
InternalLogFixedRecord(MonitoringStorageHandle,
|
|
|
|
MonitoringSource->ControlFlags,
|
|
|
|
MonitoringTypeHandle,
|
|
|
|
&entry,
|
|
|
|
sizeof(entry));
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Class_Microsoft_Singularity_Monitoring::
|
|
|
|
g_Log(uint16 provider, uint16 type, Class_System_String *s)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
if (IsMonitoringEnabled()) {
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
Struct_Microsoft_Singularity_ThreadContext *threadContext =
|
|
|
|
Class_Microsoft_Singularity_Processor::g_GetCurrentThreadContext();
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
MONITORING_ENTRY entry = {threadContext->processId, provider,type,0,0,0,0,0,0,1};
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
Struct_Microsoft_Singularity_Eventing_ArrayType array[] = {
|
|
|
|
{s->m_stringLength,
|
|
|
|
sizeof(char),
|
|
|
|
Class_Microsoft_Singularity_Eventing_DataType___string,
|
|
|
|
&s->m_firstChar}};
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
InternalLogVariableRecord(true,
|
|
|
|
MonitoringStorageHandle,
|
|
|
|
MonitoringSource->ControlFlags,
|
|
|
|
MonitoringTypeHandle,
|
|
|
|
&entry,
|
|
|
|
sizeof(entry),
|
|
|
|
sizeof(array)/sizeof(array[0]),
|
|
|
|
array);
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Class_Microsoft_Singularity_Monitoring::
|
|
|
|
g_isActive()
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
return IsMonitoringEnabled();
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Class_Microsoft_Singularity_Monitoring::
|
|
|
|
g_setActive(bool active)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
if (MonitoringSource != NULL) {
|
|
|
|
if (active) {
|
|
|
|
MonitoringSource->ControlFlags |= Monitoring_ControlFlag_Active;
|
|
|
|
} else {
|
|
|
|
MonitoringSource->ControlFlags &= ~Monitoring_ControlFlag_Active;
|
|
|
|
}
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
int Class_Microsoft_Singularity_Monitoring::
|
|
|
|
g_FillLogEntry(Struct_Microsoft_Singularity_Monitoring_LogEntry * log,
|
|
|
|
UINT64 * min_counter)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
//
|
|
|
|
// TODO: impplement it to fix monnet
|
|
|
|
//
|
|
|
|
return 0;
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
int Class_Microsoft_Singularity_Monitoring::
|
|
|
|
g_FillTextEntry(uint8 * src, UINT64 counter, uint8 * dst, int max_size)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
//
|
|
|
|
// TODO: impplement it to fix monnet
|
|
|
|
//
|
2008-03-05 09:52:00 -05:00
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
return 0;
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////// End of File.
|