1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-13 14:27:08 +03:00

0029451: Information Message Alert to debug an algorithm or object functionality

- Added possibility to send stream information and transient object into Message_Messenger. Message_Printer will process it if needed.
- Add Message_PrinterToReport to send messenger information into Message_Report.
- Extended Message_Report to collect hierarchical alerts, to be able to collect some metrics during alerts processing.
- Added Message_AlertExtended to prepare hierarchical alerts with custom attributes. One attribute for one alert.
- Added Message_CompositeAlerts class to handle a container of alerts.
- Added Message_Level to start a new hierarchical level by creating an instance, stop by destricting.
- Added Message_Attribute and inheritors to store custom information about alert like object, stream, shape, some metrics.
- Implement Message_AttributeAlert to collect start/stop information about active metrics of Message_Report. This kind of attribute is created if at least one metric is active in the report.
- Add Message_MetricType enumeration with possible kinds of metrics in report.
- Implement DumpJson for Message_Report to store all collected alerts into stream.
- Added draw commands for Message_Report, Message_Messenger.
This commit is contained in:
nds
2020-10-02 14:17:59 +03:00
committed by bugmaster
parent dba9887351
commit 6522304c17
37 changed files with 2734 additions and 81 deletions

View File

@@ -17,12 +17,18 @@
#define _Message_Report_HeaderFile
#include <Message_Gravity.hxx>
#include <Message_Level.hxx>
#include <Message_ListOfAlert.hxx>
#include <Message_MetricType.hxx>
#include <NCollection_IndexedMap.hxx>
#include <NCollection_Sequence.hxx>
#include <Standard_Mutex.hxx>
class Message_CompositeAlerts;
class Message_Messenger;
class Message_Report;
DEFINE_STANDARD_HANDLE(Message_Report, MMgt_TShared)
//! Container for alert messages, sorted according to their gravity.
@@ -46,7 +52,8 @@ DEFINE_STANDARD_HANDLE(Message_Report, MMgt_TShared)
//! 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
{
public:
@@ -67,6 +74,28 @@ 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);
//! Updates internal flag IsActiveInMessenger.
//! It becomes true if messenger contains at least one instance of Message_PrinterToReport.
//! @param theMessenger the messenger. If it's NULL, the default messenger is used
Standard_EXPORT void UpdateActiveInMessenger (const Handle(Message_Messenger)& theMessenger = NULL);
//! Add new level of alerts
//! @param theLevel a level
Standard_EXPORT void AddLevel (Message_Level* theLevel, const TCollection_AsciiString& theName);
//! Remove level of alerts
Standard_EXPORT void RemoveLevel (Message_Level* theLevel);
//! Clears all collected alerts
Standard_EXPORT void Clear ();
@@ -76,6 +105,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_IndexedMap<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.
//! @param theLimit limit value
void SetLimit(const Standard_Integer theLimit) { myLimit = theLimit; }
//! Dumps all collected alerts to stream
Standard_EXPORT void Dump (Standard_OStream& theOS);
@@ -97,15 +145,36 @@ public:
//! Merges alerts with specified gravity from theOther report into this
Standard_EXPORT void Merge (const Handle(Message_Report)& theOther, Message_Gravity theGravity);
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, 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 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
Message_ListOfAlert myAlerts[Message_Fail + 1];
Handle(Message_CompositeAlerts) myCompositAlerts; //!< container of alerts
NCollection_Sequence<Message_Level*> myAlertLevels; //!< container of active levels, new alerts are added below the latest level
NCollection_IndexedMap<Message_MetricType> myActiveMetrics; //!< metrics to compute on alerts
Standard_Integer myLimit; //!< Maximum number of collected alerts on the top level
Standard_Boolean myIsActiveInMessenger; //! state whether the report is activated in messenger
};
#endif // _Message_Report_HeaderFile