Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Gaudi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Gaudi
Gaudi
Merge requests
!1408
Add algorithm to programmatically enable/disable perf
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add algorithm to programmatically enable/disable perf
rmatev/Gaudi:add-PerfProfile
into
master
Overview
11
Commits
1
Pipelines
3
Changes
3
All threads resolved!
Show all comments
Merged
Rosen Matev
requested to merge
rmatev/Gaudi:add-PerfProfile
into
master
2 years ago
Overview
11
Commits
1
Pipelines
3
Changes
3
All threads resolved!
Show all comments
Expand
0
0
Merge request reports
Compare
master
version 2
33bd9a11
2 years ago
version 1
4d1b816d
2 years ago
master (base)
and
latest version
latest version
7c343eaa
1 commit,
2 years ago
version 2
33bd9a11
1 commit,
2 years ago
version 1
4d1b816d
1 commit,
2 years ago
3 files
+
141
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
GaudiProfiling/src/component/perf/PerfProfile.cpp
0 → 100644
+
78
−
0
Options
/***********************************************************************************\
* (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
* *
* This software is distributed under the terms of the Apache version 2 licence, *
* copied verbatim in the file "LICENSE". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\***********************************************************************************/
#include
"GaudiAlg/Consumer.h"
#include
<fcntl.h>
#include
<string_view>
#include
<sys/stat.h>
/** Algorithm to enable/disable profiling with Linux perf at given events.
*
* Needs at least perf 5.9. To control perf record, start it as
*
* perf record -D -1 --control fifo:GaudiPerfProfile.fifo ... gaudirun.py ...
*
* The path to the control fifo (GaudiPerfProfile.fifo) is configurable
* with the FIFOPath property. The fifo must be created before running perf.
*
*/
struct
PerfProfile
final
:
Gaudi
::
Functional
::
Consumer
<
void
()
>
{
using
Consumer
::
Consumer
;
StatusCode
initialize
()
override
{
return
Consumer
::
initialize
().
andThen
(
[
this
]()
{
m_fifo
=
::
open
(
m_fifoPath
.
value
().
c_str
(),
O_WRONLY
|
O_NONBLOCK
);
if
(
m_fifo
==
-
1
)
{
fatal
()
<<
"open(
\"
"
<<
m_fifoPath
.
value
()
<<
"
\"
): "
<<
::
strerror
(
errno
)
<<
endmsg
;
return
StatusCode
::
FAILURE
;
}
return
StatusCode
::
SUCCESS
;
}
);
}
StatusCode
finalize
()
override
{
if
(
m_fifo
!=
-
1
)
{
::
close
(
m_fifo
);
}
return
Consumer
::
finalize
();
}
void
operator
()()
const
override
{
// We could use EventContext::evt(), however it is not always valid, as is the case with EvtSel="NONE". Instead, use
// an atomic counter.
auto
eventNumber
=
m_eventNumber
++
;
if
(
eventNumber
==
m_nStartFromEvent
.
value
()
)
{
warning
()
<<
"Starting perf profile at event "
<<
eventNumber
<<
endmsg
;
fifo_write
(
"enable
\n
"
);
}
if
(
m_nStopAtEvent
>
0
&&
eventNumber
==
m_nStopAtEvent
.
value
()
)
{
warning
()
<<
"Stopping perf profile at event "
<<
eventNumber
<<
endmsg
;
fifo_write
(
"disable
\n
"
);
}
}
private
:
void
fifo_write
(
std
::
string_view
s
)
const
{
if
(
::
write
(
m_fifo
,
s
.
data
(),
s
.
size
()
)
<
ssize_t
(
s
.
size
()
)
)
{
error
()
<<
"Write of
\"
"
<<
s
<<
"
\"
to FIFO failed: "
<<
::
strerror
(
errno
)
<<
endmsg
;
}
}
mutable
std
::
atomic
<
long
unsigned
>
m_eventNumber
=
0
;
int
m_fifo
=
-
1
;
Gaudi
::
Property
<
std
::
string
>
m_fifoPath
{
this
,
"FIFOPath"
,
"GaudiPerfProfile.fifo"
,
"Path to perf control FIFO."
};
Gaudi
::
Property
<
unsigned
long
>
m_nStartFromEvent
{
this
,
"StartFromEventN"
,
1
,
"After what event we start profiling."
};
Gaudi
::
Property
<
unsigned
long
>
m_nStopAtEvent
{
this
,
"StopAtEventN"
,
0
,
"After what event we stop profiling. If 0 than we also profile finalization stage. Default = 0."
};
};
DECLARE_COMPONENT
(
PerfProfile
)
Loading