Line data Source code
1 : #pragma once
2 :
3 : #include <string>
4 : #include <set>
5 : #include <map>
6 : #include <vector>
7 : #include <atomic>
8 : #include <sstream>
9 : #include "../../odbdesign_export.h"
10 :
11 : namespace Odb::Lib::FileModel::Design
12 : {
13 : // Utility class for tracing component height data flow
14 : // Tracks specific components (configurable list) and first N failures
15 : class ODBDESIGN_EXPORT ComponentHeightTracer
16 : {
17 : public:
18 : static ComponentHeightTracer &instance();
19 :
20 : // Check if a component should be traced
21 : bool shouldTrace(const std::string &compName, unsigned int pkgRef) const;
22 :
23 : // Check if this is a failure case (for first N failures tracking)
24 : bool shouldTraceFailure() const;
25 :
26 : // Mark a failure (increments failure counter) - const because atomic is thread-safe
27 : void markFailure() const;
28 :
29 : // Logging helpers
30 : void logParseStart(const std::string &compName, unsigned int pkgRef, const std::string &attrIdString) const;
31 : void logParseResult(const std::string &compName, unsigned int pkgRef,
32 : const std::map<std::string, std::string> &lookupTable,
33 : const std::vector<std::string> &attributeNames) const;
34 : void logSerialization(const std::string &compName, unsigned int pkgRef,
35 : const std::map<std::string, std::string> &lookupTable,
36 : const std::vector<std::string> &attributeNames) const;
37 : void logGrpcResponse(const std::string &compName, unsigned int pkgRef,
38 : const std::map<std::string, std::string> &lookupTable,
39 : const std::vector<std::string> &attributeNames) const;
40 : void logRestResponse(const std::string &compName, unsigned int pkgRef,
41 : const std::map<std::string, std::string> &lookupTable,
42 : const std::vector<std::string> &attributeNames) const;
43 :
44 : // Configuration
45 : void addComponentToTrace(const std::string &compName);
46 : void setMaxFailuresToTrace(int maxFailures);
47 :
48 : private:
49 : ComponentHeightTracer();
50 79 : ~ComponentHeightTracer() = default;
51 :
52 : std::set<std::string> m_componentsToTrace;
53 : mutable std::atomic<int> m_failureCount{0};
54 : int m_maxFailuresToTrace{20};
55 :
56 : std::string formatLookupTable(const std::map<std::string, std::string> &lookupTable) const;
57 : std::string formatAttributeNames(const std::vector<std::string> &attributeNames) const;
58 : std::string getCompKey(const std::string &compName, unsigned int pkgRef) const;
59 : };
60 : }
|