Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
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
savoirfairelinux
opendht
Commits
c2fdf6ae
Commit
c2fdf6ae
authored
6 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
dhtnode: show grouped get results, improve duration display
parent
91a81f64
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/utils.h
+12
-0
12 additions, 0 deletions
include/opendht/utils.h
tools/dhtnode.cpp
+13
-12
13 additions, 12 deletions
tools/dhtnode.cpp
with
25 additions
and
12 deletions
include/opendht/utils.h
+
12
−
0
View file @
c2fdf6ae
...
@@ -92,6 +92,18 @@ print_dt(DT d) {
...
@@ -92,6 +92,18 @@ print_dt(DT d) {
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
double
>>
(
d
).
count
();
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
double
>>
(
d
).
count
();
}
}
template
<
class
DT
>
static
std
::
string
print_duration
(
DT
d
)
{
if
(
d
<
std
::
chrono
::
milliseconds
(
1
))
{
return
std
::
to_string
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
double
,
std
::
micro
>>
(
d
).
count
())
+
" us"
;
}
else
if
(
d
<
std
::
chrono
::
seconds
(
1
))
{
return
std
::
to_string
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
double
,
std
::
milli
>>
(
d
).
count
())
+
" ms"
;
}
else
{
return
std
::
to_string
(
print_dt
(
d
))
+
" s"
;
}
}
template
<
typename
Duration
=
duration
>
template
<
typename
Duration
=
duration
>
class
uniform_duration_distribution
:
public
std
::
uniform_int_distribution
<
typename
Duration
::
rep
>
{
class
uniform_duration_distribution
:
public
std
::
uniform_int_distribution
<
typename
Duration
::
rep
>
{
using
Base
=
std
::
uniform_int_distribution
<
typename
Duration
::
rep
>
;
using
Base
=
std
::
uniform_int_distribution
<
typename
Duration
::
rep
>
;
...
...
This diff is collapsed.
Click to expand it.
tools/dhtnode.cpp
+
13
−
12
View file @
c2fdf6ae
...
@@ -308,14 +308,15 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
...
@@ -308,14 +308,15 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
if
(
op
==
"g"
)
{
if
(
op
==
"g"
)
{
std
::
string
rem
;
std
::
string
rem
;
std
::
getline
(
iss
,
rem
);
std
::
getline
(
iss
,
rem
);
dht
->
get
(
id
,
[
start
](
std
::
shared_ptr
<
Value
>
value
)
{
dht
->
get
(
id
,
[
start
](
const
std
::
vector
<
std
::
shared_ptr
<
Value
>
>&
value
s
)
{
auto
now
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
now
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Get: found value (after "
<<
print_dt
(
now
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"Get: found "
<<
values
.
size
()
<<
" value(s) after "
<<
print_duration
(
now
-
start
)
<<
std
::
endl
;
for
(
const
auto
&
value
:
values
)
std
::
cout
<<
"
\t
"
<<
*
value
<<
std
::
endl
;
std
::
cout
<<
"
\t
"
<<
*
value
<<
std
::
endl
;
return
true
;
return
true
;
},
[
start
](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Get: "
<<
(
ok
?
"completed"
:
"failure"
)
<<
"
(
took "
<<
print_d
t
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"Get: "
<<
(
ok
?
"completed"
:
"failure"
)
<<
"
,
took "
<<
print_d
uration
(
end
-
start
)
<<
std
::
endl
;
},
{},
dht
::
Where
{
rem
});
},
{},
dht
::
Where
{
rem
});
}
}
else
if
(
op
==
"q"
)
{
else
if
(
op
==
"q"
)
{
...
@@ -324,13 +325,13 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
...
@@ -324,13 +325,13 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
dht
->
query
(
id
,
[
start
](
const
std
::
vector
<
std
::
shared_ptr
<
FieldValueIndex
>>&
field_value_indexes
)
{
dht
->
query
(
id
,
[
start
](
const
std
::
vector
<
std
::
shared_ptr
<
FieldValueIndex
>>&
field_value_indexes
)
{
auto
now
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
now
=
std
::
chrono
::
high_resolution_clock
::
now
();
for
(
auto
&
index
:
field_value_indexes
)
{
for
(
auto
&
index
:
field_value_indexes
)
{
std
::
cout
<<
"Query: found field value index
(
after "
<<
print_d
t
(
now
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"Query: found field value index after "
<<
print_d
uration
(
now
-
start
)
<<
std
::
endl
;
std
::
cout
<<
"
\t
"
<<
*
index
<<
std
::
endl
;
std
::
cout
<<
"
\t
"
<<
*
index
<<
std
::
endl
;
}
}
return
true
;
return
true
;
},
[
start
](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Query: "
<<
(
ok
?
"completed"
:
"failure"
)
<<
"
(
took "
<<
print_d
t
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"Query: "
<<
(
ok
?
"completed"
:
"failure"
)
<<
"
,
took "
<<
print_d
uration
(
end
-
start
)
<<
std
::
endl
;
},
dht
::
Query
{
rem
});
},
dht
::
Query
{
rem
});
}
}
else
if
(
op
==
"l"
)
{
else
if
(
op
==
"l"
)
{
...
@@ -365,7 +366,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
...
@@ -365,7 +366,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
},
[
start
](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put: "
<<
(
ok
?
"success"
:
"failure"
)
<<
"
(
took "
<<
print_d
t
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"Put: "
<<
(
ok
?
"success"
:
"failure"
)
<<
"
,
took "
<<
print_d
uration
(
end
-
start
)
<<
std
::
endl
;
});
});
}
}
else
if
(
op
==
"pp"
)
{
else
if
(
op
==
"pp"
)
{
...
@@ -378,7 +379,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
...
@@ -378,7 +379,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
dht
->
put
(
id
,
value
,
[
start
,
value
](
bool
ok
)
{
dht
->
put
(
id
,
value
,
[
start
,
value
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
flags
(
std
::
cout
.
flags
());
auto
flags
(
std
::
cout
.
flags
());
std
::
cout
<<
"Put: "
<<
(
ok
?
"success"
:
"failure"
)
<<
"
(
took "
<<
print_d
t
(
end
-
start
)
<<
"
s)
. Value ID: "
<<
std
::
hex
<<
value
->
id
<<
std
::
endl
;
std
::
cout
<<
"Put: "
<<
(
ok
?
"success"
:
"failure"
)
<<
"
,
took "
<<
print_d
uration
(
end
-
start
)
<<
". Value ID: "
<<
std
::
hex
<<
value
->
id
<<
std
::
endl
;
std
::
cout
.
flags
(
flags
);
std
::
cout
.
flags
(
flags
);
},
time_point
::
max
(),
true
);
},
time_point
::
max
(),
true
);
}
}
...
@@ -399,7 +400,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
...
@@ -399,7 +400,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
},
[
start
](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put signed: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_d
t
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"Put signed: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_d
uration
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
});
});
}
}
else
if
(
op
==
"e"
)
{
else
if
(
op
==
"e"
)
{
...
@@ -415,7 +416,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
...
@@ -415,7 +416,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
std
::
vector
<
uint8_t
>
{
v
.
begin
(),
v
.
end
()}
},
[
start
](
bool
ok
)
{
},
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Put encrypted: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_d
t
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"Put encrypted: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_d
uration
(
end
-
start
)
<<
std
::
endl
;
});
});
}
}
else
if
(
op
==
"a"
)
{
else
if
(
op
==
"a"
)
{
...
@@ -423,7 +424,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
...
@@ -423,7 +424,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
iss
>>
port
;
iss
>>
port
;
dht
->
put
(
id
,
dht
::
Value
{
dht
::
IpServiceAnnouncement
::
TYPE
.
id
,
dht
::
IpServiceAnnouncement
(
port
)},
[
start
](
bool
ok
)
{
dht
->
put
(
id
,
dht
::
Value
{
dht
::
IpServiceAnnouncement
::
TYPE
.
id
,
dht
::
IpServiceAnnouncement
(
port
)},
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Announce: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_d
t
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
std
::
cout
<<
"Announce: "
<<
(
ok
?
"success"
:
"failure"
)
<<
" (took "
<<
print_d
uration
(
end
-
start
)
<<
std
::
endl
;
});
});
}
}
#ifdef OPENDHT_INDEXATION
#ifdef OPENDHT_INDEXATION
...
@@ -446,7 +447,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
...
@@ -446,7 +447,7 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, dht_params& params
[
start
](
bool
ok
)
{
[
start
](
bool
ok
)
{
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
std
::
cout
<<
"Pht::lookup: "
<<
(
ok
?
"done."
:
"failed."
)
std
::
cout
<<
"Pht::lookup: "
<<
(
ok
?
"done."
:
"failed."
)
<<
" took "
<<
print_d
t
(
end
-
start
)
<<
"s)"
<<
std
::
endl
;
<<
" took "
<<
print_d
uration
(
end
-
start
)
<<
std
::
endl
;
},
exact_match
.
size
()
!=
0
and
exact_match
==
"false"
?
false
:
true
},
exact_match
.
size
()
!=
0
and
exact_match
==
"false"
?
false
:
true
);
);
...
...
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