Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ademco_hb
Project
Project
Details
Activity
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
captainwong
ademco_hb
Commits
7243969f
Commit
7243969f
authored
Sep 17, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更精确的性能测试
parent
8eec0067
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
29 deletions
+35
-29
bench_client.cpp
examples/bench_client/bench_client.cpp
+27
-23
bench_client.vcxproj.user
examples/bench_client/bench_client.vcxproj.user
+1
-1
bench_client_ex.cpp
examples/bench_client_ex/bench_client_ex.cpp
+3
-2
server_demo_libevent.cpp
examples/server_demo_libevent/server_demo_libevent.cpp
+3
-2
server_demo_libevent_linux.vcxproj.user
...mo_libevent_linux/server_demo_libevent_linux.vcxproj.user
+1
-1
No files found.
examples/bench_client/bench_client.cpp
View file @
7243969f
...
...
@@ -71,8 +71,8 @@ struct Session {
int
id
=
0
;
std
::
string
acct
=
{};
AdemcoId
ademco_id
=
0
;
ADEMCO_EVENT
type
=
EVENT_I_AM_GPRS
;
ADEMCO_EVENT
status
=
EVENT_ARM
;
//
ADEMCO_EVENT type = EVENT_I_AM_GPRS;
//
ADEMCO_EVENT status = EVENT_ARM;
uint16_t
seq
=
0
;
uint16_t
nextSeq
()
{
if
(
++
seq
==
10000
)
{
seq
=
1
;
}
return
seq
;
}
...
...
@@ -106,21 +106,6 @@ void handle_ademco_msg(Session* session, bufferevent* bev)
if
(
print_data
)
{
printf
(
"session #%d recv:%s
\n
"
,
session
->
id
,
session
->
packet
.
toString
().
data
());
}
auto
output
=
bufferevent_get_output
(
bev
);
switch
(
session
->
packet
.
id_
.
eid_
)
{
case
AdemcoMsgId
:
:
id_ack
:
{
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
output
,
buf
,
session
->
lastTimePacketSize
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
encodeTime
+=
us
;
}
break
;
default:
break
;
}
}
void
readcb
(
struct
bufferevent
*
bev
,
void
*
user_data
)
...
...
@@ -131,11 +116,12 @@ void readcb(struct bufferevent* bev, void* user_data)
while
(
1
)
{
size_t
len
=
evbuffer_get_length
(
input
);
if
(
len
<
9
)
{
return
;
}
char
buff
[
1024
]
=
{
0
};
evbuffer_copyout
(
input
,
buff
,
std
::
min
(
len
,
sizeof
(
buff
)));
char
buff
[
4096
]
=
{
0
};
len
=
std
::
min
(
len
,
sizeof
(
buff
));
evbuffer_copyout
(
input
,
buff
,
len
);
size_t
cb_commited
=
0
;
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
auto
res
=
session
->
packet
.
parse
(
buff
,
1024
,
cb_commited
);
auto
res
=
session
->
packet
.
parse
(
buff
,
len
,
cb_commited
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
decodeTime
+=
us
;
bool
done
=
false
;
...
...
@@ -163,9 +149,20 @@ void readcb(struct bufferevent* bev, void* user_data)
void
writecb
(
struct
bufferevent
*
bev
,
void
*
user_data
)
{
auto
session
=
(
Session
*
)
user_data
;
if
(
0
==
evbuffer_get_length
(
bufferevent_get_output
(
bev
)))
{
auto
output
=
bufferevent_get_output
(
bev
);
if
(
0
==
evbuffer_get_length
(
output
))
{
session
->
bytesWritten
+=
session
->
lastTimePacketSize
;
session
->
msgWritten
++
;
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
output
,
buf
,
session
->
lastTimePacketSize
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
encodeTime
+=
us
;
if
(
print_data
)
{
printf
(
"session #%d send:%s
\n
"
,
session
->
id
,
session
->
packet
.
toString
().
data
());
}
}
}
...
...
@@ -194,7 +191,7 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
printf
(
"All connected
\n
"
);
}
}
char
buf
[
1024
];
/*
char buf[1024];
session->lastTimePacketSize = session->packet.make_hb(buf, sizeof(buf),
session->nextSeq(), session->acct, session->ademco_id, 0, session->status, 0);
if (print_data) {
...
...
@@ -205,7 +202,14 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
if (print_data) {
printf("session #%d send:%s\n", session->id, session->packet.toString().data());
}
evbuffer_add(bufferevent_get_output(bev), buf, session->lastTimePacketSize);*/
char
buf
[
1024
];
session
->
lastTimePacketSize
=
session
->
packet
.
make_null
(
buf
,
sizeof
(
buf
),
session
->
nextSeq
(),
session
->
acct
,
session
->
ademco_id
);
evbuffer_add
(
bufferevent_get_output
(
bev
),
buf
,
session
->
lastTimePacketSize
);
if
(
print_data
)
{
printf
(
"session #%d send:%s
\n
"
,
session
->
id
,
session
->
packet
.
toString
().
data
());
}
auto
base
=
bufferevent_get_base
(
bev
);
session
->
timer
=
event_new
(
base
,
-
1
,
EV_TIMEOUT
,
timer_cb
,
session
);
...
...
@@ -251,7 +255,7 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
"Decode average time %.2f us, %.2f packets/s
\n
"
,
totalBytesRead
/
1024.0
/
1024
,
totalMsgRead
,
totalBytesWrite
/
1024.0
/
1024
,
totalMsgWritten
,
(
totalBytesRead
+
totalBytesWrite
)
*
1.0
/
(
totalMsgRead
+
totalMsgWritten
),
totalBytesRead
*
1.0
/
(
timeout
*
1024.0
*
1024
),
totalMsgRead
*
1.0
/
timeout
,
(
totalBytesRead
+
totalBytesWrite
)
*
1.0
/
(
timeout
*
1024.0
*
1024
),
(
totalBytesRead
+
totalBytesWrite
)
*
1.0
/
timeout
,
encodeSpeed
,
1000000.0
/
encodeSpeed
,
decodeSpeed
,
1000000.0
/
decodeSpeed
);
}
...
...
examples/bench_client/bench_client.vcxproj.user
View file @
7243969f
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"Current"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<LocalDebuggerCommandArguments>
192.168.1.
90 12345 1 1 0 30 1
</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>
192.168.1.
166 12345 6 1200 30 0
</LocalDebuggerCommandArguments>
<DebuggerFlavor>
WindowsLocalDebugger
</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
...
...
examples/bench_client_ex/bench_client_ex.cpp
View file @
7243969f
...
...
@@ -139,10 +139,11 @@ void readcb(struct bufferevent* bev, void* user_data)
size_t
len
=
evbuffer_get_length
(
input
);
if
(
len
<
9
)
{
return
;
}
char
buff
[
1024
]
=
{
0
};
evbuffer_copyout
(
input
,
buff
,
std
::
min
(
len
,
sizeof
(
buff
)));
len
=
std
::
min
(
len
,
sizeof
(
buff
));
evbuffer_copyout
(
input
,
buff
,
len
);
size_t
cb_commited
=
0
;
auto
now
=
std
::
chrono
::
steady_clock
::
now
();
auto
res
=
session
->
packet
.
parse
(
buff
,
1024
,
cb_commited
);
auto
res
=
session
->
packet
.
parse
(
buff
,
len
,
cb_commited
);
auto
us
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
now
).
count
();
session
->
decodeTime
+=
us
;
bool
done
=
false
;
...
...
examples/server_demo_libevent/server_demo_libevent.cpp
View file @
7243969f
...
...
@@ -572,9 +572,10 @@ void readcb(struct bufferevent* bev, void* user_data)
size_t
len
=
evbuffer_get_length
(
input
);
if
(
len
<
9
)
{
return
;
}
char
buff
[
1024
]
=
{
0
};
evbuffer_copyout
(
input
,
buff
,
std
::
min
(
len
,
sizeof
(
buff
)));
len
=
std
::
min
(
len
,
sizeof
(
buff
));
evbuffer_copyout
(
input
,
buff
,
len
);
size_t
cb_commited
=
0
;
auto
res
=
context
->
packet
.
parse
(
buff
,
1024
,
cb_commited
);
auto
res
=
context
->
packet
.
parse
(
buff
,
len
,
cb_commited
);
bool
done
=
false
;
switch
(
res
)
{
case
ademco
:
:
ParseResult
::
RESULT_OK
:
...
...
examples/server_demo_libevent_linux/server_demo_libevent_linux.vcxproj.user
View file @
7243969f
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"Current"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<RemoteTarget>
1735438401;www.hbwechatserver.com
(username=, port=22, authentication=Password)
</RemoteTarget>
<RemoteTarget>
-2055866198;192.168.1.166
(username=, port=22, authentication=Password)
</RemoteTarget>
<RemoteDebuggerCommand>
server_demo_libevent_linux
</RemoteDebuggerCommand>
<RemoteDebuggerWorkingDirectory>
/root/vsprojects/server_demo_libevent_linux/examples/server_demo_libevent_linux/bin/x64/Debug
</RemoteDebuggerWorkingDirectory>
<DebuggerFlavor>
LinuxDebugger
</DebuggerFlavor>
...
...
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