Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Fischer
emper
Commits
d7a79bdd
Commit
d7a79bdd
authored
3 years ago
by
Florian Fischer
Browse files
Options
Downloads
Patches
Plain Diff
do not parallelize searching and use smaller buffers
parent
6befa43b
No related branches found
No related tags found
No related merge requests found
Pipeline
#80388
failed
3 years ago
Stage: smoke-test
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/fsearch/fsearch.cpp
+5
-33
5 additions, 33 deletions
apps/fsearch/fsearch.cpp
with
5 additions
and
33 deletions
apps/fsearch/fsearch.cpp
+
5
−
33
View file @
d7a79bdd
...
...
@@ -3,7 +3,6 @@
#include
<fcntl.h>
#include
<unistd.h>
#include
<array>
#include
<atomic>
#include
<boost/program_options.hpp>
#include
<cstdlib>
...
...
@@ -26,7 +25,6 @@
namespace
fs
=
std
::
filesystem
;
namespace
po
=
boost
::
program_options
;
#define EMPER_READ_BUFSIZE 65536
#define EMPER_SEARCH_BUFSIZE 4096
static
const
char
*
needle
;
...
...
@@ -37,17 +35,11 @@ static emper::Semaphore* max_open;
static
emper
::
lib
::
ShardedFileBuffer
*
outBuf
;
void
searchPart
(
const
char
*
buf
,
size_t
len
,
std
::
atomic
<
bool
>*
found
)
{
if
(
found
->
load
(
std
::
memory_order_consume
))
return
;
if
(
memmem
(
buf
,
len
,
needle
,
needle_len
))
found
->
store
(
true
,
std
::
memory_order_release
);
}
// NOLINTNEXTLINE(clang-diagnostic-unknown-attributes)
emper_fibril
void
search
(
const
std
::
string
&
path
)
{
emper
::
io
::
RegisteredFile
file
;
auto
*
buf
=
new
std
::
array
<
char
,
EMPER_
R
EA
D
_BUFSIZE
>
;
char
buf
[
EMPER_
S
EA
RCH
_BUFSIZE
]
;
emper
::
io
::
OpenFuture
openFuture
(
file
,
path
.
c_str
(),
O_RDONLY
);
int
res
=
openFuture
.
submitAndWait
();
...
...
@@ -55,7 +47,7 @@ emper_fibril void search(const std::string& path) {
DIE_MSG
(
"opening "
<<
path
<<
" failed:"
<<
strerror
(
-
res
));
}
emper
::
io
::
ReadFuture
readFuture
(
file
,
buf
->
data
(),
buf
->
size
(
),
0
);
emper
::
io
::
ReadFuture
readFuture
(
file
,
buf
,
sizeof
(
buf
),
0
);
// readFuture.setDependency(openFuture);
int
bytes_read
=
readFuture
.
submitAndWait
();
...
...
@@ -68,29 +60,12 @@ emper_fibril void search(const std::string& path) {
// }
while
(
bytes_read
>
0
)
{
// Parallel searching
std
::
atomic
<
bool
>
found
=
false
;
{
const
size_t
parts
=
bytes_read
/
EMPER_SEARCH_BUFSIZE
+
1
;
Fibril
fibril
;
for
(
size_t
i
=
0
;
i
<
parts
;
++
i
)
{
const
size_t
partBegin
=
i
*
EMPER_SEARCH_BUFSIZE
;
const
char
*
partBuf
=
&
(
*
buf
)[
partBegin
];
const
size_t
partLen
=
(
i
<
parts
-
1
)
?
EMPER_SEARCH_BUFSIZE
:
bytes_read
-
partBegin
;
fibril
.
spawn
(
searchPart
,
partBuf
,
partLen
,
&
found
);
}
// The fibril is implicitly joined when dropped
}
if
(
found
.
load
(
std
::
memory_order_acquire
))
{
if
(
memmem
(
buf
,
bytes_read
,
needle
,
needle_len
))
{
outBuf
->
getStream
()
<<
path
<<
std
::
endl
;
goto
out
;
return
;
}
emper
::
io
::
ReadFuture
readFuture
(
file
,
buf
->
data
(),
buf
->
size
(
),
-
1
);
emper
::
io
::
ReadFuture
readFuture
(
file
,
buf
,
sizeof
(
buf
),
-
1
);
bytes_read
=
readFuture
.
submitAndWait
();
}
...
...
@@ -98,9 +73,6 @@ emper_fibril void search(const std::string& path) {
DIE_MSG
(
"read of "
<<
path
<<
" failed: "
<<
strerror
(
-
bytes_read
));
}
out
:
delete
buf
;
// We do not need to close registered files they are closed automatically if a
// new file is registered at their slot.
// And the slot is returned when the RegisteredFile is dropped.
...
...
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