libzypp: zypp/base/Debug.h Source File

libzypp 17.38.14

Debug.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
13#ifndef ZYPP_NDEBUG
14#warning ZYPP_BASE_DEBUG_H included
15#ifndef ZYPP_BASE_DEBUG_H
16#define ZYPP_BASE_DEBUG_H
17
18#include <iosfwd>
19//#include <sstream>
20//#include <string>
21#include <zypp-core/base/Logger.h>
22#include <zypp-core/base/String.h>
23#include <zypp-core/ExternalProgram.h>
24#include <zypp-core/base/ProvideNumericId>
25
27namespace zypp
28{
30 namespace debug
31 {
32
35
36#define TAG INT << __PRETTY_FUNCTION__ << std::endl
37
39 inline std::ostream & dumpMemOn( std::ostream & str, const std::string & msg = std::string() )
40 {
41 static std::string mypid( str::numstring( getpid() ) );
42 const char* argv[] =
43 {
44 "ps",
45 "v",
46 mypid.c_str(),
47 NULL
48 };
49 ExternalProgram prog(argv,ExternalProgram::Discard_Stderr, false, -1, true);
50
51 str << "MEMUSAGE " << msg << std::endl;
52 for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
53 str << line;
54
55 prog.close();
56 return str;
57 }
58
60
64
67 struct TraceCADBase
68 {
69 enum What { CTOR, COPYCTOR, MOVECTOR, ASSIGN, MOVEASSIGN, DTOR, PING };
70 std::string _ident;
71 };
72
74 inline std::ostream & operator<<( std::ostream & str, TraceCADBase::What obj )
75 {
76 switch( obj )
77 {
78 case TraceCADBase::CTOR: return str << "CTOR";
79 case TraceCADBase::COPYCTOR: return str << "COPYCTOR";
80 case TraceCADBase::MOVECTOR: return str << "MOVECTOR";
81 case TraceCADBase::ASSIGN: return str << "ASSIGN";
82 case TraceCADBase::MOVEASSIGN: return str << "MOVEASSIGN";
83 case TraceCADBase::DTOR: return str << "DTOR";
84 case TraceCADBase::PING: return str << "PING";
85 }
86 return str;
87 }
88
110 template<class Tp>
111 struct TraceCAD : public base::ProvideNumericId<TraceCAD<Tp>, unsigned long>
112 , public TraceCADBase
113 {
114 static unsigned long & _totalTraceCAD()
115 { static unsigned long _val = 0;
116 return _val; }
117
118 TraceCAD()
119 { _ident = __PRETTY_FUNCTION__;
120 ++_totalTraceCAD();
121 traceCAD( CTOR, *this, *this ); }
122
123 TraceCAD( const TraceCAD & rhs )
124 { ++_totalTraceCAD();
125 traceCAD( COPYCTOR, *this, rhs ); }
126
127 TraceCAD( TraceCAD && rhs ) noexcept
128 { ++_totalTraceCAD();
129 traceCAD( MOVECTOR, *this, rhs ); }
130
131 TraceCAD & operator=( const TraceCAD & rhs )
132 { traceCAD( ASSIGN, *this, rhs ); return *this; }
133
134 TraceCAD & operator=( TraceCAD && rhs ) noexcept
135 { traceCAD( MOVEASSIGN, *this, rhs ); return *this; }
136
137 virtual ~TraceCAD()
138 { --_totalTraceCAD();
139 traceCAD( DTOR, *this, *this ); }
140
141 void ping() const
142 { traceCAD( PING, *this, *this ); }
143 };
144
146 template<class Tp>
147 inline std::ostream & operator<<( std::ostream & str, const TraceCAD<Tp> & obj )
148 { return str << "(ID " << obj.numericId() << ", TOTAL " << obj._totalTraceCAD()
149 << ") [" << &obj << "] "; }
150
154 template<class Tp>
155 void traceCAD( TraceCADBase::What what_r,
156 const TraceCAD<Tp> & self_r,
157 const TraceCAD<Tp> & rhs_r )
158 {
159 switch( what_r )
160 {
161 case TraceCADBase::CTOR:
162 case TraceCADBase::PING:
163 case TraceCADBase::DTOR:
164 L_DBG("DEBUG") << what_r << self_r << " (" << self_r._ident << ")" << std::endl;
165 break;
166
167 case TraceCADBase::COPYCTOR:
168 case TraceCADBase::MOVECTOR:
169 case TraceCADBase::ASSIGN:
170 case TraceCADBase::MOVEASSIGN:
171 L_DBG("DEBUG") << what_r << self_r << "( " << rhs_r << ")" << " (" << self_r._ident << ")" << std::endl;
172 break;
173 }
174 }
175
176
177
179 } // namespace debug
180
182} // namespace zypp
184#endif // ZYPP_BASE_DEBUG_H
185#endif // ZYPP_NDEBUG
ExternalProgram.h
Logger.h
L_DBG
#define L_DBG(GROUP)
Definition Logger.h:111
String.h
zypp::ExternalProgram
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Definition ExternalProgram.h:64
zypp::ExternalProgram::close
int close() override
Wait for the progamm to complete.
Definition ExternalProgram.cc:357
zypp::ExternalProgram::Discard_Stderr
@ Discard_Stderr
Definition ExternalProgram.h:76
zypp::externalprogram::ExternalDataSource::receiveLine
std::string receiveLine()
Read one line from the input stream.
Definition ExternalDataSource.cc:115
str
String related utilities and Regular expression matching.
zypp::debug
Definition Debug.h:31
zypp::debug::operator<<
std::ostream & operator<<(std::ostream &str, TraceCADBase::What obj)
relates: TraceCADBase Stream output of TraceCADBase::What.
Definition Debug.h:74
zypp::debug::traceCAD
void traceCAD(TraceCADBase::What what_r, const TraceCAD< Tp > &self_r, const TraceCAD< Tp > &rhs_r)
Drop a log line about the traced method.
Definition Debug.h:155
zypp::debug::dumpMemOn
std::ostream & dumpMemOn(std::ostream &str, const std::string &msg=std::string())
'ps v'
Definition Debug.h:39
zypp::str::numstring
std::string numstring(char n, int w=0)
Definition String.h:290
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::base::ProvideNumericId
Base class for objects providing a numeric Id.
Definition providenumericid.h:46
zypp::base::ProvideNumericId::numericId
TNumericIdType numericId() const
Definition providenumericid.h:49
zypp::debug::TraceCADBase
Base for a simple tracer.
Definition Debug.h:68
zypp::debug::TraceCADBase::What
What
Definition Debug.h:69
zypp::debug::TraceCADBase::COPYCTOR
@ COPYCTOR
Definition Debug.h:69
zypp::debug::TraceCADBase::DTOR
@ DTOR
Definition Debug.h:69
zypp::debug::TraceCADBase::MOVEASSIGN
@ MOVEASSIGN
Definition Debug.h:69
zypp::debug::TraceCADBase::ASSIGN
@ ASSIGN
Definition Debug.h:69
zypp::debug::TraceCADBase::PING
@ PING
Definition Debug.h:69
zypp::debug::TraceCADBase::CTOR
@ CTOR
Definition Debug.h:69
zypp::debug::TraceCADBase::MOVECTOR
@ MOVECTOR
Definition Debug.h:69
zypp::debug::TraceCADBase::_ident
std::string _ident
Definition Debug.h:70
zypp::debug::TraceCAD
A simple tracer for (copy) Construction, Assignment, and Destruction.
Definition Debug.h:113
zypp::debug::TraceCAD::TraceCAD
TraceCAD(const TraceCAD &rhs)
Definition Debug.h:123
zypp::debug::TraceCAD::~TraceCAD
virtual ~TraceCAD()
Definition Debug.h:137
zypp::debug::TraceCAD::operator=
TraceCAD & operator=(TraceCAD &&rhs) noexcept
Definition Debug.h:134
zypp::debug::TraceCAD::TraceCAD
TraceCAD(TraceCAD &&rhs) noexcept
Definition Debug.h:127
zypp::debug::TraceCAD::operator=
TraceCAD & operator=(const TraceCAD &rhs)
Definition Debug.h:131
zypp::debug::TraceCAD::_totalTraceCAD
static unsigned long & _totalTraceCAD()
Definition Debug.h:114
zypp::debug::TraceCAD::TraceCAD
TraceCAD()
Definition Debug.h:118
zypp::debug::TraceCAD::ping
void ping() const
Definition Debug.h:141