Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
0a649e24
Commit
0a649e24
authored
Sep 16, 2013
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Use std::chrono instead of gettimeofday and clock_gettime
parent
04457aae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
76 deletions
+54
-76
src/app_helper.cc
src/app_helper.cc
+8
-31
src/app_helper.h
src/app_helper.h
+12
-3
src/nghttp.cc
src/nghttp.cc
+34
-42
No files found.
src/app_helper.cc
View file @
0a649e24
...
...
@@ -164,11 +164,10 @@ void print_nv(nghttp2_nv *nva, size_t nvlen)
void
print_timer
()
{
timeval
tv
;
get_timer
(
&
tv
);
auto
millis
=
get_timer
();
printf
(
"%s[%3ld.%03ld]%s"
,
ansi_esc
(
"
\033
[33m"
),
(
long
int
)
tv
.
tv_sec
,
tv
.
tv_usec
/
1000
,
(
long
int
)
(
millis
.
count
()
/
1000
),
(
long
int
)(
millis
.
count
()
%
1000
)
,
ansi_escend
());
}
...
...
@@ -438,45 +437,23 @@ int on_data_send_callback
return
0
;
}
int64_t
time_delta
(
const
timeval
&
a
,
const
timeval
&
b
)
{
int64_t
res
=
(
a
.
tv_sec
-
b
.
tv_sec
)
*
1000
;
res
+=
(
a
.
tv_usec
-
b
.
tv_usec
)
/
1000
;
return
res
;
}
namespace
{
timeval
base_tv
;
std
::
chrono
::
steady_clock
::
time_point
base_tv
;
}
// namespace
void
reset_timer
()
{
get_time
(
&
base_tv
);
base_tv
=
std
::
chrono
::
steady_clock
::
now
(
);
}
void
get_timer
(
timeval
*
tv
)
std
::
chrono
::
milliseconds
get_timer
(
)
{
get_time
(
tv
);
tv
->
tv_usec
-=
base_tv
.
tv_usec
;
tv
->
tv_sec
-=
base_tv
.
tv_sec
;
if
(
tv
->
tv_usec
<
0
)
{
tv
->
tv_usec
+=
1000000
;
--
tv
->
tv_sec
;
}
return
time_delta
(
std
::
chrono
::
steady_clock
::
now
(),
base_tv
);
}
int
get_time
(
timeval
*
tv
)
std
::
chrono
::
steady_clock
::
time_point
get_time
(
)
{
int
rv
;
#ifdef HAVE_CLOCK_GETTIME
timespec
ts
;
rv
=
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
tv
->
tv_sec
=
ts
.
tv_sec
;
tv
->
tv_usec
=
ts
.
tv_nsec
/
1000
;
#else // !HAVE_CLOCK_GETTIME
rv
=
gettimeofday
(
tv
,
0
);
#endif // !HAVE_CLOCK_GETTIME
return
rv
;
return
std
::
chrono
::
steady_clock
::
now
();
}
}
// namespace nghttp2
src/app_helper.h
View file @
0a649e24
...
...
@@ -31,7 +31,9 @@
#include <cstdlib>
#include <sys/time.h>
#include <poll.h>
#include <map>
#include <chrono>
#include <nghttp2/nghttp2.h>
...
...
@@ -74,13 +76,20 @@ int on_data_send_callback
// Returns difference between |a| and |b| in milliseconds, assuming
// |a| is more recent than |b|.
int64_t
time_delta
(
const
timeval
&
a
,
const
timeval
&
b
);
template
<
typename
TimePoint
>
std
::
chrono
::
milliseconds
time_delta
(
const
TimePoint
&
a
,
const
TimePoint
&
b
)
{
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
a
-
b
);
}
// Resets timer
void
reset_timer
();
void
get_timer
(
timeval
*
tv
);
// Returns the duration since timer reset.
std
::
chrono
::
milliseconds
get_timer
();
int
get_time
(
timeval
*
tv
);
// Returns current time point.
std
::
chrono
::
steady_clock
::
time_point
get_time
();
void
print_timer
();
...
...
src/nghttp.cc
View file @
0a649e24
...
...
@@ -50,6 +50,7 @@
#include <vector>
#include <sstream>
#include <tuple>
#include <chrono>
#include <openssl/ssl.h>
#include <openssl/err.h>
...
...
@@ -111,28 +112,21 @@ struct Config {
};
}
// namespace
namespace
{
struct
RequestStat
{
timeval
on_syn_stream_time
;
timeval
on_syn_reply_time
;
timeval
on_complete_time
;
RequestStat
()
{
on_syn_stream_time
.
tv_sec
=
-
1
;
on_syn_stream_time
.
tv_usec
=
-
1
;
on_syn_reply_time
.
tv_sec
=
-
1
;
on_syn_reply_time
.
tv_usec
=
-
1
;
on_complete_time
.
tv_sec
=
-
1
;
on_complete_time
.
tv_usec
=
-
1
;
}
enum
StatStage
{
STAT_INITIAL
,
STAT_ON_REQUEST
,
STAT_ON_RESPONSE
,
STAT_ON_COMPLETE
};
}
// namespace
namespace
{
void
record_time
(
timeval
*
tv
)
{
get_time
(
tv
);
}
struct
RequestStat
{
std
::
chrono
::
steady_clock
::
time_point
on_request_time
;
std
::
chrono
::
steady_clock
::
time_point
on_response_time
;
std
::
chrono
::
steady_clock
::
time_point
on_complete_time
;
StatStage
stage
;
RequestStat
()
:
stage
(
STAT_INITIAL
)
{}
};
}
// namespace
namespace
{
...
...
@@ -318,31 +312,29 @@ struct Request {
}
}
void
record_
syn_stream
_time
()
void
record_
request
_time
()
{
record_time
(
&
stat
.
on_syn_stream_time
);
stat
.
stage
=
STAT_ON_REQUEST
;
stat
.
on_request_time
=
get_time
();
}
void
record_
syn_reply
_time
()
void
record_
response
_time
()
{
record_time
(
&
stat
.
on_syn_reply_time
);
stat
.
stage
=
STAT_ON_RESPONSE
;
stat
.
on_response_time
=
get_time
();
}
void
record_complete_time
()
{
record_time
(
&
stat
.
on_complete_time
);
stat
.
stage
=
STAT_ON_COMPLETE
;
stat
.
on_complete_time
=
get_time
();
}
};
}
// namespace
namespace
{
struct
SessionStat
{
timeval
on_handshake_time
;
SessionStat
()
{
on_handshake_time
.
tv_sec
=
-
1
;
on_handshake_time
.
tv_usec
=
-
1
;
}
std
::
chrono
::
steady_clock
::
time_point
on_handshake_time
;
};
}
// namespace
...
...
@@ -821,7 +813,7 @@ struct HttpClient {
}
void
record_handshake_time
()
{
record_time
(
&
stat
.
on_handshake_time
);
stat
.
on_handshake_time
=
get_time
(
);
}
};
}
// namespace
...
...
@@ -1026,7 +1018,7 @@ void check_stream_id(nghttp2_session *session, int32_t stream_id,
stream_id
);
assert
(
req
);
client
->
streams
[
stream_id
]
=
req
;
req
->
record_
syn_stream
_time
();
req
->
record_
request
_time
();
}
}
// namespace
...
...
@@ -1101,7 +1093,7 @@ int on_frame_recv_callback2
// If this is the HTTP Upgrade with OPTIONS method to avoid POST,
// req is nullptr.
if
(
req
)
{
req
->
record_
syn_reply
_time
();
req
->
record_
response
_time
();
}
}
check_response_header
(
session
,
frame
,
user_data
);
...
...
@@ -1141,23 +1133,23 @@ void print_stats(const HttpClient& client)
std
::
cout
<<
" Status: "
<<
req
->
status
<<
std
::
endl
;
std
::
cout
<<
" Delta (ms) from handshake(HEADERS):"
<<
std
::
endl
;
if
(
req
->
stat
.
on_syn_reply_time
.
tv_sec
>=
0
)
{
std
::
cout
<<
"
SYN_REPLY
: "
<<
time_delta
(
req
->
stat
.
on_
syn_reply
_time
,
client
.
stat
.
on_handshake_time
)
if
(
req
->
stat
.
stage
>=
STAT_ON_RESPONSE
)
{
std
::
cout
<<
"
response HEADERS
: "
<<
time_delta
(
req
->
stat
.
on_
response
_time
,
client
.
stat
.
on_handshake_time
)
.
count
()
<<
"("
<<
time_delta
(
req
->
stat
.
on_
syn_reply
_time
,
req
->
stat
.
on_
syn_stream_time
)
<<
time_delta
(
req
->
stat
.
on_
response
_time
,
req
->
stat
.
on_
request_time
).
count
(
)
<<
")"
<<
std
::
endl
;
}
if
(
req
->
stat
.
on_complete_time
.
tv_sec
>=
0
)
{
if
(
req
->
stat
.
stage
>=
STAT_ON_COMPLETE
)
{
std
::
cout
<<
" Completed: "
<<
time_delta
(
req
->
stat
.
on_complete_time
,
client
.
stat
.
on_handshake_time
)
client
.
stat
.
on_handshake_time
)
.
count
()
<<
"("
<<
time_delta
(
req
->
stat
.
on_complete_time
,
req
->
stat
.
on_
syn_stream_time
)
req
->
stat
.
on_
request_time
).
count
(
)
<<
")"
<<
std
::
endl
;
}
...
...
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