1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

0031362: Inspectors - MessageView plugin for message alerts

DumpJson correction

(cherry picked from commit 1f4dcce7ee5da0846acd124a3ff900aaad1d2cbd)
(cherry picked from commit 03f183f4fea1992f1ee05ded17a88db1dc434ee0)
(cherry picked from commit 45db541dd3dac1890ac10ce09b6605ddcce82e53)
(cherry picked from commit 8b7b151aa4ccbe46ddeeecf59d18577e0fb3d8b2)

# Conflicts:
#	src/Select3D/Select3D_SensitiveEntity.cxx
#	src/Standard/Standard_Dump.hxx
#	src/gp/gp_Ax1.cxx
#	src/gp/gp_Ax2.cxx
#	src/gp/gp_Ax3.cxx
#	src/gp/gp_Dir.cxx
#	src/gp/gp_Mat.cxx
#	src/gp/gp_Pnt.cxx
#	src/gp/gp_Trsf.cxx
This commit is contained in:
nds
2020-10-08 12:27:06 +03:00
parent 59a6dfcaff
commit 4eb3e3b90f
10 changed files with 99 additions and 17 deletions

View File

@@ -25,9 +25,10 @@
namespace
{
static Standard_CString Message_Table_PrintMetricTypeEnum[10] =
static Standard_CString Message_Table_PrintMetricTypeEnum[13] =
{
"NONE", "UserTimeCPU", "SystemTimeInfo", "MemPrivate", "MemVirtual",
"NONE", "UserThreadCPU", "SystemThreadCPU", "UserTimeCPU", "SystemTimeCPU",
"WallClock", "MemPrivate", "MemVirtual",
"MemWorkingSet", "MemWorkingSetPeak", "MemSwapUsage", "MemSwapUsagePeak", "MemHeapUsage"
};
}

View File

@@ -17,6 +17,7 @@
#include <Message.hxx>
#include <Message_Report.hxx>
#include <OSD_Chronometer.hxx>
#include <OSD_Timer.hxx>
#include <Precision.hxx>
#include <Standard_Dump.hxx>
@@ -128,6 +129,16 @@ void Message_AttributeMeter::SetAlertMetrics (const Handle(Message_AlertExtended
const NCollection_IndexedMap<Message_MetricType>& anActiveMetrics = aReport->ActiveMetrics();
// time metrics
if (anActiveMetrics.Contains (Message_MetricType_WallClock))
{
OSD_Timer aTimer;
aTimer.Start();
Standard_Real aTime = aTimer.StartTime();
if (theStartValue)
aMeterAttribute->SetStartValue (Message_MetricType_WallClock, aTime);
else
aMeterAttribute->SetStopValue (Message_MetricType_WallClock, aTime);
}
if (anActiveMetrics.Contains (Message_MetricType_ProcessCPUUserTime) ||
anActiveMetrics.Contains (Message_MetricType_ProcessCPUSystemTime) ||
anActiveMetrics.Contains (Message_MetricType_ThreadCPUUserTime) ||
@@ -244,13 +255,7 @@ void Message_AttributeMeter::DumpJson (Standard_OStream& theOStream,
for (NCollection_IndexedDataMap<Message_MetricType, StartToStopValue>::Iterator anIterator (myMetrics);
anIterator.More(); anIterator.Next())
{
Message_MetricType aMetricType = anIterator.Key();
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aMetricType)
Standard_Real aStartValue = anIterator.Value().first;
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aStartValue)
Standard_Real aStopValue = anIterator.Value().second;
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aStopValue)
OCCT_DUMP_VECTOR_CLASS (theOStream, Message::MetricToString (anIterator.Key()),
2, anIterator.Value().first, anIterator.Value().second)
}
}

View File

@@ -47,6 +47,5 @@ void Message_AttributeStream::DumpJson (Standard_OStream& theOStream,
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Message_Attribute)
TCollection_AsciiString aStream = Standard_Dump::Text (myStream);
OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aStream)
OCCT_DUMP_STREAM_VALUE_DUMPED (theOStream, myStream)
}

View File

@@ -171,13 +171,17 @@ void Message_CompositeAlerts::DumpJson (Standard_OStream& theOStream,
for (unsigned int i = 0; i < sizeof(myAlerts)/sizeof(myAlerts[0]); ++i)
{
if (myAlerts[i].IsEmpty())
continue;
Message_Gravity aGravity = (Message_Gravity)i;
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aGravity)
for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); anIt.Next())
Standard_Integer anInc = 1;
for (Message_ListOfAlert::Iterator anIt (myAlerts[i]); anIt.More(); anIt.Next(), anInc++)
{
const Handle(Message_Alert)& anAlert = anIt.Value();
OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anAlert.get())
OCCT_DUMP_FIELD_VALUES_DUMPED_INC (theOStream, theDepth, anAlert.get(), anInc)
}
}
}

View File

@@ -22,6 +22,7 @@ enum Message_MetricType
Message_MetricType_ThreadCPUSystemTime, //!< OSD_Chronometer::GetThreadCPU system time
Message_MetricType_ProcessCPUUserTime, //!< OSD_Chronometer::GetProcessCPU user time
Message_MetricType_ProcessCPUSystemTime, //!< OSD_Chronometer::GetProcessCPU system time
Message_MetricType_WallClock, //!< OSD_Timer elapsed time
Message_MetricType_MemPrivate, //!< OSD_MemInfo::MemPrivate
Message_MetricType_MemVirtual, //!< OSD_MemInfo::MemVirtual
Message_MetricType_MemWorkingSet, //!< OSD_MemInfo::MemWorkingSet

View File

@@ -79,6 +79,9 @@ public:
//! the Timer.
Standard_EXPORT virtual void Start() Standard_OVERRIDE;
//! Returns start time in seconds.
Standard_Real StartTime() const { return myTimeStart; }
//! Returns elapsed time in seconds.
Standard_EXPORT Standard_Real ElapsedTime() const;

View File

@@ -39,7 +39,7 @@ void Select3D_SensitiveEntity::DumpJson (Standard_OStream& theOStream, Standard_
{
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myOwnerId.get())
OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myOwnerId.get())
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, mySFactor)
//OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, NbSubElements());

View File

@@ -125,6 +125,27 @@ void SelectMgr_Selection::DumpJson (Standard_OStream& theOStream, Standard_Integ
{
OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)> anOwners;
for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anIterator (myEntities); anIterator.More(); anIterator.Next())
{
const Handle(SelectMgr_SensitiveEntity)& anEntity = anIterator.Value();
if (anEntity.IsNull() || anEntity->BaseSensitive().IsNull())
{
continue;
}
const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->BaseSensitive()->OwnerId();
if (!anOwners.Contains (anOwner))
{
anOwners.Add (anOwner);
}
}
for (NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)>::Iterator anIterator (anOwners); anIterator.More(); anIterator.Next())
{
const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anOwner.get())
}
for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anIterator (myEntities); anIterator.More(); anIterator.Next())
{
const Handle(SelectMgr_SensitiveEntity)& anEntity = anIterator.Value();

View File

@@ -24,7 +24,7 @@ void Standard_Dump::AddValuesSeparator (Standard_OStream& theOStream)
Standard_SStream aStream;
aStream << theOStream.rdbuf();
TCollection_AsciiString aStreamStr = Standard_Dump::Text (aStream);
if (!aStreamStr.IsEmpty() && !aStreamStr.EndsWith ("{"))
if (!aStreamStr.IsEmpty() && !aStreamStr.EndsWith ("{") && !aStreamStr.EndsWith (", "))
theOStream << ", ";
}
@@ -173,9 +173,15 @@ TCollection_AsciiString Standard_Dump::FormatJson (const Standard_SStream& theSt
Standard_Integer anIndentCount = 0;
Standard_Boolean isMassiveValues = Standard_False;
for (Standard_Integer anIndex = 1; anIndex < aStreamStr.Length(); anIndex++)
for (Standard_Integer anIndex = 1; anIndex <= aStreamStr.Length(); anIndex++)
{
Standard_Character aSymbol = aStreamStr.Value (anIndex);
if (anIndex == 1 && aText.IsEmpty() && aSymbol != '{')
{
// append opening brace for json start
aSymbol = '{';
anIndex--;
}
if (aSymbol == '{')
{
anIndentCount++;
@@ -221,6 +227,18 @@ TCollection_AsciiString Standard_Dump::FormatJson (const Standard_SStream& theSt
}
else
aText += aSymbol;
if (anIndex == aStreamStr.Length() && aSymbol != '}')
{
// append closing brace for json end
aSymbol = '}';
anIndentCount--;
aText += '\n';
for (int anIndent = 0; anIndent < anIndentCount; anIndent++)
aText += anIndentStr;
aText += aSymbol;
}
}
return aText;
}

View File

@@ -121,6 +121,35 @@
} \
}
//! @def OCCT_DUMP_FIELD_VALUES_DUMPED
//! Append into output value: "Name": { field dumped values }
//! It computes Dump of the fields. The expected field is a pointer.
//! Use this macro for fields of the dumped class which has own Dump implementation.
//! The macros is recursive. Recursion is stopped when the depth value becomes equal to zero.
//! Depth = -1 is the default value, dump here is unlimited.
#define OCCT_DUMP_FIELD_VALUES_DUMPED_INC(theOStream, theDepth, theField, theIncName) \
{ \
if (theDepth != 0 && (void*)(theField) != NULL) \
{ \
Standard_SStream aFieldStream; \
(theField)->DumpJson (aFieldStream, theDepth - 1); \
TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (#theField) + theIncName; \
Standard_Dump::DumpKeyToClass (theOStream, aName, Standard_Dump::Text (aFieldStream)); \
} \
}
//! @def OCCT_DUMP_FIELD_VALUES_DUMPED
//! Append into output value: "Name": { field dumped values }
//! It computes Dump of the fields. The expected field is a pointer.
//! Use this macro for fields of the dumped class which has own Dump implementation.
//! The macros is recursive. Recursion is stopped when the depth value becomes equal to zero.
//! Depth = -1 is the default value, dump here is unlimited.
#define OCCT_DUMP_STREAM_VALUE_DUMPED(theOStream, theField) \
{ \
TCollection_AsciiString aName = Standard_Dump::DumpFieldToName (#theField); \
Standard_Dump::DumpKeyToClass (theOStream, aName, Standard_Dump::Text (theField)); \
}
//! @def OCCT_DUMP_FIELD_VALUES_NUMERICAL
//! Append real values into output values in an order: [value_1, value_2, ...]
//! It computes Dump of the parent. The expected field is a parent class name to call ClassName::Dump.
@@ -207,6 +236,7 @@ public:
//! - for '{' append after '\n' and indent to the next value, increment current indent value
//! - for '}' append '\n' and current indent before it, decrement indent value
//! - for ',' append after '\n' and indent to the next value. If the current symbol is in massive container [], do nothing
//! Covers result with opened and closed brackets on the top level, if it has no symbols there.
//! @param theStream source value
//! @param theIndent count of ' ' symbols to apply hierarchical indent of the text values
//! @return text presentation