ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
PerformanceMonitoring
PerfMonTests
src
PerfMonTestManyLeaksAlg.cxx
Go to the documentation of this file.
1
2
3
/*
4
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5
*/
6
7
// PerfMonTestManyLeaksAlg.cxx
8
// Implementation file for class PerfMonTest::ManyLeaksAlg
9
// Author: R.Sesuter
11
12
13
// STL includes
14
15
// FrameWork includes
16
#include "Gaudi/Property.h"
17
18
// PerfMonTests includes
19
#include "
PerfMonTestManyLeaksAlg.h
"
20
21
using namespace
PerfMonTest
;
22
23
long
** ManyLeaksAlg::m_pointers
ATLAS_THREAD_SAFE
= NULL;
24
25
26
StatusCode
ManyLeaksAlg::initialize
()
27
{
28
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
) ;
29
30
// in m_pointers, we'll store the pointers to the allocated space
31
// they need to exist beyond the lifetime of this algorithm
32
// or the'll be gone and everything is labelled as 'definitly lost'
33
34
if
( !
bool
(m_pointers) )
35
m_pointers =
new
long
* [4];
36
37
if
(
m_leakInInit
)
leakAll
();
38
39
return
StatusCode::SUCCESS;
40
}
41
42
StatusCode
ManyLeaksAlg::execute
(
const
EventContext&
/*ctx*/
)
43
{
44
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
) ;
45
46
if
( 0 ==
m_leakSize
) {
47
return
StatusCode::SUCCESS;
48
}
49
50
if
( !
m_leakInInit
)
leakAll
();
51
52
return
StatusCode::SUCCESS;
53
}
54
55
void
ManyLeaksAlg::leakAll
()
56
{
57
// 1024: if it's too small, they'll be classified as definitely lost
58
// check Scott's wiki - will be created on the heap ?
59
const
unsigned
int
maxSize = 256;
60
long
**
array
=
new
long
* [maxSize];
61
for
(
unsigned
int
i=0; i<maxSize; ++i )
62
array
[i] = NULL;
63
64
// this one's definitely lost
65
m_pointers[0] = this->
definitelyLostFct
(array);
66
67
// this one's indirectly lost
68
m_pointers[2] = this->
indirectlyLostFct
(array);
69
70
// this one's possible lost
71
m_pointers[1] = this->
possibleLostFct
(array);
72
73
// we'll create a small 'mem leak', but it's still reachable
74
m_pointers[0] = this->
stillReachableFct
(array);
75
76
// don't delete m_pointers
77
}
78
79
long
*
ManyLeaksAlg::stillReachableFct
(
long
**
/* array */
)
80
{
81
if
( !
bool
(
m_stillReachable
) )
82
{
83
m_stillReachable
=
new
long
[
m_leakSize
];
84
85
// do something with it ...
86
87
// we don't really need it any more, but we never delete m_stillReachable
88
// delete [] m_stillReachable;
89
}
90
return
m_stillReachable
;
91
}
92
93
long
*
ManyLeaksAlg::possibleLostFct
(
long
**
/* array */
)
94
{
95
if
( !
bool
(
m_possibleLost
) )
96
{
97
// this one's possible lost
98
m_possibleLost
=
new
long
[
m_leakSize
];
99
// move along
100
m_possibleLost
++;
101
m_possibleLost
++;
102
m_possibleLost
++;
103
m_possibleLost
++;
104
105
// do something with it ...
106
107
// we don't really need it any more, but we never delete m_possibleLost
108
// delete [] m_possibleLost (must point to original location !!!)
109
}
110
return
m_possibleLost
;
111
}
112
113
long
*
ManyLeaksAlg::indirectlyLostFct
(
long
**
array
)
114
{
115
if
( !
bool
(
m_indirectlyLost
) )
116
{
117
// this one's indirectly lost
118
m_indirectlyLost
=
new
long
[
m_leakSize
];
119
120
// move along
121
m_indirectlyLost
++;
122
m_indirectlyLost
++;
123
m_indirectlyLost
++;
124
m_indirectlyLost
++;
125
m_indirectlyLost
++;
126
m_indirectlyLost
++;
127
m_indirectlyLost
++;
128
m_indirectlyLost
++;
129
130
// save pointer in array
131
array
[127] =
m_indirectlyLost
;
132
133
// do something with it ...
134
135
// and (accidentially) invalidate pointer
136
m_indirectlyLost
= NULL;
137
138
// we don't need it any more, but we don't clean up and delete array
139
// array goes out of scope and it's lost !
140
// array still points to m_indirectlyLost which is now indirectly lost
141
}
142
return
m_indirectlyLost
;
143
}
144
145
long
*
ManyLeaksAlg::definitelyLostFct
(
long
**
/* array */
)
146
{
147
if
( !
bool
(
m_definitelyLost
) )
148
{
149
// this one's definitely lost
150
m_definitelyLost
=
new
long
[
m_leakSize
];
151
152
// do something with it ...
153
154
// and (accidentially) invalidate pointer
155
m_definitelyLost
= NULL;
156
// now, we cannot delete m_possibleLost, because it's pointer value is gone
157
// there's no reference in memory, so we cannot even do :
158
// delete [] m_possibleLost;
159
}
160
return
m_definitelyLost
;
161
}
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
PerfMonTestManyLeaksAlg.h
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
PerfMonTest::ManyLeaksAlg::stillReachableFct
long * stillReachableFct(long **array)
Definition
PerfMonTestManyLeaksAlg.cxx:79
PerfMonTest::ManyLeaksAlg::leakAll
void leakAll()
this one's definitely lost
Definition
PerfMonTestManyLeaksAlg.cxx:55
PerfMonTest::ManyLeaksAlg::m_leakSize
Gaudi::Property< int > m_leakSize
Property to setup the size of the leak.
Definition
PerfMonTestManyLeaksAlg.h:53
PerfMonTest::ManyLeaksAlg::m_definitelyLost
long * m_definitelyLost
Definition
PerfMonTestManyLeaksAlg.h:70
PerfMonTest::ManyLeaksAlg::possibleLostFct
long * possibleLostFct(long **array)
this one's possible lost
Definition
PerfMonTestManyLeaksAlg.cxx:93
PerfMonTest::ManyLeaksAlg::m_leakInInit
Gaudi::Property< bool > m_leakInInit
Property to setup the location of the leak, in initialize (true) or execute (false).
Definition
PerfMonTestManyLeaksAlg.h:56
PerfMonTest::ManyLeaksAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
PerfMonTestManyLeaksAlg.cxx:42
PerfMonTest::ManyLeaksAlg::m_possibleLost
long * m_possibleLost
Definition
PerfMonTestManyLeaksAlg.h:64
PerfMonTest::ManyLeaksAlg::indirectlyLostFct
long * indirectlyLostFct(long **array)
this one's indirectly lost
Definition
PerfMonTestManyLeaksAlg.cxx:113
PerfMonTest::ManyLeaksAlg::definitelyLostFct
long * definitelyLostFct(long **array)
this one's definitely lost
Definition
PerfMonTestManyLeaksAlg.cxx:145
PerfMonTest::ManyLeaksAlg::m_stillReachable
long * m_stillReachable
Definition
PerfMonTestManyLeaksAlg.h:61
PerfMonTest::ManyLeaksAlg::m_indirectlyLost
long * m_indirectlyLost
Definition
PerfMonTestManyLeaksAlg.h:67
PerfMonTest::ManyLeaksAlg::initialize
virtual StatusCode initialize() override
Definition
PerfMonTestManyLeaksAlg.cxx:26
array
STL class.
PerfMonTest
PerfMonTestPolyVectorAlg.h Example for the memory optimization tutorial.
Definition
Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:7
Generated on
for ATLAS Offline Software by
1.17.0