Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
5407293e
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5407293e
编写于
9月 22, 2018
作者:
G
gruminions
提交者:
fengqikai1414
9月 23, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
framework: optimize history
上级
45a5a674
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
35 deletion
+31
-35
framework/benchmark/transport/intra.cpp
framework/benchmark/transport/intra.cpp
+21
-21
framework/cybertron/transport/message/history.h
framework/cybertron/transport/message/history.h
+10
-14
未找到文件。
framework/benchmark/transport/intra.cpp
浏览文件 @
5407293e
...
@@ -19,11 +19,11 @@ using namespace apollo::cybertron::proto;
...
@@ -19,11 +19,11 @@ using namespace apollo::cybertron::proto;
struct
RunConfig
{
struct
RunConfig
{
RunConfig
()
RunConfig
()
:
msg_size
(
1000
),
msg_num
(
1000
),
sleep_us
(
10000
),
lower_reach
_num
(
1
)
{}
:
msg_size
(
1000
),
msg_num
(
1000
),
sleep_us
(
10000
),
receiver
_num
(
1
)
{}
int
msg_size
;
int
msg_size
;
int
msg_num
;
int
msg_num
;
int
sleep_us
;
int
sleep_us
;
int
lower_reach
_num
;
int
receiver
_num
;
};
};
struct
RunStatistic
{
struct
RunStatistic
{
...
@@ -38,9 +38,9 @@ struct RunStatistic {
...
@@ -38,9 +38,9 @@ struct RunStatistic {
uint64_t
total_latency
;
uint64_t
total_latency
;
};
};
const
int
MAX_
LOWER_REACH
_NUM
=
10
;
const
int
MAX_
RECEIVER
_NUM
=
10
;
std
::
shared_ptr
<
LowerReach
<
RawMessage
>>
lower_reach
[
MAX_LOWER_REACH
_NUM
];
std
::
shared_ptr
<
Receiver
<
RawMessage
>>
receiver
[
MAX_RECEIVER
_NUM
];
RunStatistic
statistic
[
MAX_
LOWER_REACH
_NUM
];
RunStatistic
statistic
[
MAX_
RECEIVER
_NUM
];
bool
Fill
(
std
::
string
*
dst
)
{
bool
Fill
(
std
::
string
*
dst
)
{
if
(
dst
==
nullptr
)
{
if
(
dst
==
nullptr
)
{
...
@@ -93,10 +93,10 @@ bool Init(char* argv[], RunConfig* cfg) {
...
@@ -93,10 +93,10 @@ bool Init(char* argv[], RunConfig* cfg) {
}
}
tmp
=
atoi
(
argv
[
4
]);
tmp
=
atoi
(
argv
[
4
]);
if
(
tmp
<
1
||
tmp
>
MAX_
LOWER_REACH
_NUM
)
{
if
(
tmp
<
1
||
tmp
>
MAX_
RECEIVER
_NUM
)
{
return
false
;
return
false
;
}
else
{
}
else
{
cfg
->
lower_reach
_num
=
tmp
;
cfg
->
receiver
_num
=
tmp
;
}
}
return
true
;
return
true
;
...
@@ -110,8 +110,8 @@ int main(int argc, char* argv[]) {
...
@@ -110,8 +110,8 @@ int main(int argc, char* argv[]) {
std
::
cout
<<
" argv[2] message transmit number"
<<
std
::
endl
;
std
::
cout
<<
" argv[2] message transmit number"
<<
std
::
endl
;
std
::
cout
<<
" argv[3] message transmit frequency(Hz, 0 means max)"
std
::
cout
<<
" argv[3] message transmit frequency(Hz, 0 means max)"
<<
std
::
endl
;
<<
std
::
endl
;
std
::
cout
<<
" argv[4]
lower_reach number(1~"
<<
MAX_LOWER_REACH_NUM
std
::
cout
<<
" argv[4]
receiver number(1~"
<<
MAX_RECEIVER_NUM
<<
")"
<<
")"
<<
std
::
endl
;
<<
std
::
endl
;
return
0
;
return
0
;
}
}
...
@@ -125,25 +125,25 @@ int main(int argc, char* argv[]) {
...
@@ -125,25 +125,25 @@ int main(int argc, char* argv[]) {
std
::
cout
<<
" message size: "
<<
cfg
.
msg_size
<<
std
::
endl
;
std
::
cout
<<
" message size: "
<<
cfg
.
msg_size
<<
std
::
endl
;
std
::
cout
<<
" transmit num: "
<<
cfg
.
msg_num
<<
std
::
endl
;
std
::
cout
<<
" transmit num: "
<<
cfg
.
msg_num
<<
std
::
endl
;
std
::
cout
<<
" interval (us): "
<<
cfg
.
sleep_us
<<
std
::
endl
;
std
::
cout
<<
" interval (us): "
<<
cfg
.
sleep_us
<<
std
::
endl
;
std
::
cout
<<
"
lower_reach num: "
<<
cfg
.
lower_reach
_num
<<
std
::
endl
;
std
::
cout
<<
"
receiver num: "
<<
cfg
.
receiver
_num
<<
std
::
endl
;
RoleAttributes
attr
;
RoleAttributes
attr
;
attr
.
set_channel_name
(
"channel"
);
attr
.
set_channel_name
(
"channel"
);
// create
upper_reach
// create
transmitter
std
::
shared_ptr
<
apollo
::
cybertron
::
transport
::
UpperReach
<
RawMessage
>>
std
::
shared_ptr
<
apollo
::
cybertron
::
transport
::
Transmitter
<
RawMessage
>>
upper_reach
;
transmitter
;
try
{
try
{
upper_reach
=
transmitter
=
Transport
::
Create
UpperReach
<
RawMessage
>
(
attr
,
OptionalMode
::
INTRA
);
Transport
::
Create
Transmitter
<
RawMessage
>
(
attr
,
OptionalMode
::
INTRA
);
}
catch
(...)
{
}
catch
(...)
{
return
-
1
;
return
-
1
;
}
}
// create
lower_reach
// create
receiver
for
(
int
i
=
0
;
i
<
cfg
.
lower_reach
_num
;
++
i
)
{
for
(
int
i
=
0
;
i
<
cfg
.
receiver
_num
;
++
i
)
{
try
{
try
{
lower_reach
[
i
]
=
Transport
::
CreateLowerReach
<
RawMessage
>
(
receiver
[
i
]
=
Transport
::
CreateReceiver
<
RawMessage
>
(
attr
,
attr
,
[
i
](
const
std
::
shared_ptr
<
RawMessage
>&
msg
,
[
i
](
const
std
::
shared_ptr
<
RawMessage
>&
msg
,
const
MessageInfo
&
msg_info
,
const
RoleAttributes
&
attr
)
{
const
MessageInfo
&
msg_info
,
const
RoleAttributes
&
attr
)
{
...
@@ -170,7 +170,7 @@ int main(int argc, char* argv[]) {
...
@@ -170,7 +170,7 @@ int main(int argc, char* argv[]) {
// transmit msg
// transmit msg
for
(
int
i
=
0
;
i
<
cfg
.
msg_num
;
++
i
)
{
for
(
int
i
=
0
;
i
<
cfg
.
msg_num
;
++
i
)
{
Fill
(
&
msg
->
message
);
Fill
(
&
msg
->
message
);
upper_reach
->
Transmit
(
msg
);
transmitter
->
Transmit
(
msg
);
usleep
(
cfg
.
sleep_us
);
usleep
(
cfg
.
sleep_us
);
static
int
last_percent
=
0
;
static
int
last_percent
=
0
;
...
@@ -189,8 +189,8 @@ int main(int argc, char* argv[]) {
...
@@ -189,8 +189,8 @@ int main(int argc, char* argv[]) {
RunStatistic
total
;
RunStatistic
total
;
// show result
// show result
for
(
int
i
=
0
;
i
<
cfg
.
lower_reach
_num
;
++
i
)
{
for
(
int
i
=
0
;
i
<
cfg
.
receiver
_num
;
++
i
)
{
std
::
cout
<<
"
lower_reach
["
<<
i
<<
"]"
<<
std
::
endl
;
std
::
cout
<<
"
receiver
["
<<
i
<<
"]"
<<
std
::
endl
;
std
::
cout
<<
" recv num: "
<<
statistic
[
i
].
recv_num
<<
std
::
endl
;
std
::
cout
<<
" recv num: "
<<
statistic
[
i
].
recv_num
<<
std
::
endl
;
std
::
cout
<<
" min latency(ns): "
<<
statistic
[
i
].
min_latency
<<
std
::
endl
;
std
::
cout
<<
" min latency(ns): "
<<
statistic
[
i
].
min_latency
<<
std
::
endl
;
std
::
cout
<<
" max latency(ns): "
<<
statistic
[
i
].
max_latency
<<
std
::
endl
;
std
::
cout
<<
" max latency(ns): "
<<
statistic
[
i
].
max_latency
<<
std
::
endl
;
...
...
framework/cybertron/transport/message/history.h
浏览文件 @
5407293e
...
@@ -18,9 +18,9 @@
...
@@ -18,9 +18,9 @@
#define CYBERTRON_TRANSPORT_MESSAGE_HISTORY_H_
#define CYBERTRON_TRANSPORT_MESSAGE_HISTORY_H_
#include <cstdint>
#include <cstdint>
#include <list>
#include <memory>
#include <memory>
#include <mutex>
#include <mutex>
#include <queue>
#include <vector>
#include <vector>
#include "cybertron/common/global_data.h"
#include "cybertron/common/global_data.h"
...
@@ -63,7 +63,7 @@ class History {
...
@@ -63,7 +63,7 @@ class History {
uint32_t
depth_
;
uint32_t
depth_
;
uint32_t
max_depth_
;
uint32_t
max_depth_
;
bool
is_full_
;
bool
is_full_
;
std
::
queue
<
CachedMessage
>
msgs_
;
std
::
list
<
CachedMessage
>
msgs_
;
std
::
mutex
msgs_mutex_
;
std
::
mutex
msgs_mutex_
;
};
};
...
@@ -100,10 +100,10 @@ void History<MessageT>::Add(const MessagePtr& msg,
...
@@ -100,10 +100,10 @@ void History<MessageT>::Add(const MessagePtr& msg,
}
}
std
::
lock_guard
<
std
::
mutex
>
lock
(
msgs_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
msgs_mutex_
);
if
(
is_full_
)
{
if
(
is_full_
)
{
msgs_
.
pop
();
msgs_
.
pop
_front
();
}
}
msgs_
.
emplace
(
msg
,
msg_info
);
msgs_
.
emplace
_back
(
msg
,
msg_info
);
if
(
!
is_full_
)
{
if
(
!
is_full_
)
{
if
(
msgs_
.
size
()
==
depth_
)
{
if
(
msgs_
.
size
()
==
depth_
)
{
...
@@ -115,9 +115,7 @@ void History<MessageT>::Add(const MessagePtr& msg,
...
@@ -115,9 +115,7 @@ void History<MessageT>::Add(const MessagePtr& msg,
template
<
typename
MessageT
>
template
<
typename
MessageT
>
void
History
<
MessageT
>::
Clear
()
{
void
History
<
MessageT
>::
Clear
()
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
msgs_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
msgs_mutex_
);
while
(
!
msgs_
.
empty
())
{
msgs_
.
clear
();
msgs_
.
pop
();
}
}
}
template
<
typename
MessageT
>
template
<
typename
MessageT
>
...
@@ -125,15 +123,13 @@ void History<MessageT>::GetCachedMessage(std::vector<CachedMessage>* msgs) {
...
@@ -125,15 +123,13 @@ void History<MessageT>::GetCachedMessage(std::vector<CachedMessage>* msgs) {
if
(
msgs
==
nullptr
)
{
if
(
msgs
==
nullptr
)
{
return
;
return
;
}
}
std
::
queue
<
CachedMessage
>
local_msgs
;
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
msgs_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
msgs_mutex_
);
local_msgs
=
msgs_
;
msgs
->
reserve
(
msgs_
.
size
());
}
for
(
auto
&
item
:
msgs_
)
{
msgs
->
emplace_back
(
item
);
while
(
!
local_msgs
.
empty
())
{
}
msgs
->
emplace_back
(
local_msgs
.
front
());
local_msgs
.
pop
();
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录