Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cellframe-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
20
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cellframe
cellframe-sdk
Commits
08fb3148
Commit
08fb3148
authored
5 years ago
by
dmitriy.gerasimov
Browse files
Options
Downloads
Patches
Plain Diff
[+] "net stats tx" command thats shows total TX count for selected period and calcs TPS
parent
b98f60cf
No related branches found
Branches containing commit
No related tags found
1 merge request
!24
Support 3689
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dap_chain_net.c
+61
-5
61 additions, 5 deletions
dap_chain_net.c
with
61 additions
and
5 deletions
dap_chain_net.c
+
61
−
5
View file @
08fb3148
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include
<time.h>
#include
<stddef.h>
#include
<stddef.h>
#include
<string.h>
#include
<string.h>
#include
<pthread.h>
#include
<pthread.h>
...
@@ -56,6 +55,11 @@
...
@@ -56,6 +55,11 @@
#include
<sys/types.h>
#include
<sys/types.h>
#include
<dirent.h>
#include
<dirent.h>
#define _XOPEN_SOURCE
/* See feature_test_macros(7) */
#define __USE_XOPEN
#define _GNU_SOURCE
#include
<time.h>
#define LOG_TAG "chain_net"
#define LOG_TAG "chain_net"
/**
/**
...
@@ -608,6 +612,8 @@ int dap_chain_net_init()
...
@@ -608,6 +612,8 @@ int dap_chain_net_init()
"
\t
Find and establish links and stay online
\n
"
"
\t
Find and establish links and stay online
\n
"
"net -net <chain net name> get status
\n
"
"net -net <chain net name> get status
\n
"
"
\t
Look at current status
\n
"
"
\t
Look at current status
\n
"
"net -net <chain net name> stats tx [-from <From time>] [-to <To time>] [-prev_secs <Seconds>]
\n
"
"
\t
Transactions statistics. Time format is <Year>-<Month>-<Day>_<Hours>:<Minutes>:<Seconds> or just <Seconds>
\n
"
"net -net <chain net name> sync < all | gdb | chains >
\n
"
"net -net <chain net name> sync < all | gdb | chains >
\n
"
"
\t
Syncronyze gdb, chains or everything
\n\n
"
"
\t
Syncronyze gdb, chains or everything
\n\n
"
"net -net <chain net name> link < list | add | del | info | establish >
\n
"
"net -net <chain net name> link < list | add | del | info | establish >
\n
"
...
@@ -632,6 +638,7 @@ static int s_cli_net(int argc, const char ** argv, char **a_str_reply)
...
@@ -632,6 +638,7 @@ static int s_cli_net(int argc, const char ** argv, char **a_str_reply)
{
{
int
arg_index
=
1
;
int
arg_index
=
1
;
dap_chain_net_t
*
l_net
;
dap_chain_net_t
*
l_net
;
int
ret
=
dap_chain_node_cli_cmd_values_parse_net_chain
(
&
arg_index
,
argc
,
argv
,
a_str_reply
,
NULL
,
&
l_net
);
int
ret
=
dap_chain_node_cli_cmd_values_parse_net_chain
(
&
arg_index
,
argc
,
argv
,
a_str_reply
,
NULL
,
&
l_net
);
if
(
l_net
){
if
(
l_net
){
const
char
*
l_sync_str
=
NULL
;
const
char
*
l_sync_str
=
NULL
;
...
@@ -646,20 +653,69 @@ static int s_cli_net(int argc, const char ** argv, char **a_str_reply)
...
@@ -646,20 +653,69 @@ static int s_cli_net(int argc, const char ** argv, char **a_str_reply)
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"stats"
,
&
l_stats_str
);
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"stats"
,
&
l_stats_str
);
if
(
l_stats_str
){
if
(
l_stats_str
){
if
(
strcmp
(
l_stats_str
,
"t
ps
"
)
==
0
)
{
if
(
strcmp
(
l_stats_str
,
"t
x
"
)
==
0
)
{
const
char
*
l_to_str
=
NULL
;
const
char
*
l_to_str
=
NULL
;
struct
tm
l_to_tm
=
{
0
};
struct
tm
l_to_tm
=
{
0
};
const
char
*
l_from_str
=
NULL
;
const
char
*
l_from_str
=
NULL
;
struct
tm
l_from_tm
=
{
0
};
struct
tm
l_from_tm
=
{
0
};
const
char
*
l_prev_sec_str
=
NULL
;
time_t
l_prev_sec_ts
;
const
char
c_time_fmt
[]
=
"%Y-%m-%d_%H:%M:%S"
;
// Read from/to time
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"-from "
,
&
l_from_str
);
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"-from "
,
&
l_from_str
);
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"-to"
,
&
l_to_str
);
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"-to"
,
&
l_to_str
);
dap_chain_node_cli_find_option_val
(
argv
,
arg_index
,
argc
,
"-prev_sec"
,
&
l_prev_sec_str
);
if
(
l_from_str
){
if
(
l_from_str
){
//strptime()
strptime
(
l_from_str
,
c_time_fmt
,
&
l_from_tm
);
}
if
(
l_to_str
){
strptime
(
l_to_str
,
c_time_fmt
,
&
l_to_tm
);
}
}
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Network
\"
%s
\"
go from state %s to %s"
);
if
(
l_to_str
==
NULL
){
// If not set '-to' - we set up current time
time_t
l_ts_now
=
time
(
NULL
);
localtime_r
(
&
l_ts_now
,
&
l_to_tm
);
}
if
(
l_prev_sec_str
){
time_t
l_ts_now
=
time
(
NULL
);
l_ts_now
-=
strtol
(
l_prev_sec_str
,
NULL
,
10
);
localtime_r
(
&
l_ts_now
,
&
l_from_tm
);
}
else
if
(
l_from_str
==
NULL
){
// If not set '-from' we set up current time minus 10 seconds
time_t
l_ts_now
=
time
(
NULL
);
l_ts_now
-=
10
;
localtime_r
(
&
l_ts_now
,
&
l_from_tm
);
}
// Form timestamps from/to
time_t
l_from_ts
=
mktime
(
&
l_from_tm
);
time_t
l_to_ts
=
mktime
(
&
l_to_tm
);
// Produce strings
char
l_from_str_new
[
50
];
char
l_to_str_new
[
50
];
strftime
(
l_from_str_new
,
sizeof
(
l_from_str_new
),
c_time_fmt
,
&
l_from_tm
);
strftime
(
l_to_str_new
,
sizeof
(
l_to_str_new
),
c_time_fmt
,
&
l_to_tm
);
dap_string_t
*
l_ret_str
=
dap_string_new
(
"Transactions statistics:
\n
"
);
dap_string_append_printf
(
l_ret_str
,
"
\t
From: %s
\t
To: %s
\n
"
,
l_from_str_new
,
l_to_str_new
);
log_it
(
L_INFO
,
"Calc TPS from %s to %s"
,
l_from_str_new
,
l_to_str_new
);
uint64_t
l_tx_count
=
dap_chain_ledger_count_from_to
(
l_net
->
pub
.
ledger
,
l_from_ts
,
l_to_ts
);
long
double
l_tps
=
l_to_ts
==
l_from_ts
?
0
:
(
long
double
)
l_tx_count
/
(
long
double
)
(
l_to_ts
-
l_from_ts
);
dap_string_append_printf
(
l_ret_str
,
"
\t
Speed: %.3Lf TPS
\n
"
,
l_tps
);
dap_string_append_printf
(
l_ret_str
,
"
\t
Total: %llu
\n
"
,
l_tx_count
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
l_ret_str
->
str
);
dap_string_free
(
l_ret_str
,
false
);
}
}
}
if
(
l_go_str
){
}
else
if
(
l_go_str
){
if
(
strcmp
(
l_go_str
,
"online"
)
==
0
)
{
if
(
strcmp
(
l_go_str
,
"online"
)
==
0
)
{
dap_chain_net_state_go_to
(
l_net
,
NET_STATE_ONLINE
);
dap_chain_net_state_go_to
(
l_net
,
NET_STATE_ONLINE
);
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Network
\"
%s
\"
go from state %s to %s"
,
dap_chain_node_cli_set_reply_text
(
a_str_reply
,
"Network
\"
%s
\"
go from state %s to %s"
,
...
...
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