From: nds Date: Thu, 23 Jan 2020 14:49:40 +0000 (+0300) Subject: 0029451: Information Message Alert to debug an algorithm or object functionality X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FCR31278;p=occt-copy.git 0029451: Information Message Alert to debug an algorithm or object functionality # code corrections (cherry picked from commit b38ed07a0e5d389d9a968800271f1ec6da98459f) --- diff --git a/src/Draw/Draw_BasicCommands.cxx b/src/Draw/Draw_BasicCommands.cxx index 5fa9608390..f6d65bc7ab 100644 --- a/src/Draw/Draw_BasicCommands.cxx +++ b/src/Draw/Draw_BasicCommands.cxx @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -769,50 +768,58 @@ static int dmeminfo (Draw_Interpretor& theDI, Standard_Integer theArgNb, const char** theArgVec) { - OSD_MemInfo aMemInfo; if (theArgNb <= 1) { + OSD_MemInfo aMemInfo; theDI << aMemInfo.ToString(); return 0; } + NCollection_Map 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::Iterator aCountersIt (aCounters); aCountersIt.More(); aCountersIt.Next()) + { + theDI << Standard_Real (aMemInfo.Value (OSD_MemInfo::MemVirtual)) << " "; + } theDI << "\n"; return 0; } @@ -937,7 +944,6 @@ static int dsetsignal (Draw_Interpretor& theDI, Standard_Integer theArgNb, const //function : dsetreportprinter //purpose : //============================================================================== -static Handle(Message_PrinterToReport) MyPrinterToReport; static Message_SequenceOfPrinters MyDeactivatedPrinters; static Standard_Integer dsetreportprinter(Draw_Interpretor&, Standard_Integer n, const char** a) @@ -948,35 +954,31 @@ static Standard_Integer dsetreportprinter(Draw_Interpretor&, Standard_Integer n, 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; @@ -997,13 +999,11 @@ static Standard_Integer dsetreportmetric(Draw_Interpretor&, Standard_Integer n, 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]); @@ -1012,9 +1012,9 @@ static Standard_Integer dsetreportmetric(Draw_Interpretor&, Standard_Integer n, 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; } diff --git a/src/Message/FILES b/src/Message/FILES index e332c94b46..7619c20302 100755 --- a/src/Message/FILES +++ b/src/Message/FILES @@ -12,7 +12,6 @@ Message_Attribute.cxx Message_Attribute.hxx Message_AttributeMeter.cxx Message_AttributeMeter.hxx -Message_AttributeObject.cxx Message_AttributeObject.hxx Message_AttributeStream.cxx Message_AttributeStream.hxx diff --git a/src/Message/Message.cxx b/src/Message/Message.cxx index 4c412893cf..54d5b33665 100644 --- a/src/Message/Message.cxx +++ b/src/Message/Message.cxx @@ -23,14 +23,28 @@ #include #include +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; } //======================================================================= diff --git a/src/Message/Message.hxx b/src/Message/Message.hxx index 2df8154bce..a78d15d8c7 100644 --- a/src/Message/Message.hxx +++ b/src/Message/Message.hxx @@ -59,6 +59,9 @@ public: //! 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. @@ -94,15 +97,15 @@ public: } //! 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: diff --git a/src/Message/Message_AlertExtended.cxx b/src/Message/Message_AlertExtended.cxx index 2e7815feae..aab9cb7411 100644 --- a/src/Message/Message_AlertExtended.cxx +++ b/src/Message/Message_AlertExtended.cxx @@ -1,6 +1,4 @@ -// 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. // @@ -37,10 +35,10 @@ Standard_CString Message_AlertExtended::GetMessageKey () const } //======================================================================= -//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(); @@ -60,7 +58,7 @@ Standard_Boolean Message_AlertExtended::SupportsMerge () const // 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; } diff --git a/src/Message/Message_AlertExtended.hxx b/src/Message/Message_AlertExtended.hxx index c5d81355e5..930fd1384b 100644 --- a/src/Message/Message_AlertExtended.hxx +++ b/src/Message/Message_AlertExtended.hxx @@ -1,6 +1,4 @@ -// 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. // @@ -31,13 +29,9 @@ class Message_CompositeAlerts; //! //! 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: @@ -52,17 +46,17 @@ 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. @@ -90,7 +84,6 @@ public: 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 }; diff --git a/src/Message/Message_Alerts.hxx b/src/Message/Message_Alerts.hxx index 3aed324b89..ed367c1ae1 100644 --- a/src/Message/Message_Alerts.hxx +++ b/src/Message/Message_Alerts.hxx @@ -1,6 +1,4 @@ -// 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. // diff --git a/src/Message/Message_Attribute.cxx b/src/Message/Message_Attribute.cxx index b76c1cb8ed..6efcd0f7ba 100644 --- a/src/Message/Message_Attribute.cxx +++ b/src/Message/Message_Attribute.cxx @@ -1,6 +1,4 @@ -// 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. // diff --git a/src/Message/Message_Attribute.hxx b/src/Message/Message_Attribute.hxx index 61198d28d0..a76b95a239 100644 --- a/src/Message/Message_Attribute.hxx +++ b/src/Message/Message_Attribute.hxx @@ -1,6 +1,4 @@ -// 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. // @@ -49,7 +47,6 @@ public: DEFINE_STANDARD_RTTIEXT(Message_Attribute, Standard_Transient) private: - TCollection_AsciiString myName; //!< alert name, if defined is used in GetMessageKey }; diff --git a/src/Message/Message_AttributeMeter.cxx b/src/Message/Message_AttributeMeter.cxx index 3ffc22cb7b..16ea1f0542 100644 --- a/src/Message/Message_AttributeMeter.cxx +++ b/src/Message/Message_AttributeMeter.cxx @@ -39,11 +39,10 @@ Standard_Boolean Message_AttributeMeter::HasMetric (const Message_MetricType& th //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(); } //======================================================================= @@ -53,7 +52,7 @@ Standard_Boolean Message_AttributeMeter::IsMetricValid (const Message_MetricType Standard_Real Message_AttributeMeter::StartValue (const Message_MetricType& theMetric) const { if (!HasMetric (theMetric)) - return GetUndefinedMetric(); + return UndefinedMetricValue(); return myMetrics.Find (theMetric).first; } @@ -66,7 +65,7 @@ void Message_AttributeMeter::SetStartValue (const Message_MetricType& theMetric, { if (!HasMetric (theMetric)) { - myMetrics.Bind (theMetric, std::make_pair (theValue, GetUndefinedMetric())); + myMetrics.Bind (theMetric, std::make_pair (theValue, UndefinedMetricValue())); } myMetrics.ChangeFind (theMetric).first = theValue; } @@ -78,7 +77,7 @@ void Message_AttributeMeter::SetStartValue (const Message_MetricType& theMetric, Standard_Real Message_AttributeMeter::StopValue (const Message_MetricType& theMetric) const { if (!HasMetric (theMetric)) - return GetUndefinedMetric(); + return UndefinedMetricValue(); return myMetrics.Find (theMetric).second; } diff --git a/src/Message/Message_AttributeMeter.hxx b/src/Message/Message_AttributeMeter.hxx index a9f98d42ba..032b2558b0 100644 --- a/src/Message/Message_AttributeMeter.hxx +++ b/src/Message/Message_AttributeMeter.hxx @@ -19,11 +19,10 @@ #include -#include - 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: @@ -32,41 +31,44 @@ 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 MinToMaxValue; - NCollection_DataMap myMetrics; //!< computed metrics + typedef std::pair StartToStopValue; + NCollection_DataMap myMetrics; //!< computed metrics }; #endif // _Message_AttributeMeter_HeaderFile diff --git a/src/Message/Message_AttributeObject.cxx b/src/Message/Message_AttributeObject.cxx deleted file mode 100644 index 67ac1f6aff..0000000000 --- a/src/Message/Message_AttributeObject.cxx +++ /dev/null @@ -1,30 +0,0 @@ -// 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 - -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; -} diff --git a/src/Message/Message_AttributeObject.hxx b/src/Message/Message_AttributeObject.hxx index 75321a1008..a889cc90c5 100644 --- a/src/Message/Message_AttributeObject.hxx +++ b/src/Message/Message_AttributeObject.hxx @@ -1,6 +1,4 @@ -// 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. // @@ -17,28 +15,31 @@ #define _Message_AttributeObject_HeaderFile #include -#include -//! 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 diff --git a/src/Message/Message_AttributeStream.cxx b/src/Message/Message_AttributeStream.cxx index 19c5c8323a..f0cf931415 100644 --- a/src/Message/Message_AttributeStream.cxx +++ b/src/Message/Message_AttributeStream.cxx @@ -1,6 +1,4 @@ -// 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. // @@ -15,10 +13,6 @@ #include -#include -#include -#include - IMPLEMENT_STANDARD_RTTIEXT(Message_AttributeStream, Message_Attribute) //======================================================================= diff --git a/src/Message/Message_AttributeStream.hxx b/src/Message/Message_AttributeStream.hxx index 2520670cfc..0003c30eb4 100644 --- a/src/Message/Message_AttributeStream.hxx +++ b/src/Message/Message_AttributeStream.hxx @@ -1,6 +1,4 @@ -// 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. // @@ -17,27 +15,25 @@ #define _Message_AttributeStream_HeaderFile #include -#include #include +#include -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) diff --git a/src/Message/Message_CompositeAlerts.cxx b/src/Message/Message_CompositeAlerts.cxx index 79ed72e80d..cb09663af4 100644 --- a/src/Message/Message_CompositeAlerts.cxx +++ b/src/Message/Message_CompositeAlerts.cxx @@ -1,6 +1,4 @@ -// 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. // @@ -20,10 +18,22 @@ 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); @@ -52,7 +62,6 @@ Standard_Boolean Message_CompositeAlerts::AddAlert (Message_Gravity theGravity, //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); @@ -67,20 +76,6 @@ Standard_Boolean Message_CompositeAlerts::RemoveAlert (Message_Gravity theGravit 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 : @@ -90,7 +85,7 @@ Standard_Boolean Message_CompositeAlerts::HasAlert (const Handle(Message_Alert)& { 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; } @@ -101,7 +96,6 @@ Standard_Boolean Message_CompositeAlerts::HasAlert (const Handle(Message_Alert)& //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]), @@ -119,7 +113,6 @@ Standard_Boolean Message_CompositeAlerts::HasAlert (const Handle(Standard_Type)& //function : Clear //purpose : //======================================================================= - void Message_CompositeAlerts::Clear () { for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i) @@ -132,7 +125,6 @@ void Message_CompositeAlerts::Clear () //function : Clear //purpose : //======================================================================= - void Message_CompositeAlerts::Clear (Message_Gravity theGravity) { Standard_ASSERT_RETURN (theGravity >= 0 && size_t(theGravity) < sizeof(myAlerts)/sizeof(myAlerts[0]), @@ -144,7 +136,6 @@ void Message_CompositeAlerts::Clear (Message_Gravity theGravity) //function : Clear //purpose : //======================================================================= - void Message_CompositeAlerts::Clear (const Handle(Standard_Type)& theType) { for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i) diff --git a/src/Message/Message_CompositeAlerts.hxx b/src/Message/Message_CompositeAlerts.hxx index aeb53d972f..36a3ab4115 100644 --- a/src/Message/Message_CompositeAlerts.hxx +++ b/src/Message/Message_CompositeAlerts.hxx @@ -1,6 +1,4 @@ -// 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. // @@ -24,48 +22,48 @@ 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 @@ -74,7 +72,7 @@ public: 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 diff --git a/src/Message/Message_Level.cxx b/src/Message/Message_Level.cxx index 2542a6df8a..694be1ce2f 100644 --- a/src/Message/Message_Level.cxx +++ b/src/Message/Message_Level.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -37,7 +38,6 @@ Message_Level::Message_Level() //function : Destructor //purpose : //======================================================================= - Message_Level::~Message_Level() { Remove(); @@ -47,7 +47,6 @@ Message_Level::~Message_Level() //function : SetRootAlert //purpose : //======================================================================= - void Message_Level::SetRootAlert (const Handle(Message_AlertExtended)& theAlert) { myRootAlert = theAlert; @@ -58,7 +57,6 @@ void Message_Level::SetRootAlert (const Handle(Message_AlertExtended)& theAlert) //function : AddAlert //purpose : //======================================================================= - Standard_Boolean Message_Level::AddAlert (const Message_Gravity theGravity, const Handle(Message_Alert)& theAlert) { @@ -71,13 +69,14 @@ Standard_Boolean Message_Level::AddAlert (const Message_Gravity theGravity, // 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 @@ -87,16 +86,17 @@ Standard_Boolean Message_Level::AddAlert (const Message_Gravity theGravity, } //======================================================================= -//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); @@ -107,7 +107,6 @@ Standard_Boolean Message_Level::AddLevelAlert (const Message_Gravity theGravity, //function : Remove() //purpose : //======================================================================= - void Message_Level::Remove() { const Handle(Message_Report)& aDefaultReport = Message::DefaultReport(); @@ -121,40 +120,19 @@ void Message_Level::Remove() 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& anActiveMetrics = aReport->ActiveMetrics(); @@ -192,10 +170,11 @@ Standard_Boolean Message_Level::setAlertMetrics (const Handle(Message_AlertExten 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::Iterator anIterator (aCounters); anIterator.More(); anIterator.Next()) { @@ -207,5 +186,4 @@ Standard_Boolean Message_Level::setAlertMetrics (const Handle(Message_AlertExten else aMeterAttribute->SetStopValue (aMetricType, (Standard_Real)aMemInfo.ValuePreciseMiB (anIterator.Value())); } - return Standard_True; } diff --git a/src/Message/Message_Level.hxx b/src/Message/Message_Level.hxx index 35de389bab..2aca780a1e 100644 --- a/src/Message/Message_Level.hxx +++ b/src/Message/Message_Level.hxx @@ -21,13 +21,23 @@ #include #include -//! 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(); @@ -35,59 +45,55 @@ public: //! 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 diff --git a/src/Message/Message_MetricType.hxx b/src/Message/Message_MetricType.hxx index 1529306864..a99db83399 100644 --- a/src/Message/Message_MetricType.hxx +++ b/src/Message/Message_MetricType.hxx @@ -1,6 +1,4 @@ -// 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. // diff --git a/src/Message/Message_PrinterToReport.cxx b/src/Message/Message_PrinterToReport.cxx index 99ce957882..0294a1382f 100644 --- a/src/Message/Message_PrinterToReport.cxx +++ b/src/Message/Message_PrinterToReport.cxx @@ -32,7 +32,6 @@ IMPLEMENT_STANDARD_RTTIEXT(Message_PrinterToReport, Message_Printer) //function : Report //purpose : //======================================================================= - const Handle(Message_Report)& Message_PrinterToReport::Report() const { if (!myReport.IsNull()) @@ -41,30 +40,19 @@ const Handle(Message_Report)& Message_PrinterToReport::Report() const 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(); @@ -73,18 +61,17 @@ void Message_PrinterToReport::Send (const TCollection_ExtendedString& theString, 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 @@ -92,12 +79,11 @@ void Message_PrinterToReport::Send (const Standard_SStream& theStream, 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; } @@ -106,7 +92,6 @@ void Message_PrinterToReport::Send (const Standard_SStream& theStream, //function : Send //purpose : //======================================================================= - void Message_PrinterToReport::Send (const Handle(Standard_Transient)& theObject, const Message_Gravity theGravity, const Standard_Boolean /*putEndl*/) const @@ -114,24 +99,21 @@ void Message_PrinterToReport::Send (const Handle(Standard_Transient)& theObject, 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(); } diff --git a/src/Message/Message_PrinterToReport.hxx b/src/Message/Message_PrinterToReport.hxx index 37d61ca04a..cc87d34f4b 100644 --- a/src/Message/Message_PrinterToReport.hxx +++ b/src/Message/Message_PrinterToReport.hxx @@ -25,7 +25,7 @@ class Message_PrinterToReport; 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 { @@ -33,24 +33,24 @@ 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; @@ -78,7 +78,7 @@ protected: 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 diff --git a/src/Message/Message_Report.cxx b/src/Message/Message_Report.cxx index f225f004e0..283a707169 100644 --- a/src/Message/Message_Report.cxx +++ b/src/Message/Message_Report.cxx @@ -38,47 +38,6 @@ Message_Report::Message_Report () { } -//======================================================================= -//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 : @@ -96,7 +55,7 @@ void Message_Report::AddAlert (Message_Gravity theGravity, const Handle(Message_ 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()); @@ -107,10 +66,8 @@ void Message_Report::AddAlert (Message_Gravity theGravity, const Handle(Message_ // 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); @@ -124,10 +81,11 @@ void Message_Report::AddAlert (Message_Gravity theGravity, const Handle(Message_ // 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); } @@ -144,24 +102,7 @@ const Message_ListOfAlert& Message_Report::GetAlerts (Message_Gravity theGravity 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); } //======================================================================= @@ -186,19 +127,86 @@ Standard_Boolean Message_Report::HasAlert (const Handle(Standard_Type)& theType) 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 : @@ -239,21 +247,23 @@ void Message_Report::Clear (const Handle(Standard_Type)& theType) 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); } //======================================================================= @@ -278,18 +288,11 @@ void Message_Report::Dump (Standard_OStream& theOS, Message_Gravity theGravity) { if (compositeAlerts().IsNull()) return; - const Message_ListOfAlert& anAlerts = compositeAlerts()->GetAlerts (theGravity); - // report each type of warning only once - NCollection_Map 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()); } //======================================================================= @@ -314,20 +317,8 @@ void Message_Report::SendMessages (const Handle(Message_Messenger)& theMessenger { 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 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()); } //======================================================================= @@ -360,10 +351,72 @@ void Message_Report::Merge (const Handle(Message_Report)& theOther, Message_Grav //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 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 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()); + } +} diff --git a/src/Message/Message_Report.hxx b/src/Message/Message_Report.hxx index 81d20febc5..f66f9f0037 100644 --- a/src/Message/Message_Report.hxx +++ b/src/Message/Message_Report.hxx @@ -51,6 +51,8 @@ DEFINE_STANDARD_HANDLE(Message_Report, Standard_Transient) //! 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 { @@ -59,15 +61,6 @@ public: //! 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); @@ -81,6 +74,22 @@ public: //! 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 (); @@ -90,6 +99,25 @@ public: //! 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& 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); @@ -108,48 +136,32 @@ public: //! 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& 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 myAlertLevels; //! container of alerts, new alerts are added below the latest level + NCollection_Sequence myAlertLevels; //! container of active levels, new alerts are added below the latest level NCollection_Map myActiveMetrics; //! metrics to compute on alerts + + Standard_Integer myLimit; //! Maximum number of collected alerts on the top level }; #endif // _Message_Report_HeaderFile diff --git a/src/OSD/OSD_MemInfo.cxx b/src/OSD/OSD_MemInfo.cxx index 8723021376..dd5457cad7 100644 --- a/src/OSD/OSD_MemInfo.cxx +++ b/src/OSD/OSD_MemInfo.cxx @@ -43,6 +43,11 @@ // ======================================================================= OSD_MemInfo::OSD_MemInfo (const Standard_Boolean theImmediateUpdate) { + NCollection_Map aCounters; + for (int i = (int)MemPrivate; i < MemCounter_NB; i++) + aCounters.Add ((Counter)i); + SetActiveCounters (aCounters); + if (theImmediateUpdate) { Update(); @@ -73,6 +78,9 @@ void OSD_MemInfo::Clear() void OSD_MemInfo::Update() { Clear(); + + if (IsActiveCounter (MemVirtual)) + { #ifndef OCCT_UWP #if defined(_WIN32) #if (_WIN32_WINNT >= 0x0500) @@ -86,7 +94,14 @@ void OSD_MemInfo::Update() 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) @@ -104,7 +119,10 @@ void OSD_MemInfo::Update() myCounters[MemSwapUsage] = aProcMemCnts.PagefileUsage; myCounters[MemSwapUsagePeak] = aProcMemCnts.PeakPagefileUsage; } + } + if (IsActiveCounter (MemHeapUsage)) + { _HEAPINFO hinfo; int heapstatus; hinfo._pentry = NULL; @@ -115,8 +133,12 @@ void OSD_MemInfo::Update() 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()); @@ -138,173 +160,46 @@ void OSD_MemInfo::Update() 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 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, @@ -320,7 +215,7 @@ void OSD_MemInfo::Update (const NCollection_Map theCounter myCounters[MemHeapUsage] = aStats.size_in_use; } -*/ + } #endif #endif } @@ -332,33 +227,33 @@ void OSD_MemInfo::Update (const NCollection_Map theCounter 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"; } @@ -371,7 +266,7 @@ TCollection_AsciiString OSD_MemInfo::ToString() const // ======================================================================= 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); } @@ -384,7 +279,7 @@ Standard_Size OSD_MemInfo::Value (const OSD_MemInfo::Counter theCounter) const // ======================================================================= 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); } @@ -398,7 +293,7 @@ Standard_Size OSD_MemInfo::ValueMiB (const OSD_MemInfo::Counter theCounter) cons // ======================================================================= 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; } @@ -415,3 +310,12 @@ TCollection_AsciiString OSD_MemInfo::PrintInfo() 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); +} diff --git a/src/OSD/OSD_MemInfo.hxx b/src/OSD/OSD_MemInfo.hxx index 84d4fda7ec..790649f9eb 100644 --- a/src/OSD/OSD_MemInfo.hxx +++ b/src/OSD/OSD_MemInfo.hxx @@ -69,15 +69,19 @@ public: //! 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& 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 theCounters); - //! Return the string representation for all available counter. Standard_EXPORT TCollection_AsciiString ToString() const; @@ -101,10 +105,16 @@ public: //! 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 myActiveCounters; //!< container of information to collect }; #endif // _OSD_MemInfo_H__ diff --git a/src/TopoDS/TopoDS_AlertAttribute.cxx b/src/TopoDS/TopoDS_AlertAttribute.cxx index 886260ac0d..a1b9c5b1ba 100644 --- a/src/TopoDS/TopoDS_AlertAttribute.cxx +++ b/src/TopoDS/TopoDS_AlertAttribute.cxx @@ -49,7 +49,7 @@ void TopoDS_AlertAttribute::Send (const Handle(Message_Messenger)& theMessenger, 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(); } diff --git a/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx b/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx index 8546a7e8c7..7747d0b693 100644 --- a/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx +++ b/src/XmlDrivers/XmlDrivers_MessageReportStorage.cxx @@ -180,11 +180,11 @@ void XmlDrivers_MessageReportStorage::exportAlert (const Handle(Message_Alert)& 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); } @@ -265,7 +265,7 @@ void XmlDrivers_MessageReportStorage::exportAlertParameters (const Handle(Messag { 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);