Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-xt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ag-ohlberger
dune-community
dune-xt
Commits
ef58c3dd
Commit
ef58c3dd
authored
14 years ago
by
René Fritze
Browse files
Options
Downloads
Patches
Plain Diff
profiler: fix mysterious memory corruption error in ScopeTiming usage
parent
97742c9a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
stuff/profiler.hh
+42
-23
42 additions, 23 deletions
stuff/profiler.hh
with
42 additions
and
23 deletions
stuff/profiler.hh
+
42
−
23
View file @
ef58c3dd
...
@@ -25,11 +25,19 @@ struct TimingData
...
@@ -25,11 +25,19 @@ struct TimingData
TimingData
(
const
std
::
string
_name
,
const
clock_t
_start
)
TimingData
(
const
std
::
string
_name
,
const
clock_t
_start
)
:
start
(
_start
)
:
start
(
_start
)
,
end
((
clock_t
)
0.0
)
,
end
((
clock_t
)
0.0
)
,
name
(
_name
){};
,
name
(
_name
)
{
}
TimingData
()
TimingData
()
:
start
((
clock_t
)
0.0
)
:
start
((
clock_t
)
0.0
)
,
end
((
clock_t
)
0.0
)
,
end
((
clock_t
)
0.0
)
,
name
(
"blank"
){};
,
name
(
"blank"
)
{
}
long
delta
()
const
{
return
long
(
end
-
start
);
}
};
};
/** \brief simple inline profiling class
/** \brief simple inline profiling class
...
@@ -51,53 +59,63 @@ protected:
...
@@ -51,53 +59,63 @@ protected:
{
{
}
}
typedef
std
::
vector
<
TimingData
>
TimingVector
;
typedef
std
::
map
<
std
::
string
,
std
::
pair
<
bool
,
TimingData
>>
KnownTimersMap
;
typedef
std
::
map
<
std
::
string
,
TimingVector
>
DataMap
;
typedef
std
::
map
<
std
::
string
,
long
>
DataMap
;
typedef
std
::
vector
<
DataMap
>
MapVector
;
typedef
std
::
vector
<
DataMap
>
MapVector
;
public
:
public
:
//! set this to begin a named section
//! set this to begin a named section
void
StartTiming
(
const
std
::
string
section_name
)
void
StartTiming
(
const
std
::
string
section_name
)
{
{
TimingData
td
(
section_name
,
clock
());
if
(
m_cur_run_num
>=
m_timings
.
size
())
{
if
(
m_cur_run_num
>=
m_timings
.
size
())
{
m_timings
.
push_back
(
DataMap
());
m_timings
.
push_back
(
DataMap
());
m_total_runs
++
;
m_total_runs
++
;
}
}
(
m_timings
[
m_cur_run_num
])[
section_name
].
push_back
(
td
);
KnownTimersMap
::
iterator
section
=
known_timers_map_
.
find
(
section_name
);
if
(
section
!=
known_timers_map_
.
end
())
{
if
(
section
->
second
.
first
)
// timer currently running
return
;
section
->
second
.
first
=
true
;
// set active, start with new
section
->
second
.
second
=
TimingData
(
section_name
,
clock
());
}
else
{
// init new section
known_timers_map_
[
section_name
]
=
std
::
make_pair
(
true
,
TimingData
(
section_name
,
clock
()));
}
}
}
//! stop named section's counter
//! stop named section's counter
void
StopTiming
(
const
std
::
string
section_name
)
void
StopTiming
(
const
std
::
string
section_name
)
{
{
assert
(
m_cur_run_num
<
m_timings
.
size
());
assert
(
m_cur_run_num
<
m_timings
.
size
());
if
(
(
m_timings
[
m_cur_run_num
])[
section_name
].
size
()
<
1
)
if
(
known_timers_map_
.
find
(
section_name
)
==
known_timers_map_
.
end
()
)
DUNE_THROW
(
Dune
::
RangeError
,
"trying to stop timer "
<<
section_name
<<
" that wasn't started
\n
"
);
DUNE_THROW
(
Dune
::
RangeError
,
"trying to stop timer "
<<
section_name
<<
" that wasn't started
\n
"
);
(
m_timings
[
m_cur_run_num
])[
section_name
].
back
().
end
=
clock
();
known_timers_map_
[
section_name
].
first
=
false
;
known_timers_map_
[
section_name
].
second
.
end
=
clock
();
DataMap
&
current_data
=
m_timings
[
m_cur_run_num
];
if
(
current_data
.
find
(
section_name
)
==
current_data
.
end
())
current_data
[
section_name
]
=
known_timers_map_
[
section_name
].
second
.
delta
();
else
current_data
[
section_name
]
+=
known_timers_map_
[
section_name
].
second
.
delta
();
}
}
//! get runtime of section in seconds
//! get runtime of section in seconds
long
GetTiming
(
const
std
::
string
section_name
)
const
long
GetTiming
(
const
std
::
string
section_name
)
const
{
{
std
::
cerr
<<
"SEC "
<<
section_name
<<
std
::
endl
;
return
GetTiming
(
section_name
,
m_cur_run_num
);
}
long
GetTiming
(
const
std
::
string
section_name
,
const
int
run_number
)
const
{
assert
(
m_cur_run_num
<
m_timings
.
size
());
assert
(
m_cur_run_num
<
m_timings
.
size
());
const
DataMap
&
data
=
m_timings
[
m_cur_
run_num
];
const
DataMap
&
data
=
m_timings
[
run_num
ber
];
DataMap
::
const_iterator
section
=
data
.
find
(
section_name
);
DataMap
::
const_iterator
section
=
data
.
find
(
section_name
);
if
(
section
==
data
.
end
())
{
if
(
section
==
data
.
end
())
{
ASSERT_EXCEPTION
(
false
,
"no timer found: "
+
section_name
);
ASSERT_EXCEPTION
(
false
,
"no timer found: "
+
section_name
);
return
-
1
;
return
-
1
;
}
}
return
GetTiming
(
section
->
second
);
return
long
(
section
->
second
/
double
(
CLOCKS_PER_SEC
));
}
long
GetTiming
(
const
TimingVector
&
timing_vector
)
const
{
TimingVector
::
const_iterator
endIt
=
timing_vector
.
end
();
TimingVector
::
const_iterator
it
=
timing_vector
.
begin
();
long
diff
=
0
;
for
(;
it
!=
endIt
;
++
it
)
{
diff
+=
it
->
end
-
it
->
start
;
}
return
long
(
diff
/
double
(
CLOCKS_PER_SEC
));
}
}
/** output to currently pre-defined (csv) file, does not output individual run results, but average over all recorded
/** output to currently pre-defined (csv) file, does not output individual run results, but average over all recorded
...
@@ -152,7 +170,7 @@ public:
...
@@ -152,7 +170,7 @@ public:
}
}
//! a utility class to time a limited scope of code
//! a utility class to time a limited scope of code
class
ScopedTiming
class
ScopedTiming
:
public
boost
::
noncopyable
{
{
const
std
::
string
section_name_
;
const
std
::
string
section_name_
;
...
@@ -175,6 +193,7 @@ protected:
...
@@ -175,6 +193,7 @@ protected:
// debug counter, only outputted in debug mode
// debug counter, only outputted in debug mode
std
::
map
<
int
,
int
>
m_count
;
std
::
map
<
int
,
int
>
m_count
;
clock_t
init_time_
;
clock_t
init_time_
;
KnownTimersMap
known_timers_map_
;
static
Profiler
&
instance
()
static
Profiler
&
instance
()
{
{
...
@@ -300,7 +319,7 @@ long Profiler::OutputCommon(CollectiveCommunication& comm, InfoContainer& run_in
...
@@ -300,7 +319,7 @@ long Profiler::OutputCommon(CollectiveCommunication& comm, InfoContainer& run_in
const
DataMap
&
data_map
=
*
ti_it
;
const
DataMap
&
data_map
=
*
ti_it
;
for
(
DataMap
::
const_iterator
it
=
data_map
.
begin
();
it
!=
data_map
.
end
();
++
it
)
{
for
(
DataMap
::
const_iterator
it
=
data_map
.
begin
();
it
!=
data_map
.
end
();
++
it
)
{
long
clock_count
=
GetTiming
(
it
->
second
);
long
clock_count
=
GetTiming
(
it
->
first
,
idx
);
clock_count
=
long
(
comm
.
sum
(
clock_count
)
/
double
(
scale_factor
*
numProce
));
clock_count
=
long
(
comm
.
sum
(
clock_count
)
/
double
(
scale_factor
*
numProce
));
csv
<<
clock_count
<<
"
\t
"
;
csv
<<
clock_count
<<
"
\t
"
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment