#include <Draw_ProgressIndicator.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
-#include <Message_PrinterToReport.hxx>
#include <Message_Report.hxx>
#include <OSD.hxx>
#include <OSD_Chronometer.hxx>
Standard_Integer theArgNb,
const char** theArgVec)
{
- OSD_MemInfo aMemInfo;
if (theArgNb <= 1)
{
+ OSD_MemInfo aMemInfo;
theDI << aMemInfo.ToString();
return 0;
}
+ NCollection_Map<OSD_MemInfo::Counter> aCounters;
for (Standard_Integer anIter = 1; anIter < theArgNb; ++anIter)
{
TCollection_AsciiString anArg (theArgVec[anIter]);
anArg.LowerCase();
if (anArg == "virt" || anArg == "v")
{
- theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemVirtual)) << " ";
+ aCounters.Add (OSD_MemInfo::MemVirtual);
}
else if (anArg == "heap" || anArg == "h")
{
- theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemHeapUsage)) << " ";
+ aCounters.Add (OSD_MemInfo::MemHeapUsage);
}
else if (anArg == "wset" || anArg == "w")
{
- theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemWorkingSet)) << " ";
+ aCounters.Add (OSD_MemInfo::MemWorkingSet);
}
else if (anArg == "wsetpeak")
{
- theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemWorkingSetPeak)) << " ";
+ aCounters.Add (OSD_MemInfo::MemWorkingSetPeak);
}
else if (anArg == "swap")
{
- theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemSwapUsage)) << " ";
+ aCounters.Add (OSD_MemInfo::MemSwapUsage);
}
else if (anArg == "swappeak")
{
- theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemSwapUsagePeak)) << " ";
+ aCounters.Add (OSD_MemInfo::MemSwapUsagePeak);
}
else if (anArg == "private")
{
- theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemPrivate)) << " ";
+ aCounters.Add (OSD_MemInfo::MemPrivate);
}
else
{
std::cerr << "Unknown argument '" << theArgVec[anIter] << "'!\n";
}
}
+
+ OSD_MemInfo aMemInfo;
+ aMemInfo.SetActiveCounters (aCounters);
+ for (NCollection_Map<OSD_MemInfo::Counter>::Iterator aCountersIt (aCounters); aCountersIt.More(); aCountersIt.Next())
+ {
+ theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemVirtual)) << " ";
+ }
theDI << "\n";
return 0;
}
//function : dsetreportprinter
//purpose :
//==============================================================================
-static Handle(Message_PrinterToReport) MyPrinterToReport;
static Message_SequenceOfPrinters MyDeactivatedPrinters;
static Standard_Integer dsetreportprinter(Draw_Interpretor&, Standard_Integer n, const char** a)
return 1;
}
- const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger();
- if (aMsgMgr.IsNull())
- return 1;
-
+ const Handle(Message_Report)& aReport = Message::DefaultReport (Standard_True);
+ const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger();
if (! strcmp (a[1], "on") && n == 2)
{
- if (MyPrinterToReport.IsNull())
- MyPrinterToReport = new Message_PrinterToReport;
-
- if (MyPrinterToReport->Report()->IsActiveInMessenger())
+ if (aReport->IsActiveInMessenger (aMessenger))
{
std::cout << "Report printer has been already activated." << std::endl;
return 1;
}
+ // store current printers in cache to restore them by deactivation current printer
+ MyDeactivatedPrinters = aMessenger->Printers();
+ aMessenger->ChangePrinters().Clear();
- MyDeactivatedPrinters = Message::DefaultMessenger()->Printers();
- Message::DefaultMessenger()->ChangePrinters().Clear();
- aMsgMgr->AddPrinter (MyPrinterToReport);
-
+ aReport->ActivateInMessenger (Standard_True);
}
else if (! strcmp (a[1], "off") && n == 2)
{
- if (MyPrinterToReport.IsNull() || !MyPrinterToReport->Report()->IsActiveInMessenger())
+ if (!aReport->IsActiveInMessenger())
{
std::cout << "Report printer was not activated." << std::endl;
return 1;
}
+ aReport->ActivateInMessenger (Standard_False);
- Message::DefaultMessenger()->ChangePrinters().Assign (MyDeactivatedPrinters);
+ aMessenger->ChangePrinters().Assign (MyDeactivatedPrinters);
}
else {
std::cout << "Unrecognized option(s): " << a[1] << std::endl;
return 1;
}
- const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger();
- const Handle(Message_Report)& aDefReport = Message::DefaultReport();
-
- if (aMsgMgr.IsNull() || aDefReport.IsNull())
+ const Handle(Message_Report)& aReport = Message::DefaultReport (Standard_True);
+ if (aReport.IsNull())
return 1;
- aDefReport->ClearMetrics();
+ aReport->ClearMetrics();
for (int i = 1; i < n; i++)
{
Standard_Integer aMetricId = atoi (a [i]);
std::cout << "Unrecognized message metric: " << aMetricId << std::endl;
return 1;
}
- aDefReport->SetActiveMetric ((Message_MetricType)aMetricId, Standard_True);
+ aReport->SetActiveMetric ((Message_MetricType)aMetricId, Standard_True);
}
-
+
return 0;
}
Message_Attribute.hxx
Message_AttributeMeter.cxx
Message_AttributeMeter.hxx
-Message_AttributeObject.cxx
Message_AttributeObject.hxx
Message_AttributeStream.cxx
Message_AttributeStream.hxx
#include <stdio.h>
#include <string.h>
+static Handle(Message_Messenger) MyMessenger;
+
//=======================================================================
//function : DefaultMessenger
//purpose :
//=======================================================================
-const Handle(Message_Messenger)& Message::DefaultMessenger ()
+
+const Handle(Message_Messenger)& Message::DefaultMessenger()
+{
+ if (MyMessenger.IsNull())
+ MyMessenger = new Message_Messenger;
+ return MyMessenger;
+}
+
+//=======================================================================
+//function : SetDefaultMessenger
+//purpose :
+//=======================================================================
+
+void Message::SetDefaultMessenger (const Handle(Message_Messenger)& theMessenger)
{
- static Handle(Message_Messenger) aMessenger = new Message_Messenger;
- return aMessenger;
+ MyMessenger = theMessenger;
}
//=======================================================================
//! It can be customized according to the application needs.
Standard_EXPORT static const Handle(Message_Messenger)& DefaultMessenger();
+ //! Sets default messenger for OCCT applications.
+ Standard_EXPORT static void SetDefaultMessenger (const Handle(Message_Messenger)& theMessenger);
+
//! returns the only one instance of Report
//! When theToCreate is true - automatically creates message report when not exist.
//! that has been created.
}
//! Converts message metric to OSD memory info type.
- //! \param theMetric [in] message metric
- //! \param theMemInfo [out] filled memory info type
- //! \return true if converted
+ //! @param theMetric [in] message metric
+ //! @param theMemInfo [out] filled memory info type
+ //! @return true if converted
static Standard_EXPORT Standard_Boolean ToOSDMetric (const Message_MetricType theMetric, OSD_MemInfo::Counter& theMemInfo);
//! Converts OSD memory info type to message metric.
- //! \param theMemInfo [int] memory info type
- //! \param theMetric [out] filled message metric
- //! \return true if converted
+ //! @param theMemInfo [int] memory info type
+ //! @param theMetric [out] filled message metric
+ //! @return true if converted
static Standard_EXPORT Standard_Boolean ToMessageMetric (const OSD_MemInfo::Counter theMemInfo, Message_MetricType& theMetric);
protected:
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
}
//=======================================================================
-//function : GetCompositeAlerts
+//function : CompositeAlerts
//purpose :
//=======================================================================
-Handle (Message_CompositeAlerts) Message_AlertExtended::GetCompositeAlerts (const Standard_Boolean isCreate)
+Handle (Message_CompositeAlerts) Message_AlertExtended::CompositeAlerts (const Standard_Boolean isCreate)
{
if (myCompositAlerts.IsNull() && isCreate)
myCompositAlerts = new Message_CompositeAlerts();
// hierarchical alerts can not be merged
for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
{
- if (!myCompositAlerts->GetAlerts ((Message_Gravity)iGravity).IsEmpty())
+ if (!myCompositAlerts->Alerts ((Message_Gravity)iGravity).IsEmpty())
return Standard_False;
}
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
//!
//! It has Message_Attributes to provide the alert name, and other custom information
//!
-//! It is possible to set performance meter into alert to store time/memory metric information
-//! spent between the next alert adding. Also time of child alerts are collected
-//!
//! It has a container of composite alerts, if the alert might provide
//! sub-alerts collecting.
//!
-
class Message_AlertExtended : public Message_Alert
{
public:
virtual Standard_EXPORT Standard_CString GetMessageKey () const;
//! Sets container of the alert attributes
- //! \param theAttributes an attribute values
+ //! @param theAttributes an attribute values
void SetAttribute (const Handle(Message_Attribute)& theAttribute) { myAttribute = theAttribute; }
//! Returns container of the alert attributes
- //! \param theAttributes an attribute values
+ //! @param theAttributes an attribute values
const Handle(Message_Attribute)& Attribute() const { return myAttribute; }
//! Returns class provided hierarchy of alerts if created or create if the parameter is true
- //! \param isCreate if composite alert has not been created for this alert, it should be created
- //! \return instance or NULL
- Standard_EXPORT Handle (Message_CompositeAlerts) GetCompositeAlerts (const Standard_Boolean isCreate = Standard_False);
+ //! @param isCreate if composite alert has not been created for this alert, it should be created
+ //! @return instance or NULL
+ Standard_EXPORT Handle (Message_CompositeAlerts) CompositeAlerts (const Standard_Boolean isCreate = Standard_False);
//! Return true if this type of alert can be merged with other
//! of the same type to avoid duplication.
protected:
Handle(Message_CompositeAlerts) myCompositAlerts; //!< class provided hierarchical structure of alerts
- //!< It should be created by an attempt of a child alert creation
Handle(Message_Attribute) myAttribute; //!< container of the alert attributes
};
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
DEFINE_STANDARD_RTTIEXT(Message_Attribute, Standard_Transient)
private:
-
TCollection_AsciiString myName; //!< alert name, if defined is used in GetMessageKey
};
//function : IsMetricValid
//purpose :
//=======================================================================
-
Standard_Boolean Message_AttributeMeter::IsMetricValid (const Message_MetricType& theMetric) const
{
- return fabs (StartValue (theMetric) - GetUndefinedMetric()) > Precision::Confusion() &&
- fabs (StopValue (theMetric) - GetUndefinedMetric()) > Precision::Confusion();
+ return fabs (StartValue (theMetric) - UndefinedMetricValue()) > Precision::Confusion() &&
+ fabs (StopValue (theMetric) - UndefinedMetricValue()) > Precision::Confusion();
}
//=======================================================================
Standard_Real Message_AttributeMeter::StartValue (const Message_MetricType& theMetric) const
{
if (!HasMetric (theMetric))
- return GetUndefinedMetric();
+ return UndefinedMetricValue();
return myMetrics.Find (theMetric).first;
}
{
if (!HasMetric (theMetric))
{
- myMetrics.Bind (theMetric, std::make_pair (theValue, GetUndefinedMetric()));
+ myMetrics.Bind (theMetric, std::make_pair (theValue, UndefinedMetricValue()));
}
myMetrics.ChangeFind (theMetric).first = theValue;
}
Standard_Real Message_AttributeMeter::StopValue (const Message_MetricType& theMetric) const
{
if (!HasMetric (theMetric))
- return GetUndefinedMetric();
+ return UndefinedMetricValue();
return myMetrics.Find (theMetric).second;
}
#include <NCollection_DataMap.hxx>
-#include <TCollection_AsciiString.hxx>
-
class Message_Alert;
-//! Alert object storing container metrics values
+//! Alert object storing alert metrics values.
+//! Start and stop values for each metric.
class Message_AttributeMeter : public Message_Attribute
{
public:
Standard_EXPORT Message_AttributeMeter (const TCollection_AsciiString& theName = TCollection_AsciiString());
//! Checks whether the attribute has values for the metric
- //! \param theMetric [in] metric type
- //! \return true if the metric values exist
+ //! @param theMetric [in] metric type
+ //! @return true if the metric values exist in the attribute
Standard_EXPORT Standard_Boolean HasMetric (const Message_MetricType& theMetric) const;
- //! Returns true if metric is computed
- //! @return value
+ //! Returns true when both values of the metric are set.
+ //! @param theMetric [in] metric type
+ //! @return true if metric values are valid
Standard_EXPORT Standard_Boolean IsMetricValid (const Message_MetricType& theMetric) const;
//! Returns start value for the metric
- //! \param theMetric [in] metric type
+ //! @param theMetric [in] metric type
+ //! @return real value
Standard_EXPORT Standard_Real StartValue (const Message_MetricType& theMetric) const;
//! Sets start values for the metric
- //! \param theMetric [in] metric type
+ //! @param theMetric [in] metric type
Standard_EXPORT void SetStartValue (const Message_MetricType& theMetric, const Standard_Real theValue);
//! Returns stop value for the metric
- //! \param theMetric [in] metric type
+ //! @param theMetric [in] metric type
+ //! @return real value
Standard_EXPORT Standard_Real StopValue (const Message_MetricType& theMetric) const;
//! Sets stop values for the metric
- //! \param theMetric [in] metric type
+ //! @param theMetric [in] metric type
Standard_EXPORT void SetStopValue (const Message_MetricType& theMetric, const Standard_Real theValue);
- //! Returns default value of the time/mem when it is not defined
- //! \return integer value
- static Standard_Real GetUndefinedMetric() { return -1.0; }
+ //! Returns default value of the metric when it is not defined
+ //! @return undefined value
+ static Standard_Real UndefinedMetricValue() { return -1.0; }
// OCCT RTTI
DEFINE_STANDARD_RTTIEXT(Message_AttributeMeter, Message_Attribute)
private:
- typedef std::pair<Standard_Real, Standard_Real> MinToMaxValue;
- NCollection_DataMap<Message_MetricType, MinToMaxValue> myMetrics; //!< computed metrics
+ typedef std::pair<Standard_Real, Standard_Real> StartToStopValue;
+ NCollection_DataMap<Message_MetricType, StartToStopValue> myMetrics; //!< computed metrics
};
#endif // _Message_AttributeMeter_HeaderFile
+++ /dev/null
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <Message_AttributeObject.hxx>
-
-IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeObject, Message_Attribute)
-
-//=======================================================================
-//function : Message_AttributeObject
-//purpose :
-//=======================================================================
-
-Message_AttributeObject::Message_AttributeObject (const Handle(Standard_Transient)& theObject,
- const TCollection_AsciiString& theName)
-: Message_Attribute (theName)
-{
- myObject = theObject;
-}
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
#define _Message_AttributeObject_HeaderFile
#include <Message_Attribute.hxx>
-#include <TCollection_AsciiString.hxx>
-//! Alert object storing Transient object in its field
+class Standard_Transient;
+
+//! Alert object storing a transient object
class Message_AttributeObject : public Message_Attribute
{
public:
//! Constructor with string argument
- Standard_EXPORT Message_AttributeObject (const Handle(Standard_Transient)& theObject,
- const TCollection_AsciiString& theName = TCollection_AsciiString());
+ Message_AttributeObject (const Handle(Standard_Transient)& theObject,
+ const TCollection_AsciiString& theName = TCollection_AsciiString())
+ : Message_Attribute (theName) { myObject = theObject; }
+
+ //! Returns object
+ //! @return the object instance
+ Handle(Standard_Transient) Object() const { return myObject; }
//! Sets the object
//! @param theObject an instance
void SetObject (const Handle(Standard_Transient)& theObject) { myObject = theObject; }
- //! Returns object
- Handle(Standard_Transient) GetObject() const { return myObject; }
-
// OCCT RTTI
- DEFINE_STANDARD_RTTIEXT(Message_AttributeObject, Message_Attribute)
+ DEFINE_STANDARD_RTTI_INLINE(Message_AttributeObject, Message_Attribute)
private:
- Handle(Standard_Transient) myObject;
+ Handle(Standard_Transient) myObject; //!< alert object
};
#endif // _Message_AttributeObject_HeaderFile
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
#include <Message_AttributeStream.hxx>
-#include <Message.hxx>
-#include <Message_Msg.hxx>
-#include <Message_Report.hxx>
-
IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeStream, Message_Attribute)
//=======================================================================
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
#define _Message_AttributeStream_HeaderFile
#include <Message_Attribute.hxx>
-#include <TCollection_AsciiString.hxx>
#include <NCollection_Vector.hxx>
+#include <Standard_SStream.hxx>
-class Message_Report;
-
-//! Alert object storing container of Standard_Real values in its field
+//! Alert object storing stream values
class Message_AttributeStream : public Message_Attribute
{
public:
//! Constructor with string argument
Standard_EXPORT Message_AttributeStream (const Standard_SStream& theStream,
- const TCollection_AsciiString& theName = TCollection_AsciiString());
+ const TCollection_AsciiString& theName = TCollection_AsciiString());
+
+ //! Returns stream value
+ const Standard_SStream& Stream() const { return myStream; }
//! Sets stream value
Standard_EXPORT void SetStream (const Standard_SStream& theStream);
- //! Returns stream value
- const Standard_SStream& GetStream() const { return myStream; }
-
// OCCT RTTI
DEFINE_STANDARD_RTTIEXT(Message_AttributeStream, Message_Attribute)
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
IMPLEMENT_STANDARD_RTTIEXT(Message_CompositeAlerts, Standard_Transient)
//=======================================================================
-//function : AddAlert
+//function : Alerts
//purpose :
//=======================================================================
+const Message_ListOfAlert& Message_CompositeAlerts::Alerts (const Message_Gravity theGravity) const
+{
+ static const Message_ListOfAlert anEmptyList;
+ Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
+ "Requesting alerts for gravity not in valid range", anEmptyList);
+
+ return myAlerts[theGravity];
+}
+//=======================================================================
+//function : AddAlert
+//purpose :
+//=======================================================================
Standard_Boolean Message_CompositeAlerts::AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert)
{
Standard_ASSERT_RETURN (! theAlert.IsNull(), "Attempt to add null alert", Standard_False);
//function : Merge
//purpose :
//=======================================================================
-
Standard_Boolean Message_CompositeAlerts::RemoveAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert)
{
Standard_ASSERT_RETURN (! theAlert.IsNull(), "Attempt to add null alert", Standard_False);
return Standard_True;
}
-//=======================================================================
-//function : GetAlerts
-//purpose :
-//=======================================================================
-
-const Message_ListOfAlert& Message_CompositeAlerts::GetAlerts (const Message_Gravity theGravity) const
-{
- static const Message_ListOfAlert anEmptyList;
- Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- "Requesting alerts for gravity not in valid range", anEmptyList);
-
- return myAlerts[theGravity];
-}
-
//=======================================================================
//function : HasAlerts
//purpose :
{
for (int iGravity = Message_Trace; iGravity <= Message_Fail; ++iGravity)
{
- const Message_ListOfAlert& anAlerts = GetAlerts ((Message_Gravity)iGravity);
+ const Message_ListOfAlert& anAlerts = Alerts ((Message_Gravity)iGravity);
if (anAlerts.Contains (theAlert))
return Standard_True;
}
//function : HasAlerts
//purpose :
//=======================================================================
-
Standard_Boolean Message_CompositeAlerts::HasAlert (const Handle(Standard_Type)& theType, Message_Gravity theGravity)
{
Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
//function : Clear
//purpose :
//=======================================================================
-
void Message_CompositeAlerts::Clear ()
{
for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i)
//function : Clear
//purpose :
//=======================================================================
-
void Message_CompositeAlerts::Clear (Message_Gravity theGravity)
{
Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
//function : Clear
//purpose :
//=======================================================================
-
void Message_CompositeAlerts::Clear (const Handle(Standard_Type)& theType)
{
for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i)
-// Created on: 2018-06-10
-// Created by: Natalia Ermolaeva
-// Copyright (c) 2017 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
class Message_CompositeAlerts;
DEFINE_STANDARD_HANDLE(Message_CompositeAlerts, Standard_Transient)
-//! Base class of the hierarchy of classes describing various situations
-//! occurring during execution of some algorithm or procedure.
-//!
-//! Alert should provide unique text identifier that can be used to distinguish
-//! particular type of alerts, e.g. to get text message string describing it.
-//! See method GetMessageKey(); by default, dynamic type name is used.
-//!
-//! Alert can contain some data. To avoid duplication of data, new alert
-//! can be merged with another one of the same type. Method SupportsMerge()
-//! should return true if merge is supported; method Merge() should do the
-//! merge if possible and return true in that case and false otherwise.
-//!
+//! Class providing container of alerts
class Message_CompositeAlerts : public Standard_Transient
{
public:
//! Empty constructor
- Standard_EXPORT Message_CompositeAlerts () {}
+ Standard_EXPORT Message_CompositeAlerts() {}
- //! Add alert with specified gravity.
+ //! Returns list of collected alerts with specified gravity
+ Standard_EXPORT const Message_ListOfAlert& Alerts (const Message_Gravity theGravity) const;
+
+ //! Add alert with specified gravity. If the alert supports merge it will be merged.
+ //! @param theGravity an alert gravity
+ //! @param theAlert an alert to be added as a child alert
+ //! @return true if the alert is added or merged
Standard_EXPORT Standard_Boolean AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert);
//! Removes alert with specified gravity.
+ //! @param theGravity an alert gravity
+ //! @param theAlert an alert to be removed from the children
+ //! @return true if the alert is removed
Standard_EXPORT Standard_Boolean RemoveAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert);
- //! Returns list of collected alerts with specified gravity
- Standard_EXPORT const Message_ListOfAlert& GetAlerts (const Message_Gravity theGravity) const;
-
//! Returns true if the alert belong the list of the child alerts.
- //! \param theAlert an alert to be checked as a child alert
- //! \return true if the alert is found in a container of children
+ //! @param theAlert an alert to be checked as a child alert
+ //! @return true if the alert is found in a container of children
Standard_EXPORT Standard_Boolean HasAlert (const Handle(Message_Alert)& theAlert);
//! Returns true if specific type of alert is recorded with specified gravity
+ //! @param theType an alert type
+ //! @param theGravity an alert gravity
+ //! @return true if the alert is found in a container of children
Standard_EXPORT Standard_Boolean HasAlert (const Handle(Standard_Type)& theType, Message_Gravity theGravity);
//! Clears all collected alerts
Standard_EXPORT void Clear ();
//! Clears collected alerts with specified gravity
+ //! @param theGravity an alert gravity
Standard_EXPORT void Clear (Message_Gravity theGravity);
//! Clears collected alerts with specified type
+ //! @param theType an alert type
Standard_EXPORT void Clear (const Handle(Standard_Type)& theType);
// OCCT RTTI
protected:
// store messages in a lists sorted by gravity;
// here we rely on knowledge that Message_Fail is the last element of the enum
- Message_ListOfAlert myAlerts[Message_Fail + 1];
+ Message_ListOfAlert myAlerts[Message_Fail + 1]; //!< container of child alert for each type of gravity
};
#endif // _Message_CompositeAlerts_HeaderFile
#include <Message_AlertExtended.hxx>
#include <Message_CompositeAlerts.hxx>
#include <Message_AttributeMeter.hxx>
+#include <Message_Messenger.hxx>
#include <Message_Report.hxx>
#include <OSD_Chronometer.hxx>
//function : Destructor
//purpose :
//=======================================================================
-
Message_Level::~Message_Level()
{
Remove();
//function : SetRootAlert
//purpose :
//=======================================================================
-
void Message_Level::SetRootAlert (const Handle(Message_AlertExtended)& theAlert)
{
myRootAlert = theAlert;
//function : AddAlert
//purpose :
//=======================================================================
-
Standard_Boolean Message_Level::AddAlert (const Message_Gravity theGravity,
const Handle(Message_Alert)& theAlert)
{
// looking for the parent of the parameter alert to release the previous alert
Handle(Message_AlertExtended) aRootAlert = myRootAlert;
- Handle(Message_CompositeAlerts) aCompositeAlert = aRootAlert->GetCompositeAlerts (Standard_True);
+ Handle(Message_CompositeAlerts) aCompositeAlert = aRootAlert->CompositeAlerts (Standard_True);
// update metrics of the previous alert
stopAlert (myLastAlert);
- // set start metrics of the new alert
myLastAlert = anAlertExtended;
+
+ // set start metrics of the new alert
startAlert (myLastAlert);
// add child alert
}
//=======================================================================
-//function : AddAlert
+//function : AddLevelAlert
//purpose :
//=======================================================================
-
Standard_Boolean Message_Level::AddLevelAlert (const Message_Gravity theGravity,
const Handle(Message_Alert)& theAlert)
{
Handle(Message_AlertExtended) aRootAlert = !myLastAlert.IsNull() ? myLastAlert : myRootAlert;
+ if (aRootAlert.IsNull())
+ return Standard_False;
- Handle(Message_CompositeAlerts) aCompositeAlert = aRootAlert->GetCompositeAlerts (Standard_True);
+ Handle(Message_CompositeAlerts) aCompositeAlert = aRootAlert->CompositeAlerts (Standard_True);
// add child alert
aCompositeAlert->AddAlert (theGravity, theAlert);
//function : Remove()
//purpose :
//=======================================================================
-
void Message_Level::Remove()
{
const Handle(Message_Report)& aDefaultReport = Message::DefaultReport();
Message::DefaultReport()->RemoveLevel (this);
}
-//=======================================================================
-//function : startAlert
-//purpose :
-//=======================================================================
-
-Standard_Boolean Message_Level::startAlert (const Handle(Message_AlertExtended)& theAlert)
-{
- return setAlertMetrics (theAlert, Standard_True);
-}
-
-//=======================================================================
-//function : stopAlert
-//purpose :
-//=======================================================================
-
-Standard_Boolean Message_Level::stopAlert (const Handle(Message_AlertExtended)& theAlert)
-{
- return setAlertMetrics (theAlert, Standard_False);
-}
-
//=======================================================================
//function : setAlertMetrics
//purpose :
//=======================================================================
-
-Standard_Boolean Message_Level::setAlertMetrics (const Handle(Message_AlertExtended)& theAlert,
+void Message_Level::setAlertMetrics (const Handle(Message_AlertExtended)& theAlert,
const Standard_Boolean theStartValue)
{
if (theAlert.IsNull())
- return Standard_False;
+ return;
Handle(Message_AttributeMeter) aMeterAttribute = Handle(Message_AttributeMeter)::DownCast (theAlert->Attribute());
if (aMeterAttribute.IsNull())
- return Standard_False;
+ return;
Handle(Message_Report) aReport = Message::DefaultReport (Standard_True);
const NCollection_Map<Message_MetricType>& anActiveMetrics = aReport->ActiveMetrics();
aCounters.Add (aMemInfo);
}
if (aCounters.IsEmpty())
- return Standard_True;
+ return;
OSD_MemInfo aMemInfo (Standard_False);
- aMemInfo.Update (aCounters);
+ //aMemInfo.SetActiveCounters (aCounters);
+ aMemInfo.Update ();
Message_MetricType aMetricType;
for (NCollection_Map<OSD_MemInfo::Counter>::Iterator anIterator (aCounters); anIterator.More(); anIterator.Next())
{
else
aMeterAttribute->SetStopValue (aMetricType, (Standard_Real)aMemInfo.ValuePreciseMiB (anIterator.Value()));
}
- return Standard_True;
}
#include <NCollection_DataMap.hxx>
#include <Standard.hxx>
-//! This class defines level of alerts in the current report.
-//! The first added alert is the root alert, next alerts are children of the root alert.
+//! This class is an instance of Sentry to create a level in a message report
+//! Constructor of the class add new (active) level in the report, destructor removes it
+//! While the level is active in the report, new alerts are added below the level root alert.
+//!
+//! The first added alert is a root alert, other are added below the root alert
+//!
+//! If alert has Message_AttributeMeter attribute, active metrics of the default report are stored in
+//! the attriute: start value of metric on adding alert, stop on adding another alert or closing (delete) the level
+//! in the report.
+//!
+//! Processing of this class is implemented in Message_Report, it is used only insided it.
+//! Levels using should be only through using MESSAGE_ADD_LEVEL_SENTRY only. No other code is required outside.
class Message_Level
{
public:
- //! Constructs and starts (if autoStart is true) the named meter
+ //! Constructor. Append
//! One string key is used for all alert meters. The perf meter is not started automatically, it will be done in
//! AddAlert method
Standard_EXPORT Message_Level();
//! Assures stopping upon destruction
Standard_EXPORT ~Message_Level();
- //! Returns message alert on the level, by default the upper alert is returned
- //! \param theLevelId a level of child position inside the upper alert of performance meter
- //! \return alert instance or NULL
+ //! Returns root alert of the level
+ //! @return alert instance or NULL
Handle(Message_AlertExtended) RootAlert() const { return myRootAlert; }
- //! Returns message alert on the level, by default the upper alert is returned
- //! \param theLevelId a level of child position inside the upper alert of performance meter
- //! \return alert instance or NULL
+ //! Sets the root alert. Starts collects alert metrics if active.
+ //! @param theAlert an alert
Standard_EXPORT void SetRootAlert (const Handle(Message_AlertExtended)& theAlert);
- //! Processes the parameter alert. There are some variants:
- //! - current alert is NULL, the alert becomes the current one and perf meter is started
- //! - last alert of the current alert is stopped (perf meter becomes NULL, time is calculated),
- //! the parameter alert is started (perf meter becomes the current one)
+ //! Adds new alert on the level. Stops the last alert metric, appends the alert and starts the alert metrics collecting.
+ //! Sets root alert beforehead this method using, if the root is NULL, it does nothing.
+ //! @param theGravity an alert gravity
+ //! @param theAlert an alert
+ //! @return true if alert is added
Standard_EXPORT Standard_Boolean AddAlert (const Message_Gravity theGravity,
const Handle(Message_Alert)& theAlert);
- //! Add level alert, that is placed under the previous last alert if exists or under the root alert
+ //! Add new alert as a child of the last alert if exists or as a child of the root alert.
+ //! @param theGravity an alert gravity
+ //! @param theAlert an alert
+ //! @return true if alert is added
Standard_EXPORT Standard_Boolean AddLevelAlert (const Message_Gravity theGravity,
const Handle(Message_Alert)& theAlert);
- //! Remove the current level from the report
+ //! Remove the current level from the report. It stops metric collecting for the last and the root alerts.
Standard_EXPORT void Remove();
protected:
- //! Sets stop time into the alert
- //! \param theAlert a level of child position inside the upper alert of performance meter
- Standard_Boolean startAlert (const Handle(Message_AlertExtended)& theAlert);
+ //! Sets start values of default report metrics into the alert
+ //! @param theAlert an alert
+ void startAlert (const Handle(Message_AlertExtended)& theAlert) { setAlertMetrics (theAlert, Standard_True); }
- //! Sets start time into the alert
- //! \param theAlert a level of child position inside the upper alert of performance meter
- Standard_Boolean stopAlert (const Handle(Message_AlertExtended)& theAlert);
+ //! Sets stop values of default report metrics into the alert
+ //! @param theAlert an alert
+ void stopAlert (const Handle(Message_AlertExtended)& theAlert) { setAlertMetrics (theAlert, Standard_True); }
- //! Fills the alert with metric values
- //! \param theAlert a level of child position inside the upper alert of performance meter
- //! \param theStartValue flag whether the computed value is the start value, if false, stop value is filled
- //! \return true if the alert is filled
- Standard_Boolean setAlertMetrics (const Handle(Message_AlertExtended)& theAlert,
- const Standard_Boolean theStartValue);
+ //! Sets current values of default report metrics into the alert.
+ //! Processed oly alert with Message_AttributeMeter attribute
+ //! @param theAlert an alert
+ //! @param theStartValue flag, if true, the start value is collected otherwise stop
+ void setAlertMetrics (const Handle(Message_AlertExtended)& theAlert,
+ const Standard_Boolean theStartValue);
protected:
- Handle(Message_AlertExtended) myRootAlert; //!< root alerts
- Handle(Message_AlertExtended) myLastAlert; //!< last added alert
+ Handle(Message_AlertExtended) myRootAlert; //!< root alert
+ Handle(Message_AlertExtended) myLastAlert; //!< last added alert on the root alert
};
//! @def MESSAGE_NEW_LEVEL
//! Creates a new level instance of Sentry. This row should be inserted before messages using in the method.
#define MESSAGE_ADD_LEVEL_SENTRY Message_Level aLevel;
-//! @def MESSAGE_NEW_LEVEL
-//! Removed the current level from report. It is not necessary to call it as the level will be removed at the method end.
-//! This macro might be useful for creation several levels in one method to remove previous and add new one.
-#define MESSAGE_REMOVE_LEVEL_SENTRY() aLevel.Remove();
-
-
#endif // _Message_Level_HeaderFile
-// Created on: 2019-08-13
-// Created by: Natalia ERMOLAEVA
-// Copyright (c) 2019 OPEN CASCADE SAS
+// Copyright (c) 2020 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
//function : Report
//purpose :
//=======================================================================
-
const Handle(Message_Report)& Message_PrinterToReport::Report() const
{
if (!myReport.IsNull())
return Message::DefaultReport (Standard_True);
}
-//=======================================================================
-//function : Clear
-//purpose :
-//=======================================================================
-void Message_PrinterToReport::Clear()
-{
- myKey.Clear();
-}
-
//=======================================================================
//function : Send
//purpose :
//=======================================================================
-
void Message_PrinterToReport::Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
{
TCollection_AsciiString aString (theString/*, myUseUtf8 ? Standard_Character(0) : '?'*/);
- Message_PrinterToReport* aThis = (Message_PrinterToReport*)this; // TODO!
if (putEndl)
{
- if (myKey.IsEmpty())
+ if (myValue.IsEmpty())
return;
const Handle(Message_Report)& aReport = Report();
sendMetricAlert (aString, theGravity);
return;
}
- Message_AlertExtended::AddAlert (aReport, new Message_Attribute (myKey), theGravity);
- aThis->Clear();
+ Message_AlertExtended::AddAlert (aReport, new Message_Attribute (myValue), theGravity);
+ ((Message_PrinterToReport*)this)->Clear();
return;
}
- aThis->myKey += aString;
+ ((Message_PrinterToReport*)this)->myValue += aString;
}
//=======================================================================
//function : Send
//purpose :
//=======================================================================
-
void Message_PrinterToReport::Send (const Standard_SStream& theStream,
const Message_Gravity theGravity,
const Standard_Boolean /*putEndl*/) const
const Handle(Message_Report)& aReport = Report();
if (!aReport->ActiveMetrics().IsEmpty())
{
- sendMetricAlert (myKey, theGravity);
+ sendMetricAlert (myValue, theGravity);
return;
}
- Message_AlertExtended::AddAlert (aReport, new Message_AttributeStream (theStream, myKey), theGravity);
- Message_PrinterToReport* aThis = (Message_PrinterToReport*)this; // TODO!
- aThis->Clear();
+ Message_AlertExtended::AddAlert (aReport, new Message_AttributeStream (theStream, myValue), theGravity);
+ ((Message_PrinterToReport*)this)->Clear();
return;
}
//function : Send
//purpose :
//=======================================================================
-
void Message_PrinterToReport::Send (const Handle(Standard_Transient)& theObject,
const Message_Gravity theGravity,
const Standard_Boolean /*putEndl*/) const
const Handle(Message_Report)& aReport = Report();
if (!aReport->ActiveMetrics().IsEmpty())
{
- sendMetricAlert (myKey, theGravity);
+ sendMetricAlert (myValue, theGravity);
return;
}
- Message_AlertExtended::AddAlert (aReport, new Message_AttributeObject (theObject, myKey), theGravity);
- Message_PrinterToReport* aThis = (Message_PrinterToReport*)this; // TODO!
- aThis->Clear();
+ Message_AlertExtended::AddAlert (aReport, new Message_AttributeObject (theObject, myValue), theGravity);
+ ((Message_PrinterToReport*)this)->Clear();
}
//=======================================================================
//function : sendMetricAlert
//purpose :
//=======================================================================
-
void Message_PrinterToReport::sendMetricAlert (const TCollection_AsciiString theValue,
const Message_Gravity theGravity) const
{
- Message_AlertExtended::AddAlert (Report(), new Message_AttributeMeter (myKey), theGravity);
- Message_PrinterToReport* aThis = (Message_PrinterToReport*)this; // TODO!
- aThis->Clear();
+ Message_AlertExtended::AddAlert (Report(), new Message_AttributeMeter (myValue), theGravity);
+ ((Message_PrinterToReport*)this)->Clear();
}
DEFINE_STANDARD_HANDLE(Message_PrinterToReport, Message_Printer)
//! Implementation of a message printer associated with Message_Report
-//! Send will create a new alert of the report.
+//! Send will create a new alert of the report. If string is sent, an alert is created by Eol only.
//! The alerts are sent into set report or default report of Message.
class Message_PrinterToReport : public Message_Printer
{
public:
//! Create printer for redirecting messages into report.
- Standard_EXPORT Message_PrinterToReport () {}
+ Message_PrinterToReport() {}
~Message_PrinterToReport() {}
//! Returns the current or default report
Standard_EXPORT const Handle(Message_Report)& Report() const;
+ //! Sets the printer report
+ //! @param theReport report for messages processing, if NULL, the default report is used
+ Standard_EXPORT void SetReport (const Handle(Message_Report)& theReport) { myReport = theReport; }
+
//!< Returns the first sent value
- TCollection_AsciiString Key() const { return myKey; }
+ TCollection_AsciiString Value() const { return myValue; }
//! Clears current values
- Standard_EXPORT void Clear();
-
- //! Sets the printer report
- //! @param theReport report for messages processing, if NULL, the default report is used
- void SetReport (const Handle(Message_Report)& theReport);
+ Standard_EXPORT void Clear() { myValue.Clear(); }
- //! Appends a new alert into message report
+ //! Appends a new alert into message report if Endl is false or send a new extended alert with attribute on value
Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString,
const Message_Gravity theGravity,
const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
private:
Handle(Message_Report) myReport; //!< the report for sending alerts
- TCollection_AsciiString myKey; //!< the sent string value
+ TCollection_AsciiString myValue; //!< the union of sent strings until Eol
};
#endif // _Message_PrinterToReport_HeaderFile
{
}
-//=======================================================================
-//function : IsActiveInMessenger
-//purpose :
-//=======================================================================
-Standard_Boolean Message_Report::IsActiveInMessenger() const
-{
- const Handle(Message_Messenger)& aMessenger = Message::DefaultMessenger();
- for (Message_SequenceOfPrinters::Iterator anIterator (aMessenger->Printers()); anIterator.More(); anIterator.Next())
- {
- if (anIterator.Value()->IsKind(STANDARD_TYPE (Message_PrinterToReport)) &&
- Handle(Message_PrinterToReport)::DownCast (anIterator.Value())->Report() == this)
- return Standard_True;
- }
- return Standard_False;
-}
-
-//=======================================================================
-//function : AddLevel
-//purpose :
-//=======================================================================
-void Message_Report::AddLevel (Message_Level* theLevel)
-{
- myAlertLevels.Append (theLevel);
-}
-
-//=======================================================================
-//function : RemoveLevel
-//purpose :
-//=======================================================================
-void Message_Report::RemoveLevel (Message_Level* theLevel)
-{
- for (int aLevelIndex = myAlertLevels.Size(); aLevelIndex >= 1; aLevelIndex--)
- {
- Message_Level* aLevel = myAlertLevels.Value (aLevelIndex);
- myAlertLevels.Remove (aLevelIndex);
-
- if (aLevel == theLevel)
- return;
- }
-}
-
//=======================================================================
//function : AddAlert
//purpose :
return;
// remove alerts under the report only
- const Message_ListOfAlert& anAlerts = aCompositeAlert->GetAlerts (theGravity);
+ const Message_ListOfAlert& anAlerts = aCompositeAlert->Alerts (theGravity);
if (anAlerts.Extent() > myLimit)
{
aCompositeAlert->RemoveAlert (theGravity, anAlerts.First());
// if there are some levels of alerts
// iterate by already recorded alerts and try to merge new one with one of those
Message_Level* aLevel = myAlertLevels.Last();
- if (!aLevel)
- return;
- // alert is placed below the level
+ // level has root alert, the new alert will be placed below the root
if (!aLevel->RootAlert().IsNull())
{
aLevel->AddAlert (theGravity, theAlert);
// below the previous level
aLevel->SetRootAlert (anAlert);
- if (myAlertLevels.Size() == 1)
+ if (myAlertLevels.Size() == 1) // this is the first level, so root alert should be pushed in the report composite of alerts
compositeAlerts (Standard_True)->AddAlert (theGravity, theAlert);
else
{
+ // root alert of next levels should be pushed under the previous level
Message_Level* aPrevLevel = myAlertLevels.Value (myAlertLevels.Size() - 1); // previous level
aPrevLevel->AddLevelAlert (theGravity, theAlert);
}
if (myCompositAlerts.IsNull())
return anEmptyList;
- return myCompositAlerts->GetAlerts (theGravity);
-}
-
-//=======================================================================
-//function : SetActiveMetric
-//purpose :
-//=======================================================================
-
-void Message_Report::SetActiveMetric (const Message_MetricType theMetricType,
- const Standard_Boolean theActivate)
-{
- if (theActivate == myActiveMetrics.Contains (theMetricType))
- return;
-
- if (theActivate)
- myActiveMetrics.Add (theMetricType);
- else
- myActiveMetrics.Remove (theMetricType);
+ return myCompositAlerts->Alerts (theGravity);
}
//=======================================================================
Standard_Boolean Message_Report::HasAlert (const Handle(Standard_Type)& theType, Message_Gravity theGravity)
{
- //Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- // "Requesting alerts for gravity not in valid range", Standard_False);
- //for (Message_ListOfAlert::Iterator anIt (myAlerts[theGravity]); anIt.More(); anIt.Next())
- //{
- // if (anIt.Value()->IsInstance(theType))
- // return Standard_True;
- //}
if (compositeAlerts().IsNull())
return Standard_False;
return compositeAlerts()->HasAlert (theType, theGravity);
}
+//=======================================================================
+//function : IsActiveInMessenger
+//purpose :
+//=======================================================================
+
+Standard_Boolean Message_Report::IsActiveInMessenger (const Handle(Message_Messenger)& theMessenger) const
+{
+ Handle(Message_Messenger) aMessenger = theMessenger.IsNull() ? Message::DefaultMessenger() : theMessenger;
+ for (Message_SequenceOfPrinters::Iterator anIterator (aMessenger->Printers()); anIterator.More(); anIterator.Next())
+ {
+ if (anIterator.Value()->IsKind(STANDARD_TYPE (Message_PrinterToReport)) &&
+ Handle(Message_PrinterToReport)::DownCast (anIterator.Value())->Report() == this)
+ return Standard_True;
+ }
+ return Standard_False;
+}
+
+//=======================================================================
+//function : ActivateInMessenger
+//purpose :
+//=======================================================================
+
+void Message_Report::ActivateInMessenger (const Standard_Boolean toActivate,
+ const Handle(Message_Messenger)& theMessenger) const
+{
+ if (toActivate == IsActiveInMessenger())
+ return;
+
+ Handle(Message_Messenger) aMessenger = theMessenger.IsNull() ? Message::DefaultMessenger() : theMessenger;
+ if (toActivate)
+ {
+ Handle (Message_PrinterToReport) aPrinterToReport = new Message_PrinterToReport();
+ aPrinterToReport->SetReport (this);
+ aMessenger->AddPrinter (aPrinterToReport);
+ }
+ else // deactivate
+ {
+ for (Message_SequenceOfPrinters::Iterator anIterator (aMessenger->Printers()); anIterator.More(); anIterator.Next())
+ {
+ const Handle(Message_Printer) aPrinter = anIterator.Value();
+ if (aPrinter->IsKind(STANDARD_TYPE (Message_PrinterToReport)) &&
+ Handle(Message_PrinterToReport)::DownCast (aPrinter)->Report() == this)
+ aMessenger->RemovePrinter (aPrinter);
+ }
+ }
+}
+
+//=======================================================================
+//function : AddLevel
+//purpose :
+//=======================================================================
+
+void Message_Report::AddLevel (Message_Level* theLevel)
+{
+ myAlertLevels.Append (theLevel);
+}
+
+//=======================================================================
+//function : RemoveLevel
+//purpose :
+//=======================================================================
+
+void Message_Report::RemoveLevel (Message_Level* theLevel)
+{
+ for (int aLevelIndex = myAlertLevels.Size(); aLevelIndex >= 1; aLevelIndex--)
+ {
+ Message_Level* aLevel = myAlertLevels.Value (aLevelIndex);
+ myAlertLevels.Remove (aLevelIndex);
+
+ if (aLevel == theLevel)
+ return;
+ }
+}
+
//=======================================================================
//function : Clear
//purpose :
compositeAlerts()->Clear (theType);
myAlertLevels.Clear();
+}
+
+//=======================================================================
+//function : SetActiveMetric
+//purpose :
+//=======================================================================
- //for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i)
- //{
- // for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); )
- // {
- // if (anIt.Value().IsNull() || anIt.Value()->IsInstance (theType))
- // {
- // myAlerts[i].Remove (anIt);
- // }
- // else
- // {
- // anIt.More();
- // }
- // }
- //}
+void Message_Report::SetActiveMetric (const Message_MetricType theMetricType,
+ const Standard_Boolean theActivate)
+{
+ if (theActivate == myActiveMetrics.Contains (theMetricType))
+ return;
+
+ if (theActivate)
+ myActiveMetrics.Add (theMetricType);
+ else
+ myActiveMetrics.Remove (theMetricType);
}
//=======================================================================
{
if (compositeAlerts().IsNull())
return;
- const Message_ListOfAlert& anAlerts = compositeAlerts()->GetAlerts (theGravity);
- // report each type of warning only once
- NCollection_Map<Handle(Standard_Type)> aPassedAlerts;
- for (Message_ListOfAlert::Iterator anIt (anAlerts); anIt.More(); anIt.Next())
- {
- if (aPassedAlerts.Add (anIt.Value()->DynamicType()))
- {
- Message_Msg aMsg (anIt.Value()->GetMessageKey());
- theOS << aMsg.Original() << std::endl;
- }
- }
+ if (compositeAlerts().IsNull())
+ return;
+
+ dumpMessages (theOS, theGravity, compositeAlerts());
}
//=======================================================================
{
if (compositeAlerts().IsNull())
return;
- const Message_ListOfAlert& anAlerts = compositeAlerts()->GetAlerts (theGravity);
- //Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]),
- // "Requesting alerts for gravity not in valid range", );
- // report each type of warning only once
- NCollection_Map<Handle(Standard_Type)> aPassedAlerts;
- for (Message_ListOfAlert::Iterator anIt (anAlerts); anIt.More(); anIt.Next())
- {
- if (aPassedAlerts.Add (anIt.Value()->DynamicType()))
- {
- Message_Msg aMsg (anIt.Value()->GetMessageKey());
- theMessenger->Send (aMsg, theGravity);
- }
- }
+ sendMessages (theMessenger, theGravity, compositeAlerts());
}
//=======================================================================
//function : ñompositeAlerts
//purpose :
//=======================================================================
-Handle (Message_CompositeAlerts) Message_Report::compositeAlerts (const Standard_Boolean isCreate)
+const Handle(Message_CompositeAlerts)& Message_Report::compositeAlerts (const Standard_Boolean isCreate)
{
if (myCompositAlerts.IsNull() && isCreate)
myCompositAlerts = new Message_CompositeAlerts();
return myCompositAlerts;
}
+
+//=======================================================================
+//function : sendMessages
+//purpose :
+//=======================================================================
+
+void Message_Report::sendMessages (const Handle(Message_Messenger)& theMessenger, Message_Gravity theGravity,
+ const Handle(Message_CompositeAlerts)& theCompositeAlert)
+{
+ if (theCompositeAlert.IsNull())
+ return;
+
+ const Message_ListOfAlert& anAlerts = theCompositeAlert->Alerts (theGravity);
+ // report each type of warning only once
+ NCollection_Map<Handle(Standard_Type)> aPassedAlerts;
+ for (Message_ListOfAlert::Iterator anIt (anAlerts); anIt.More(); anIt.Next())
+ {
+ if (aPassedAlerts.Add (anIt.Value()->DynamicType()))
+ {
+ Message_Msg aMsg (anIt.Value()->GetMessageKey());
+ theMessenger->Send (aMsg, theGravity);
+ }
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (anIt.Value());
+ if (anExtendedAlert.IsNull())
+ continue;
+
+ Handle(Message_CompositeAlerts) aCompositeAlerts = anExtendedAlert->CompositeAlerts();
+ if (aCompositeAlerts.IsNull())
+ continue;
+
+ sendMessages (theMessenger, theGravity, aCompositeAlerts);
+ }
+}
+
+//=======================================================================
+//function : dumpMessages
+//purpose :
+//=======================================================================
+
+void Message_Report::dumpMessages (Standard_OStream& theOS, Message_Gravity theGravity,
+ const Handle(Message_CompositeAlerts)& theCompositeAlert)
+{
+ if (theCompositeAlert.IsNull())
+ return;
+
+ const Message_ListOfAlert& anAlerts = theCompositeAlert->Alerts (theGravity);
+ // report each type of warning only once
+ NCollection_Map<Handle(Standard_Type)> aPassedAlerts;
+ for (Message_ListOfAlert::Iterator anIt (anAlerts); anIt.More(); anIt.Next())
+ {
+ if (aPassedAlerts.Add (anIt.Value()->DynamicType()))
+ {
+ Message_Msg aMsg (anIt.Value()->GetMessageKey());
+ theOS << aMsg.Original() << std::endl;
+ }
+
+ Handle(Message_AlertExtended) anExtendedAlert = Handle(Message_AlertExtended)::DownCast (anIt.Value());
+ if (anExtendedAlert.IsNull())
+ continue;
+ dumpMessages (theOS, theGravity, anExtendedAlert->CompositeAlerts());
+ }
+}
//! Dump() or in more advanced way, by iterating over lists returned by GetAlerts()
//!
//! - Report can be cleared by methods Clear() (usually after reporting)
+//!
+//! Message_PrinterToReport is a printer in Messenger to convert data sent to messenger into report
class Message_Report : public Standard_Transient
{
//! Empty constructor
Standard_EXPORT Message_Report ();
- //! Returns true if report printer is registered in the messenger
- Standard_EXPORT Standard_Boolean IsActiveInMessenger() const;
-
- //! Add new level of alerts
- Standard_EXPORT void AddLevel (Message_Level* theLevel);
-
- //! Remove level of alerts
- Standard_EXPORT void RemoveLevel (Message_Level* theLevel);
-
//! Add alert with specified gravity.
//! This method is thread-safe, i.e. alerts can be added from parallel threads safely.
Standard_EXPORT void AddAlert (Message_Gravity theGravity, const Handle(Message_Alert)& theAlert);
//! Returns true if specific type of alert is recorded with specified gravity
Standard_EXPORT Standard_Boolean HasAlert (const Handle(Standard_Type)& theType, Message_Gravity theGravity);
+ //! Returns true if a report printer for the current report is registered in the messenger
+ // @param theMessenger the messenger. If it's NULL, the default messenger is used
+ Standard_EXPORT Standard_Boolean IsActiveInMessenger (const Handle(Message_Messenger)& theMessenger = NULL) const;
+
+ //! Creates an instance of Message_PrinterToReport with the current report and register it in messenger
+ //! @param toActivate if true, activated else deactivated
+ // @param theMessenger the messenger. If it's NULL, the default messenger is used
+ Standard_EXPORT void ActivateInMessenger (const Standard_Boolean toActivate, const Handle(Message_Messenger)& theMessenger = NULL) const;
+
+ //! Add new level of alerts
+ //! @param theLevel a level
+ Standard_EXPORT void AddLevel (Message_Level* theLevel);
+
+ //! Remove level of alerts
+ Standard_EXPORT void RemoveLevel (Message_Level* theLevel);
+
//! Clears all collected alerts
Standard_EXPORT void Clear ();
//! Clears collected alerts with specified type
Standard_EXPORT void Clear (const Handle(Standard_Type)& theType);
+ //! Returns computed metrics when alerts are performed
+ const NCollection_Map<Message_MetricType>& ActiveMetrics() const { return myActiveMetrics; }
+
+ //! Sets metrics to compute when alerts are performed
+ //! @param theMetrics container of metrics
+ Standard_EXPORT void SetActiveMetric (const Message_MetricType theMetricType, const Standard_Boolean theActivate);
+
+ //! Removes all activated metrics
+ void ClearMetrics() { myActiveMetrics.Clear(); }
+
+ //! Returns maximum number of collecting alerts. If the limit is achieved,
+ //! first alert is removed, the new alert is added in the container.
+ //! @return the limit value
+ Standard_Integer Limit() const { return myLimit; }
+
+ //! Sets maximum number of collecting alerts.
+ //! @return theLimit limit value
+ void SetLimit(const Standard_Integer theLimit) { myLimit = theLimit; }
+
//! Dumps all collected alerts to stream
Standard_EXPORT void Dump (Standard_OStream& theOS);
//! Merges alerts with specified gravity from theOther report into this
Standard_EXPORT void Merge (const Handle(Message_Report)& theOther, Message_Gravity theGravity);
- //! Sets metrics to compute when alerts are performed
- //! \param theMetrics container of metrics
- Standard_EXPORT void SetActiveMetric (const Message_MetricType theMetricType, const Standard_Boolean theActivate);
-
- //! Returns computed metrics when alerts are performed
- const NCollection_Map<Message_MetricType>& ActiveMetrics() const { return myActiveMetrics; }
-
- //! Removes all activated metrics
- void ClearMetrics() { myActiveMetrics.Clear(); }
-
- //! Returns maximum number of collecting alerts. If the limit is achieved,
- //! adding of a new alert after removing the first cached alert.
- //! \return the limit value
- Standard_EXPORT Standard_Integer GetLimit() const { return myLimit; }
-
- //! Sets maximum number of collecting alerts.
- //! \return theLimit limit value
- Standard_EXPORT void SetLimit(const Standard_Integer theLimit) { myLimit = theLimit; }
-
- //! Dumps the content of me into the stream
- Standard_EXPORT void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const;
-
// OCCT RTTI
DEFINE_STANDARD_RTTIEXT(Message_Report,Standard_Transient)
protected:
//! Returns class provided hierarchy of alerts if created or create if the parameter is true
- //! \param isCreate if composite alert has not been created for this alert, it should be created
- //! \return instance or NULL
- Standard_EXPORT Handle (Message_CompositeAlerts) compositeAlerts (const Standard_Boolean isCreate = Standard_False);
+ //! @param isCreate if composite alert has not been created for this alert, it should be created
+ //! @return instance or NULL
+ Standard_EXPORT const Handle(Message_CompositeAlerts)& compositeAlerts (const Standard_Boolean isCreate = Standard_False);
+
+ //! Sends alerts to messenger
+ Standard_EXPORT void sendMessages (const Handle(Message_Messenger)& theMessenger, Message_Gravity theGravity,
+ const Handle(Message_CompositeAlerts)& theCompositeAlert);
+
+ //! Dumps collected alerts with specified gravity to stream
+ Standard_EXPORT void dumpMessages (Standard_OStream& theOS, Message_Gravity theGravity,
+ const Handle(Message_CompositeAlerts)& theCompositeAlert);
protected:
Standard_Mutex myMutex;
- // store messages in a lists sorted by gravity;
- // here we rely on knowledge that Message_Fail is the last element of the enum
- Handle(Message_CompositeAlerts) myCompositAlerts;
-
- Standard_Integer myLimit; //! Maximum number of collected alerts
+ Handle(Message_CompositeAlerts) myCompositAlerts; //! container of alerts
- NCollection_Sequence <Message_Level*> myAlertLevels; //! container of alerts, new alerts are added below the latest level
+ NCollection_Sequence<Message_Level*> myAlertLevels; //! container of active levels, new alerts are added below the latest level
NCollection_Map<Message_MetricType> myActiveMetrics; //! metrics to compute on alerts
+
+ Standard_Integer myLimit; //! Maximum number of collected alerts on the top level
};
#endif // _Message_Report_HeaderFile
// =======================================================================
OSD_MemInfo::OSD_MemInfo (const Standard_Boolean theImmediateUpdate)
{
+ NCollection_Map<Counter> aCounters;
+ for (int i = (int)MemPrivate; i < MemCounter_NB; i++)
+ aCounters.Add ((Counter)i);
+ SetActiveCounters (aCounters);
+
if (theImmediateUpdate)
{
Update();
void OSD_MemInfo::Update()
{
Clear();
+
+ if (IsActiveCounter (MemVirtual))
+ {
#ifndef OCCT_UWP
#if defined(_WIN32)
#if (_WIN32_WINNT >= 0x0500)
GlobalMemoryStatus (&aStat);
myCounters[MemVirtual] = Standard_Size(aStat.dwTotalVirtual - aStat.dwAvailVirtual);
#endif
+ }
+ if (IsActiveCounter (MemPrivate) ||
+ IsActiveCounter (MemWorkingSet) ||
+ IsActiveCounter (MemWorkingSetPeak) ||
+ IsActiveCounter (MemSwapUsage) ||
+ IsActiveCounter (MemSwapUsagePeak))
+ {
// use Psapi library
HANDLE aProcess = GetCurrentProcess();
#if (_WIN32_WINNT >= 0x0501)
myCounters[MemSwapUsage] = aProcMemCnts.PagefileUsage;
myCounters[MemSwapUsagePeak] = aProcMemCnts.PeakPagefileUsage;
}
+ }
+ if (IsActiveCounter (MemHeapUsage))
+ {
_HEAPINFO hinfo;
int heapstatus;
hinfo._pentry = NULL;
if(hinfo._useflag == _USEDENTRY)
myCounters[MemHeapUsage] += hinfo._size;
}
+ }
#elif (defined(__linux__) || defined(__linux))
+ if (IsActiveCounter (MemHeapUsage))
+ if (IsActiveCounter (MemWorkingSet))
+ if (IsActiveCounter (MemWorkingSetPeak))
// use procfs on Linux
char aBuff[4096];
snprintf (aBuff, sizeof(aBuff), "/proc/%d/status", getpid());
if (strncmp (aBuff, "VmSize:", strlen ("VmSize:")) == 0)
{
+ if (IsActiveCounter (MemVirtual))
myCounters[MemVirtual] = atol (aBuff + strlen ("VmSize:")) * 1024;
}
//else if (strncmp (aBuff, "VmPeak:", strlen ("VmPeak:")) == 0)
// myVirtualPeak = atol (aBuff + strlen ("VmPeak:")) * 1024;
else if (strncmp (aBuff, "VmRSS:", strlen ("VmRSS:")) == 0)
{
+ if (IsActiveCounter (MemWorkingSet))
myCounters[MemWorkingSet] = atol (aBuff + strlen ("VmRSS:")) * 1024; // RSS - resident set size
}
else if (strncmp (aBuff, "VmHWM:", strlen ("VmHWM:")) == 0)
{
+ if (IsActiveCounter (MemWorkingSetPeak))
myCounters[MemWorkingSetPeak] = atol (aBuff + strlen ("VmHWM:")) * 1024; // HWM - high water mark
}
else if (strncmp (aBuff, "VmData:", strlen ("VmData:")) == 0)
{
- if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
- myCounters[MemPrivate] += atol (aBuff + strlen ("VmData:")) * 1024;
- }
- else if (strncmp (aBuff, "VmStk:", strlen ("VmStk:")) == 0)
- {
- if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
- myCounters[MemPrivate] += atol (aBuff + strlen ("VmStk:")) * 1024;
- }
- }
- aFile.close();
+ if (IsActiveCounter (MemPrivate))
struct mallinfo aMI = mallinfo();
myCounters[MemHeapUsage] = aMI.uordblks;
-#elif (defined(__APPLE__))
- struct task_basic_info aTaskInfo;
- mach_msg_type_number_t aTaskInfoCount = TASK_BASIC_INFO_COUNT;
- if (task_info (mach_task_self(), TASK_BASIC_INFO,
- (task_info_t )&aTaskInfo, &aTaskInfoCount) == KERN_SUCCESS)
- {
- // On Mac OS X, these values in bytes, not pages!
- myCounters[MemVirtual] = aTaskInfo.virtual_size;
- myCounters[MemWorkingSet] = aTaskInfo.resident_size;
-
- //Getting malloc statistics
- malloc_statistics_t aStats;
- malloc_zone_statistics (NULL, &aStats);
-
- myCounters[MemHeapUsage] = aStats.size_in_use;
- }
-#endif
-#endif
-}
-
-// =======================================================================
-// function : Update
-// purpose :
-// =======================================================================
-void OSD_MemInfo::Update (const NCollection_Map<OSD_MemInfo::Counter> theCounters)
-{
-#ifndef OCCT_UWP
-#if defined(_WIN32)
-
- if (theCounters.Contains (MemVirtual))
- {
- #if (_WIN32_WINNT >= 0x0500)
- MEMORYSTATUSEX aStatEx;
- aStatEx.dwLength = sizeof(aStatEx);
- GlobalMemoryStatusEx (&aStatEx);
- myCounters[MemVirtual] = Standard_Size(aStatEx.ullTotalVirtual - aStatEx.ullAvailVirtual);
- #else
- MEMORYSTATUS aStat;
- aStat.dwLength = sizeof(aStat);
- GlobalMemoryStatus (&aStat);
- myCounters[MemVirtual] = Standard_Size(aStat.dwTotalVirtual - aStat.dwAvailVirtual);
- #endif
-
- return;
- }
-
- if (theCounters.Contains (MemPrivate) ||
- theCounters.Contains (MemWorkingSet) ||
- theCounters.Contains (MemWorkingSetPeak) ||
- theCounters.Contains (MemSwapUsage) ||
- theCounters.Contains (MemSwapUsagePeak))
- {
- // use Psapi library
- HANDLE aProcess = GetCurrentProcess();
- #if (_WIN32_WINNT >= 0x0501)
- PROCESS_MEMORY_COUNTERS_EX aProcMemCnts;
- #else
- PROCESS_MEMORY_COUNTERS aProcMemCnts;
- #endif
- if (GetProcessMemoryInfo (aProcess, (PROCESS_MEMORY_COUNTERS* )&aProcMemCnts, sizeof(aProcMemCnts)))
- {
- #if (_WIN32_WINNT >= 0x0501)
- myCounters[MemPrivate] = aProcMemCnts.PrivateUsage;
- #endif
- myCounters[MemWorkingSet] = aProcMemCnts.WorkingSetSize;
- myCounters[MemWorkingSetPeak] = aProcMemCnts.PeakWorkingSetSize;
- myCounters[MemSwapUsage] = aProcMemCnts.PagefileUsage;
- myCounters[MemSwapUsagePeak] = aProcMemCnts.PeakPagefileUsage;
- }
- return;
- }
-
- if (theCounters.Contains (MemHeapUsage))
- {
- _HEAPINFO hinfo;
- int heapstatus;
- hinfo._pentry = NULL;
-
- myCounters[MemHeapUsage] = 0;
- while((heapstatus = _heapwalk(&hinfo)) == _HEAPOK)
- {
- if(hinfo._useflag == _USEDENTRY)
- myCounters[MemHeapUsage] += hinfo._size;
- }
- return;
- }
-
-#elif (defined(__linux__) || defined(__linux))
-/*
- // use procfs on Linux
- char aBuff[4096];
- snprintf (aBuff, sizeof(aBuff), "/proc/%d/status", getpid());
- std::ifstream aFile;
- aFile.open (aBuff);
- if (!aFile.is_open())
- {
- return;
- }
-
- while (!aFile.eof())
- {
- memset (aBuff, 0, sizeof(aBuff));
- aFile.getline (aBuff, 4096);
- if (aBuff[0] == '\0')
- {
- continue;
- }
-
- if (strncmp (aBuff, "VmSize:", strlen ("VmSize:")) == 0)
- {
- myCounters[MemVirtual] = atol (aBuff + strlen ("VmSize:")) * 1024;
- }
- //else if (strncmp (aBuff, "VmPeak:", strlen ("VmPeak:")) == 0)
- // myVirtualPeak = atol (aBuff + strlen ("VmPeak:")) * 1024;
- else if (strncmp (aBuff, "VmRSS:", strlen ("VmRSS:")) == 0)
- {
- myCounters[MemWorkingSet] = atol (aBuff + strlen ("VmRSS:")) * 1024; // RSS - resident set size
- }
- else if (strncmp (aBuff, "VmHWM:", strlen ("VmHWM:")) == 0)
- {
- myCounters[MemWorkingSetPeak] = atol (aBuff + strlen ("VmHWM:")) * 1024; // HWM - high water mark
- }
- else if (strncmp (aBuff, "VmData:", strlen ("VmData:")) == 0)
- {
+ {
if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
myCounters[MemPrivate] += atol (aBuff + strlen ("VmData:")) * 1024;
+ }
}
else if (strncmp (aBuff, "VmStk:", strlen ("VmStk:")) == 0)
{
+ if (IsActiveCounter (MemPrivate))
+ {
if (myCounters[MemPrivate] == Standard_Size(-1)) ++myCounters[MemPrivate];
myCounters[MemPrivate] += atol (aBuff + strlen ("VmStk:")) * 1024;
+ }
}
}
aFile.close();
-
- struct mallinfo aMI = mallinfo();
- myCounters[MemHeapUsage] = aMI.uordblks;
-
#elif (defined(__APPLE__))
+ if (IsActiveCounter (MemVirtual) || IsActiveCounter (MemWorkingSet) || IsActiveCounter (MemHeapUsage))
+ {
struct task_basic_info aTaskInfo;
mach_msg_type_number_t aTaskInfoCount = TASK_BASIC_INFO_COUNT;
if (task_info (mach_task_self(), TASK_BASIC_INFO,
myCounters[MemHeapUsage] = aStats.size_in_use;
}
-*/
+ }
#endif
#endif
}
TCollection_AsciiString OSD_MemInfo::ToString() const
{
TCollection_AsciiString anInfo;
- if (myCounters[MemPrivate] != Standard_Size(-1))
+ if (hasValue (MemPrivate))
{
anInfo += TCollection_AsciiString(" Private memory: ") + Standard_Integer (ValueMiB (MemPrivate)) + " MiB\n";
}
- if (myCounters[MemWorkingSet] != Standard_Size(-1))
+ if (hasValue (MemWorkingSet))
{
anInfo += TCollection_AsciiString(" Working Set: ") + Standard_Integer (ValueMiB (MemWorkingSet)) + " MiB";
- if (myCounters[MemWorkingSetPeak] != Standard_Size(-1))
+ if (hasValue (MemWorkingSetPeak))
{
anInfo += TCollection_AsciiString(" (peak: ") + Standard_Integer (ValueMiB (MemWorkingSetPeak)) + " MiB)";
}
anInfo += "\n";
}
- if (myCounters[MemSwapUsage] != Standard_Size(-1))
+ if (hasValue (MemSwapUsage))
{
anInfo += TCollection_AsciiString(" Pagefile usage: ") + Standard_Integer (ValueMiB (MemSwapUsage)) + " MiB";
- if (myCounters[MemSwapUsagePeak] != Standard_Size(-1))
+ if (hasValue (MemSwapUsagePeak))
{
anInfo += TCollection_AsciiString(" (peak: ") + Standard_Integer (ValueMiB (MemSwapUsagePeak)) + " MiB)";
}
anInfo += "\n";
}
- if (myCounters[MemVirtual] != Standard_Size(-1))
+ if (hasValue (MemVirtual))
{
anInfo += TCollection_AsciiString(" Virtual memory: ") + Standard_Integer (ValueMiB (MemVirtual)) + " MiB\n";
}
- if (myCounters[MemHeapUsage] != Standard_Size(-1))
+ if (hasValue (MemHeapUsage))
{
anInfo += TCollection_AsciiString(" Heap memory: ") + Standard_Integer (ValueMiB (MemHeapUsage)) + " MiB\n";
}
// =======================================================================
Standard_Size OSD_MemInfo::Value (const OSD_MemInfo::Counter theCounter) const
{
- if (theCounter < 0 || theCounter >= MemCounter_NB)
+ if (theCounter < 0 || theCounter >= MemCounter_NB || !IsActiveCounter (theCounter))
{
return Standard_Size(-1);
}
// =======================================================================
Standard_Size OSD_MemInfo::ValueMiB (const OSD_MemInfo::Counter theCounter) const
{
- if (theCounter < 0 || theCounter >= MemCounter_NB)
+ if (theCounter < 0 || theCounter >= MemCounter_NB || !IsActiveCounter (theCounter))
{
return Standard_Size(-1);
}
// =======================================================================
Standard_Real OSD_MemInfo::ValuePreciseMiB (const OSD_MemInfo::Counter theCounter) const
{
- if (theCounter < 0 || theCounter >= MemCounter_NB)
+ if (theCounter < 0 || theCounter >= MemCounter_NB || !IsActiveCounter (theCounter))
{
return -1.0;
}
OSD_MemInfo anInfo;
return anInfo.ToString();
}
+
+// =======================================================================
+// function : hasValue
+// purpose :
+// =======================================================================
+Standard_Boolean OSD_MemInfo::hasValue (const OSD_MemInfo::Counter theCounter) const
+{
+ return IsActiveCounter (theCounter) && myCounters[theCounter] != Standard_Size(-1);
+}
//! Create and initialize
Standard_EXPORT OSD_MemInfo (const Standard_Boolean theImmediateUpdate = Standard_True);
+ //! Set counters that information should be collected. By default, all counters are active.
+ //! @param theCounters container of ids
+ void SetActiveCounters (const NCollection_Map<OSD_MemInfo::Counter>& theCounters) { myActiveCounters = theCounters; }
+
+ //! Return true if the counter is active
+ Standard_Boolean IsActiveCounter (const OSD_MemInfo::Counter theCounter) const { return myActiveCounters.Contains (theCounter); }
+
//! Clear counters
Standard_EXPORT void Clear();
//! Update counters
Standard_EXPORT void Update();
- //! Update counter of specified counter
- Standard_EXPORT void Update (const NCollection_Map<OSD_MemInfo::Counter> theCounters);
-
//! Return the string representation for all available counter.
Standard_EXPORT TCollection_AsciiString ToString() const;
//! Return the string representation for all available counter.
Standard_EXPORT static TCollection_AsciiString PrintInfo();
+protected:
+
+ //! Return true if the counter is active and the value is valid
+ Standard_Boolean hasValue (const OSD_MemInfo::Counter theCounter) const;
+
private:
Standard_Size myCounters[MemCounter_NB]; //!< Counters' values, in bytes
+ NCollection_Map<OSD_MemInfo::Counter> myActiveCounters; //!< container of information to collect
};
#endif // _OSD_MemInfo_H__
Handle (Message_PrinterToReport) aPrinterToReport = Handle(Message_PrinterToReport)::DownCast (aPrinter);
const Handle(Message_Report)& aReport = aPrinterToReport->Report();
- Message_AlertExtended::AddAlert (aReport, new TopoDS_AlertAttribute (theShape, aPrinterToReport->Key()),
+ Message_AlertExtended::AddAlert (aReport, new TopoDS_AlertAttribute (theShape, aPrinterToReport->Value()),
theMessenger->OuputGravity());
aPrinterToReport->Clear();
}
Handle(Message_AlertExtended) anAlertExtended = Handle(Message_AlertExtended)::DownCast (theAlert);
if (anAlertExtended.IsNull())
continue;
- Handle(Message_CompositeAlerts) aComposite = anAlertExtended->GetCompositeAlerts();
+ Handle(Message_CompositeAlerts) aComposite = anAlertExtended->CompositeAlerts();
if (aComposite.IsNull())
continue;
- const Message_ListOfAlert& anAlerts = aComposite->GetAlerts ((Message_Gravity)aGravityId);
+ const Message_ListOfAlert& anAlerts = aComposite->Alerts ((Message_Gravity)aGravityId);
for (Message_ListOfAlert::Iterator anAlertsIt (anAlerts); anAlertsIt.More(); anAlertsIt.Next())
exportAlert (anAlertsIt.Value(), aGravityLabel);
}
{
Handle(Message_AttributeStream) aValuesArrayAlert = Handle(Message_AttributeStream)::DownCast (anAttribute);
// store values
- TCollection_AsciiString aStreamText = Standard_Dump::Text (aValuesArrayAlert->GetStream());
+ TCollection_AsciiString aStreamText = Standard_Dump::Text (aValuesArrayAlert->Stream());
if (aStreamText.IsEmpty())
return;
Handle(TDataStd_ExtStringArray) aListAttribute = TDataStd_ExtStringArray::Set (theAlertLabel, 0, 0);