Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
a6addb70
Unverified
Commit
a6addb70
authored
4 years ago
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check for memory usage
parent
d5a8bdb2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
19 deletions
+42
-19
Log.h
Log.h
+10
-0
VERSION
VERSION
+1
-1
common.h
common.h
+31
-18
No files found.
Log.h
View file @
a6addb70
...
...
@@ -81,9 +81,19 @@ static uint64_t __COUNT__ = 0; \
__COUNT__++; \
if (__COUNT__ % 1000 == 0) { \
spdlog::info(string(__FUNCTION__) + " processed " + to_string(__COUNT__) + " requests"); \
struct sysinfo memInfo; \
sysinfo (&memInfo); \
long long totalPhysMem = memInfo.totalram; \
/*Multiply in next statement to avoid int overflow on right hand side...*/
\
totalPhysMem *= memInfo.mem_unit; \
int usedByCurrentProcess = getValue(); \
if ( 0.9 * totalPhysMem < usedByCurrentProcess ) { \
exit(-103); \
} \
}
// if uknown error, the error is 10000 + line number
...
...
This diff is collapsed.
Click to expand it.
VERSION
View file @
a6addb70
1.
66.1
1.
70.0
This diff is collapsed.
Click to expand it.
common.h
View file @
a6addb70
...
...
@@ -31,6 +31,11 @@ using namespace std;
#include <iostream>
#include <map>
#include <memory>
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <string.h>
#include <vector>
#include <boost/throw_exception.hpp>
...
...
@@ -69,6 +74,32 @@ inline void print_stack() {
exit
(
-
1
);
}
inline
int
parseLine
(
char
*
line
)
{
// This assumes that a digit will be found and the line ends in " Kb".
int
i
=
strlen
(
line
);
const
char
*
p
=
line
;
while
(
*
p
<
'0'
||
*
p
>
'9'
)
p
++
;
line
[
i
-
3
]
=
'\0'
;
i
=
atoi
(
p
);
return
i
;
}
inline
int
getValue
()
{
//Note: this value is in KB!
FILE
*
file
=
fopen
(
"/proc/self/status"
,
"r"
);
int
result
=
-
1
;
char
line
[
128
];
while
(
fgets
(
line
,
128
,
file
)
!=
NULL
){
if
(
strncmp
(
line
,
"VmRSS:"
,
6
)
==
0
){
result
=
parseLine
(
line
);
break
;
}
}
fclose
(
file
);
return
result
;
}
#define CHECK_STATE(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
...
...
@@ -126,23 +157,5 @@ extern uint64_t initTime;
#define WRITE_LOCK(__X__) std::unique_lock<std::shared_timed_mutex> __LOCK__(__X__);
#include <boost/interprocess/sync/interprocess_semaphore.hpp>
// max of 200 threads can call enclave at a time
extern
boost
::
interprocess
::
interprocess_semaphore
enclaveSemaphore
;
class
semaphore_guard
{
boost
::
interprocess
::
interprocess_semaphore
&
sem
;
public
:
semaphore_guard
(
boost
::
interprocess
::
interprocess_semaphore
&
_semaphore
)
:
sem
(
_semaphore
)
{
sem
.
wait
();
}
~
semaphore_guard
()
{
sem
.
post
();
}
};
#endif //SGXWALLET_COMMON_H
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment