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
Commits
a018d4bb
Commit
a018d4bb
authored
2 years ago
by
Christopher Rob Jones
Browse files
Options
Downloads
Patches
Plain Diff
ProcStats: Attempt to reconnection to process proc stat when information appeats corrupted
parent
e321a6ae
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GaudiAud/src/ProcStats.cpp
+12
-9
12 additions, 9 deletions
GaudiAud/src/ProcStats.cpp
GaudiAud/src/ProcStats.h
+19
-11
19 additions, 11 deletions
GaudiAud/src/ProcStats.h
with
31 additions
and
20 deletions
GaudiAud/src/ProcStats.cpp
+
12
−
9
View file @
a018d4bb
...
@@ -30,10 +30,6 @@
...
@@ -30,10 +30,6 @@
# endif // __linux__
# endif // __linux__
# include <cstdio>
# include <cstdio>
using
std
::
cerr
;
using
std
::
cout
;
using
std
::
endl
;
/* Format of the Linux proc/stat (man 5 proc, kernel 2.6.35):
/* Format of the Linux proc/stat (man 5 proc, kernel 2.6.35):
pid %d The process ID.
pid %d The process ID.
...
@@ -245,17 +241,19 @@ ProcStats* ProcStats::instance() {
...
@@ -245,17 +241,19 @@ ProcStats* ProcStats::instance() {
return
&
inst
;
return
&
inst
;
}
}
ProcStats
::
ProcStats
()
{
void
ProcStats
::
open_ufd
()
{
m_valid
=
false
;
#if defined( __linux__ ) or defined( __APPLE__ )
#if defined( __linux__ ) or defined( __APPLE__ )
m_ufd
.
close
();
m_pg_size
=
sysconf
(
_SC_PAGESIZE
);
// getpagesize();
m_pg_size
=
sysconf
(
_SC_PAGESIZE
);
// getpagesize();
const
auto
fname
=
"/proc/"
+
std
::
to_string
(
getpid
()
)
+
"/stat"
;
const
auto
fname
=
"/proc/"
+
std
::
to_string
(
getpid
()
)
+
"/stat"
;
m_ufd
.
open
(
fname
.
c_str
(),
O_RDONLY
);
m_ufd
.
open
(
fname
.
c_str
(),
O_RDONLY
);
if
(
!
m_ufd
)
{
if
(
!
m_ufd
)
{
cerr
<<
"Failed to open "
<<
fname
<<
endl
;
std
::
cerr
<<
"ProcStats : Failed to open "
<<
fname
<<
std
::
endl
;
return
;
}
else
{
m_valid
=
true
;
}
}
#endif // __linux__ or __APPLE__
#endif // __linux__ or __APPLE__
m_valid
=
true
;
}
}
bool
ProcStats
::
fetch
(
procInfo
&
f
)
{
bool
ProcStats
::
fetch
(
procInfo
&
f
)
{
...
@@ -273,7 +271,7 @@ bool ProcStats::fetch( procInfo& f ) {
...
@@ -273,7 +271,7 @@ bool ProcStats::fetch( procInfo& f ) {
m_ufd
.
lseek
(
0
,
SEEK_SET
);
m_ufd
.
lseek
(
0
,
SEEK_SET
);
if
(
(
cnt
=
m_ufd
.
read
(
buf
,
sizeof
(
buf
)
)
)
<
0
)
{
if
(
(
cnt
=
m_ufd
.
read
(
buf
,
sizeof
(
buf
)
)
)
<
0
)
{
cout
<<
"
LINUX Read of Proc file failed:"
<<
endl
;
std
::
cerr
<<
"ProcStats :
LINUX Read of Proc file failed:"
<<
std
::
endl
;
return
false
;
return
false
;
}
}
...
@@ -298,6 +296,11 @@ bool ProcStats::fetch( procInfo& f ) {
...
@@ -298,6 +296,11 @@ bool ProcStats::fetch( procInfo& f ) {
f
.
vsize
=
pr_size
/
(
1024
*
1024
);
f
.
vsize
=
pr_size
/
(
1024
*
1024
);
f
.
rss
=
pr_rssize
*
m_pg_size
/
(
1024
*
1024
);
f
.
rss
=
pr_rssize
*
m_pg_size
/
(
1024
*
1024
);
if
(
0
==
pinfo
.
vsize
)
{
std
::
cerr
<<
"ProcStats : 0==vsize -> Will try reopening process proc stats"
<<
std
::
endl
;
open_ufd
();
}
}
}
#else
#else
...
...
This diff is collapsed.
Click to expand it.
GaudiAud/src/ProcStats.h
+
19
−
11
View file @
a018d4bb
...
@@ -51,41 +51,49 @@ struct procInfo {
...
@@ -51,41 +51,49 @@ struct procInfo {
};
};
class
ProcStats
{
class
ProcStats
{
public:
public:
static
ProcStats
*
instance
();
ProcStats
()
{
open_ufd
();
}
private
:
void
open_ufd
();
bool
fetch
(
procInfo
&
fill_me
);
public
:
auto
pageSize
()
const
noexcept
{
return
m_pg_size
;
}
static
ProcStats
*
instance
();
ProcStats
();
bool
fetch
(
procInfo
&
fill_me
);
auto
pageSize
()
const
noexcept
{
return
m_pg_size
;
}
private
:
private
:
class
unique_fd
{
class
unique_fd
{
private:
private:
int
m_fd
{
-
1
};
int
m_fd
{
-
1
};
private
:
unique_fd
(
const
unique_fd
&
)
=
delete
;
unique_fd
(
const
unique_fd
&
)
=
delete
;
unique_fd
&
operator
=
(
const
unique_fd
&
)
=
delete
;
unique_fd
&
operator
=
(
const
unique_fd
&
)
=
delete
;
public
:
public
:
unique_fd
(
int
fd
=
-
1
)
:
m_fd
(
fd
)
{}
unique_fd
(
const
int
fd
=
-
1
)
:
m_fd
(
fd
)
{}
unique_fd
(
unique_fd
&&
other
)
{
unique_fd
(
unique_fd
&&
other
)
{
m_fd
=
other
.
m_fd
;
m_fd
=
other
.
m_fd
;
other
.
m_fd
=
-
1
;
other
.
m_fd
=
-
1
;
}
}
~
unique_fd
()
{
~
unique_fd
()
{
close
();
}
if
(
m_fd
!=
-
1
)
{
::
close
(
m_fd
);
}
}
public
:
explicit
operator
bool
()
const
{
return
m_fd
!=
-
1
;
}
explicit
operator
bool
()
const
{
return
m_fd
!=
-
1
;
}
template
<
typename
...
Args
>
template
<
typename
...
Args
>
unique_fd
&
open
(
Args
&&
...
args
)
{
unique_fd
&
open
(
Args
&&
...
args
)
{
m_fd
=
::
open
(
std
::
forward
<
Args
>
(
args
)...
);
m_fd
=
::
open
(
std
::
forward
<
Args
>
(
args
)...
);
return
*
this
;
return
*
this
;
}
}
int
close
()
{
int
close
()
{
auto
r
=
::
close
(
m_fd
);
int
r
=
0
;
m_fd
=
-
1
;
if
(
m_fd
!=
-
1
)
{
r
=
::
close
(
m_fd
);
m_fd
=
-
1
;
}
return
r
;
return
r
;
}
}
...
...
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