diff options
| author | Qiuwen Lu <[email protected]> | 2017-04-11 14:51:56 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2017-04-11 14:51:56 +0800 |
| commit | 48d6cbfabcc07d0f811b855c1ffe2f2c26cbaa2d (patch) | |
| tree | 20ee86246901701b1404423a2d2fe6ba97602ee7 /tools | |
| parent | 8cb51725710911d90dacfefdb8c6cf7d65824348 (diff) | |
增加物理设备统计工具,支持PyInstaller打包工具。
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/CMakeLists.txt | 28 | ||||
| -rw-r--r-- | tools/monit/monit_device.py | 1 | ||||
| -rw-r--r-- | tools/monit_device/CMakeLists.txt | 14 | ||||
| -rw-r--r-- | tools/monit_device/monit_device.py | 138 | ||||
| -rw-r--r-- | tools/stat/app_stat.c | 262 | ||||
| -rw-r--r-- | tools/stat/dev_stat.c | 196 | ||||
| -rw-r--r-- | tools/stat/event_stat.c | 80 | ||||
| -rw-r--r-- | tools/stat/libstat.c | 164 | ||||
| -rw-r--r-- | tools/stat/libstat.h | 68 | ||||
| -rw-r--r-- | tools/systemd/CMakeLists.txt | 11 |
10 files changed, 165 insertions, 797 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index eb0a1d3..a500779 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,26 +1,2 @@ -find_package(DPDK REQUIRED)
-find_package(PCAP REQUIRED)
-
-include_directories(${CMAKE_SOURCE_DIR}/include)
-include_directories(${CMAKE_SOURCE_DIR}/include/extern)
-include_directories(${CMAKE_SOURCE_DIR}/include/internal)
-include_directories(${DPDK_INCLUDE_DIR})
-include_directories(include)
-add_definitions(${DPDK_C_PREDEFINED})
-
-#add_executable(zcp_rx_tcpdump tcpdump/rx_tcpdump.c)
-#target_include_directories(zcp_rx_tcpdump PRIVATE ${PCAP_INCLUDE_DIR})
-#target_link_libraries(zcp_rx_tcpdump pag ${PCAP_LIBRARY})
-#install(TARGETS zcp_rx_tcpdump RUNTIME DESTINATION bin COMPONENT Program)
-
-#install(FILES script/mrstart DESTINATION bin PERMISSIONS WORLD_EXECUTE COMPONENT Program)
-#install(FILES script/mrstop DESTINATION bin PERMISSIONS WORLD_EXECUTE COMPONENT Program)
-#install(FILES script/mrzcpd DESTINATION /etc/init.d/ PERMISSIONS WORLD_EXECUTE COMPONENT Program)
-
-configure_file(systemd/mrenv.service.in systemd/mrenv.service)
-install(FILES ${CMAKE_BINARY_DIR}/tools/systemd/mrenv.service DESTINATION ${MR_INSTALL_SYSUNITDIR} COMPONENT Program)
-
-configure_file(systemd/mrzcpd.service.in systemd/mrzcpd.service)
-install(FILES ${CMAKE_BINARY_DIR}/tools/systemd/mrzcpd.service DESTINATION ${MR_INSTALL_SYSUNITDIR} COMPONENT Program)
-
-install(FILES systemd/mrenv-script DESTINATION ${MR_INSTALL_BINDIR} PERMISSIONS WORLD_EXECUTE COMPONENT Program)
\ No newline at end of file + +add_subdirectory(monit_device)
\ No newline at end of file diff --git a/tools/monit/monit_device.py b/tools/monit/monit_device.py deleted file mode 100644 index 5f28270..0000000 --- a/tools/monit/monit_device.py +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/tools/monit_device/CMakeLists.txt b/tools/monit_device/CMakeLists.txt new file mode 100644 index 0000000..2166bc2 --- /dev/null +++ b/tools/monit_device/CMakeLists.txt @@ -0,0 +1,14 @@ + +set(PI_DIST_PATH ${CMAKE_CURRENT_BINARY_DIR}/pi_dist) +set(PI_BUILD_PATH ${CMAKE_CURRENT_BINARY_DIR}/pi_build) +set(PI_SPEC_PATH ${CMAKE_CURRENT_BINARY_DIR}/pi_spec) + +add_custom_command(OUTPUT ${PI_DIST_PATH}/monit_device + COMMAND pyinstaller -F -y --distpath ${PI_DIST_PATH} + --workpath ${PI_BUILD_PATH} + --specpath ${PI_SPEC_PATH} + --noconsole ${CMAKE_CURRENT_SOURCE_DIR}/monit_device.py + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/monit_device.py) + +add_custom_target(monit_device ALL DEPENDS ${PI_DIST_PATH}/monit_device) +install(FILES ${PI_DIST_PATH}/monit_device DESTINATION bin PERMISSIONS WORLD_EXECUTE COMPONENT Program)
\ No newline at end of file diff --git a/tools/monit_device/monit_device.py b/tools/monit_device/monit_device.py new file mode 100644 index 0000000..e0f87cd --- /dev/null +++ b/tools/monit_device/monit_device.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python2
+
+import argparse
+import json
+import prettytable
+import time +import sys
+
+TBPS = (1 * 1000 * 1000 * 1000 * 1000)
+GBPS = (1 * 1000 * 1000 * 1000)
+MBPS = (1 * 1000 * 1000)
+KBPS = (1 * 1000)
+
+G_JSON_PATH = '/var/run/mrzcpd/mrmonit.daemon'
+
+TITLE_VECTOR = ['PhyRXFrame','PhyRXBits','PhyRXMissed','PhyRXError',
+ 'PhyRXNoBUF','PhyTXFrame','PhyTXBits','PhyTXError']
+
+TITLE_MAP = { 'PhyRXFrame' : 'ipackets',
+ 'PhyRXBits' : 'ibytes',
+ 'PhyRXMissed' : 'imissed',
+ 'PhyRXError' : 'ierrors',
+ 'PhyRXNoBUF' : 'rxnombuf',
+ 'PhyTXFrame' : 'opackets',
+ 'PhyTXBits' : 'obytes',
+ 'PhyTXError' : 'oerrors'
+ }
+
+def locate_vector_by_symbol(vector, symbol):
+ return [s for s in vector if s['symbol'] == symbol]
+
+def list_all_phydev(json_fp):
+ return [ s['symbol'] for s in json_fp['device']]
+
+def phydev_value_read(json_fp, str_device, str_item):
+ phydevs = locate_vector_by_symbol(json_fp['device'], str_device)
+ return phydevs[0]['stats']['accumulative'][str_item]
+
+def phydev_speed_read(json_fp, str_device, str_item):
+ phydevs = locate_vector_by_symbol(json_fp['device'], str_device)
+ return phydevs[0]['stats']['speed'][str_item]
+
+def trans_to_human_readable(value):
+ if value > TBPS:
+ return value * 1.0 / TBPS, 'T'
+ if value > GBPS:
+ return value * 1.0 / GBPS, 'G'
+ if value > MBPS:
+ return value * 1.0 / MBPS, 'M'
+ if value > KBPS:
+ return value * 1.0 / KBPS, 'K'
+
+ return value * 1.0, ' '
+
+def dump_human_table(json_fp, devsym, is_human_number = 0):
+
+ print('\nTime: %s, Physical device: %s' % (time.strftime('%c'), devsym))
+
+ table_phydev = prettytable.PrettyTable([' '] + TITLE_VECTOR,
+ vertical_char=' ',horizontal_char = '-', junction_char=' ')
+
+ ValueList = ['Accumulative']
+ SpeedList = ['Per Second']
+
+ table_phydev.align[' '] = 'r'
+
+ for item in TITLE_VECTOR:
+ table_phydev.align[item] = 'r'
+
+ for item in TITLE_VECTOR:
+ value = phydev_value_read(json_fp, devsym, TITLE_MAP[item])
+ if is_human_number:
+ h_value, h_value_unit = trans_to_human_readable(value)
+ ValueList.append('%7.2f%c' % (h_value, h_value_unit))
+ else:
+ ValueList.append(value)
+
+ for item in TITLE_VECTOR:
+ speed = phydev_speed_read(json_fp, devsym, TITLE_MAP[item])
+ if is_human_number:
+ h_speed, h_speed_unit = trans_to_human_readable(speed)
+ SpeedList.append('%7.2f%c' % (h_speed, h_speed_unit))
+ else:
+ SpeedList.append(speed)
+
+ table_phydev.add_row(ValueList)
+ table_phydev.add_row(SpeedList)
+ print(table_phydev)
+
+
+def setup_argv_parser(phydev_list):
+
+ parser = argparse.ArgumentParser(description='Marsio ZeroCopy Tools -- Monitor NIC devices',
+ version = 'Marsio ZeroCopy Tools Suite 4.1')
+
+ parser.add_argument('-t', '--time', help = 'interval, seconds to wait between updates',
+ type=int, default = 1)
+ parser.add_argument('-l', '--loop', help = 'print loop, exit when recv a signal',
+ action='store_true', default = 0)
+ parser.add_argument('-H', '--human-readable', help = 'print value in human readable format',
+ action = 'store_true', default = 0)
+ parser.add_argument('-i', '--interface', help = 'the name of network interface',
+ action = 'append', choices=phydev_list)
+
+ return parser.parse_args()
+
+def phydev_json_load():
+ with open(G_JSON_PATH) as json_fp:
+ return json.load(json_fp)
+
+def main():
+ try:
+ json_fp = phydev_json_load()
+ phydev_list = list_all_phydev(json_fp)
+ r_option = setup_argv_parser(phydev_list)
+ phydev_user_list = phydev_list if r_option.interface is None else r_option.interface
+
+ while True:
+ json_fp = phydev_json_load()
+ for devsym in phydev_user_list:
+ dump_human_table(json_fp, devsym, r_option.human_readable)
+
+ if not r_option.loop:
+ break
+
+ time.sleep(r_option.time)
+
+ except KeyboardInterrupt: + pass
+ except ValueError as err:
+ print(("%s, perhaps mrzcpd program is not running.") % str(err))
+ except IOError as err:
+ print(("%s, perhaps mrzcpd program is not running.") % str(err)) + + return 0
+
+if __name__ == '__main__':
+ main()
\ No newline at end of file diff --git a/tools/stat/app_stat.c b/tools/stat/app_stat.c deleted file mode 100644 index 623169d..0000000 --- a/tools/stat/app_stat.c +++ /dev/null @@ -1,262 +0,0 @@ - -#include <mr_common.h> -#include <mr_stat.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <mr_runtime.h> - -#include "libstat.h" - -#define __APPST_ITEM(_ptr, _item) (_ptr->__per_app[app_id]._per_thread[sid]._item) - -static void write_speed_table_leader(FILE * stream) -{ - char linebuf[MR_STRING_MAX]; - unsigned int linecur = 0; - - __WRITE_TABLE_ITEM("AppSym", "c", NAME_ITEM_WIDTH); - __WRITE_TABLE_ITEM("SID", "c", ID_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Rx-fps", "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Rx-bps", "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Tx-fps", "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Tx-bps", "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Drop-fps", "c", SPEED_ITEM_WIDTH); - - fprintf(stream, "%s\n", linebuf); - - linecur = 0; - __WRITE_TABLE_CLINE('-', "c", NAME_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", ID_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - - fprintf(stream, "%s\n", linebuf); - return; -} - -static void write_total_table_leader(FILE * stream) -{ - char linebuf[MR_STRING_MAX]; - unsigned int linecur = 0; - - __WRITE_TABLE_ITEM("AppSym", "c", NAME_ITEM_WIDTH); - __WRITE_TABLE_ITEM("SID", "c", ID_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Rx-frames", "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Rx-bits", "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Tx-frames", "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Tx-bits", "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_ITEM("Drop-frames", "c", SPEED_ITEM_WIDTH); - - fprintf(stream, "%s\n", linebuf); - - linecur = 0; - __WRITE_TABLE_CLINE('-', "c", NAME_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", ID_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - __WRITE_TABLE_CLINE('-', "c", SPEED_ITEM_WIDTH); - - fprintf(stream, "%s\n", linebuf); - return; -} - -static void write_timeinfo(FILE * stream) -{ - time_t currect; - time(&currect); - - char str_localtime[MR_STRING_MAX]; - libstat_strtime(str_localtime, sizeof(str_localtime), currect); - fprintf(stream, "Time: %12s\n", str_localtime); - return; -} - -static void write_speed_line(FILE * stream, const char * app_sym, unsigned int app_id, unsigned int sid, - const struct mr_app_stat * st_last, const struct mr_app_stat * st_now, - unsigned int delta_time, unsigned int human) -{ - char linebuf[MR_STRING_MAX]; - char str_human[MR_STRING_MAX]; - unsigned int linecur = 0; - unsigned int delta_rx_frame, delta_rx_bits, delta_tx_frame, delta_tx_bits; - - char numbuf[MR_STRING_MAX]; - __WRITE_TABLE_ITEM(app_sym, "c", NAME_ITEM_WIDTH); - __WRITE_TABLE_ITEM(__TRANS_DATA(sid, numbuf), "c", ID_ITEM_WIDTH); - - delta_rx_frame = __APPST_ITEM(st_now, rx_frame) - __APPST_ITEM(st_last, rx_frame); - delta_rx_bits = __APPST_ITEM(st_now, rx_byte) - __APPST_ITEM(st_last, rx_byte); - delta_tx_frame = __APPST_ITEM(st_now, tx_frame) - __APPST_ITEM(st_last, tx_frame); - delta_tx_bits = __APPST_ITEM(st_now, tx_byte) - __APPST_ITEM(st_last, tx_byte); - - delta_rx_frame /= delta_time; - delta_rx_bits /= delta_time; - delta_tx_frame /= delta_time; - delta_tx_bits /= delta_time; - - delta_rx_bits *= 8; - delta_tx_bits *= 8; - - if(human) - { - __TRANS_HUMAN(delta_rx_frame, str_human); - __WRITE_TABLE_ITEM(str_human, "r", SPEED_ITEM_WIDTH); - - __TRANS_HUMAN(delta_rx_bits, str_human); - __WRITE_TABLE_ITEM(str_human, "r", SPEED_ITEM_WIDTH); - - __TRANS_HUMAN(delta_tx_frame, str_human); - __WRITE_TABLE_ITEM(str_human, "r", SPEED_ITEM_WIDTH); - - __TRANS_HUMAN(delta_tx_bits, str_human); - __WRITE_TABLE_ITEM(str_human, "r", SPEED_ITEM_WIDTH); - } - else - { - __TRANS_DATA(delta_rx_frame, numbuf); - __WRITE_TABLE_ITEM(numbuf, "r", SPEED_ITEM_WIDTH); - - __TRANS_DATA(delta_rx_bits, numbuf); - __WRITE_TABLE_ITEM(numbuf, "r", SPEED_ITEM_WIDTH); - - __TRANS_DATA(delta_tx_frame, numbuf); - __WRITE_TABLE_ITEM(numbuf, "r", SPEED_ITEM_WIDTH); - - __TRANS_DATA(delta_tx_bits, numbuf); - __WRITE_TABLE_ITEM(numbuf, "r", SPEED_ITEM_WIDTH); - } - - fprintf(stream, "%s\n", linebuf); - return; -} - -static void write_count_line(FILE * stream, const char * app_sym, - unsigned int app_id, unsigned int sid, const struct mr_app_stat * st_now, unsigned int human) -{ - struct mr_app_stat st_zero[1]; - memset(st_zero, 0, sizeof(struct mr_app_stat)); - write_speed_line(stream, app_sym, app_id, sid, st_zero, st_now, 1, human); -} - -static struct mr_app_stat last_app_stat; -static struct mr_app_stat now_app_stat; - -void pinfo_stat_loop(FILE * stream, struct appinfo * pinfo, - struct mr_app_stat * st_now, struct mr_app_stat * st_last, - int speed, int delta_time, int human) -{ - const char * appsym = mr_appinfo_get_symbol(pinfo); - unsigned int appid = mr_appinfo_get_app_id(pinfo); - unsigned int nr_max_thread = mr_appinfo_get_nr_max_thread(pinfo); - - for(int sid = 0; sid < nr_max_thread; sid++) - { - if (speed) - write_speed_line(stream, appsym, appid, sid, - st_last, st_now, delta_time, human); - else - write_count_line(stream, appsym, appid, sid, - st_now, human); - } - - return; -} - -static struct mr_app_stat * __get_stat_handle() -{ - struct mr_app_stat * stat_ptr = mr_app_stat_get(); - if (stat_ptr == NULL) - { - fprintf(stderr, "Master(serivce) is not run or app stat " - "function is disable(handle is null).\n"); - exit(EXIT_FAILURE); - } - return stat_ptr; -} - -int app_stat_output_loop(FILE * stream, int speed, int delta_time, int human) -{ - last_app_stat = *__get_stat_handle(); - if (delta_time != 0) sleep(delta_time); - now_app_stat = *__get_stat_handle(); - - // д��ͷ - fprintf(stream, "\n"); - write_timeinfo(stream); - fprintf(stream, "\n"); - - if (speed) write_speed_table_leader(stream); - else write_total_table_leader(stream); - - // д������Ϣ - struct appinfo * appinfo_iterate = NULL; - while(mr_app_manager_appinfo_iterate(&appinfo_iterate) >= 0) - { - pinfo_stat_loop(stream, appinfo_iterate, &now_app_stat, &last_app_stat, - speed, delta_time, human); - } - - fprintf(stream, "\n"); - return 0; -} - -void print_help(const char * cmd, FILE * stream) -{ - fprintf(stream, "\n"); - fprintf(stream, "Usage: %s [-t interval][-s][-h][-?]\n", cmd); - fprintf(stream, " -t interval, seconds to wait between updates\n"); - fprintf(stream, " -s print speed or accumulative count, default is speed\n"); - fprintf(stream, " -l print loop, exit when recv a signal\n"); - fprintf(stream, " -h print value in human readable format\n"); - fprintf(stream, " -? print usage message\n"); - fprintf(stream, "\n"); -} - - -int main(int argc, char *argv[]) -{ - char c; - unsigned opt_delta_time = 1; - unsigned opt_speed = 0; - unsigned opt_human = 0; - unsigned opt_loop = 0; - - while ((c = getopt(argc, argv, "t:shl?")) != -1) - { - switch (c) - { - case 't': - opt_delta_time = atoi(optarg); - break; - case 's': - opt_speed = 1; - break; - case 'h': - opt_human = 1; - break; - case 'l': - opt_loop = 1; - break; - case '?': - default: - print_help(argv[0], stdout); - return 0; - } - } - - libstat_init(); - if (opt_delta_time <= 0) opt_delta_time = 1; - while(1) - { - app_stat_output_loop(stdout, opt_speed, opt_delta_time, opt_human); - if (!opt_loop) break; - } - - return 0; -}
\ No newline at end of file diff --git a/tools/stat/dev_stat.c b/tools/stat/dev_stat.c deleted file mode 100644 index 247a68e..0000000 --- a/tools/stat/dev_stat.c +++ /dev/null @@ -1,196 +0,0 @@ -#include <time.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <assert.h> -#include <field_stat2.h> - - -#include<mr_ctx.h> -#include <mr_common.h> -#include <mr_procman.h> -#include <mr_core.h> -//#include <mrlib.h> -//#include <mrlib_common.h> - -//#include<rte_mbuf.h> -#include "../../core/include/mr_stat.h" -#include "../../core/include/mr_device.h" -#include "../../core/include/mr_common.h" - - -#define MR_LIB_MAX_EAL_ARGC 128 - -enum DEV_STAT_COLUMN -{ - COLUMN_TABLE_DEVICE_RX_FRAME=0, - COLUMN_TABLE_DEVICE_RX_BIT, - COLUMN_TABLE_DEVICE_TX_FRAME, - COLUMN_TABLE_DEVICE_TX_BIT, - COLUMN_TABLE_DEVICE_RX_PPS, - COLUMN_TABLE_DEVICE_RX_BPS, - COLUMN_TABLE_DEVICE_TX_PPS, - COLUMN_TABLE_DEVICE_TX_BPS, - COLUMN_TABLE_COLUMN_NUM -}; -struct dev_stat_statics -{ - screen_stat_handle_t stat_handle; - int fs_column_id[COLUMN_TABLE_COLUMN_NUM]; - int fs_line_id[RTE_MAX_ETHPORTS+1]; - //char *stat_file; -}; -static void __write_arg(char * eal_argv[], unsigned int * eal_argc, - unsigned int max_argc, const char * value) -{ - assert(max_argc >= *eal_argc); - char * mem = (char *)malloc(MR_STRING_MAX * sizeof(char)); - assert(mem != NULL); - - snprintf(mem, MR_STRING_MAX * sizeof(char), "%s", value); - eal_argv[(*eal_argc)++] = mem; - return; -} - -#define WRITE_ARG(x) \ - do {__write_arg(eal_argv, &eal_argc, MR_LIB_MAX_EAL_ARGC, x);} \ - while(0) - -struct dev_stat_statics * dev_stat_init(mr_dev_t * device_list[],int device_list_count) -{ - int value=0; - int i=0; - struct dev_stat_statics *g_dev_stat_statics=(struct dev_stat_statics *)calloc(sizeof(struct dev_stat_statics),1); - g_dev_stat_statics->stat_handle=FS_create_handle(); - value=1; - FS_set_para(g_dev_stat_statics->stat_handle, PRINT_MODE, &value, sizeof(value)); - value=0; - FS_set_para(g_dev_stat_statics->stat_handle, CREATE_THREAD, &value, sizeof(value)); - - //g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_NAME]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"dev_name"); - g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_RX_FRAME]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"dev_rx_frame"); - g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_RX_BIT]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"dev_rx_bit"); - g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_TX_FRAME]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"dev_tx_frame"); - g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_TX_BIT]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT,"dev_tx_bit"); - g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_RX_PPS]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_SPEED,"dev_rx_pps"); - g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_RX_BPS]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_SPEED,"dev_rx_bps"); - g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_TX_PPS]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_SPEED,"dev_tx_pps"); - g_dev_stat_statics->fs_column_id[COLUMN_TABLE_DEVICE_TX_BPS]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_COLUMN, FS_CALC_SPEED,"dev_tx_bbs"); - - - for(i=0;i<device_list_count;i++) - { - mr_dev_t *dev=device_list[i]; - if(dev!=NULL) - g_dev_stat_statics->fs_line_id[i]=FS_register(g_dev_stat_statics->stat_handle, FS_STYLE_LINE, FS_CALC_CURRENT,dev->symbol); - } - //g_dev_stat_statics->fs_column_id[RTE_MAX_ETHPORTS]=FS_register(feather->stat_handle, FS_STYLE_LINE, FS_CALC_CURRENT,"sum"); - FS_start(g_dev_stat_statics->stat_handle); - return g_dev_stat_statics; -} - - -void dev_stat_output(struct dev_stat_statics* g_dev_stat_statics,mr_dev_t * device_list[],int device_list_count) -{ - struct mr_device_stat * mr_device_stat_stattics=mr_device_stat_get(); - time_t now; - time(&now); - int dev_count=0; - port_id_t portid; - int dev_column_count=0; - int dev_thread_count=0; - uint64_t total_dev_rx_tx_frame_bit[MR_DEVICE_MAX][COLUMN_TABLE_COLUMN_NUM]; - for(dev_count=0;dev_count<MR_DEVICE_MAX;dev_count++) - { - for(dev_column_count=0;dev_column_count<COLUMN_TABLE_COLUMN_NUM;dev_column_count++) - { - total_dev_rx_tx_frame_bit[dev_count][dev_column_count]=0; - } - } - for(dev_count=0;dev_count<device_list_count;dev_count++) - { - mr_dev_t *dev=device_list[dev_count]; - if(dev!=NULL) - { - portid=dev->port_id; - if(portid>=0&&portid<MR_DEVICE_MAX) - { - //total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_NAME]=portid;//device id - for(dev_thread_count=0;dev_thread_count<MR_MAX_GSID;dev_thread_count++) - { - total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_RX_FRAME]+=mr_device_stat_stattics->_per_thread[dev_thread_count].dev_rx_frame[portid]; - total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_RX_BIT]+=mr_device_stat_stattics->_per_thread[dev_thread_count].dev_rx_bit[portid]; - total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_TX_FRAME]+=mr_device_stat_stattics->_per_thread[dev_thread_count].dev_tx_frame[portid]; - total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_TX_BIT]+=mr_device_stat_stattics->_per_thread[dev_thread_count].dev_tx_bit[portid]; - } - total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_RX_PPS]=total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_RX_FRAME]; - total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_RX_BPS]=total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_RX_BIT]; - total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_TX_PPS]=total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_TX_FRAME]; - total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_TX_BPS]=total_dev_rx_tx_frame_bit[portid][COLUMN_TABLE_DEVICE_TX_BIT]; - } - } - } - for(dev_count=0;dev_count<MR_DEVICE_MAX;dev_count++) - { - for(dev_column_count=0;dev_column_count<COLUMN_TABLE_COLUMN_NUM;dev_column_count++) - { - FS_operate(g_dev_stat_statics->stat_handle, - g_dev_stat_statics->fs_line_id[dev_count], - g_dev_stat_statics->fs_column_id[dev_column_count], - FS_OP_SET, - total_dev_rx_tx_frame_bit[dev_count][dev_column_count]); - } - } - FS_passive_output(g_dev_stat_statics->stat_handle); - return; -} - - -static void mrapp_eal_init() -{ - char * eal_argv[8]; - unsigned int eal_argc = 0; - - WRITE_ARG("mrlib"); - WRITE_ARG("-c"); - WRITE_ARG("0x1"); - WRITE_ARG("--proc-type=secondary"); - - int ret = rte_eal_init(eal_argc, eal_argv); - MR_CHECK(ret >= 0, "Cannot init EAL Enviorment, Failed"); - return; -} -static void mrapp_slave_log_ready(FILE * logstream) -{ - if (logstream == NULL) logstream = stderr; - rte_openlog_stream(stderr); -} - -int mr_lib_init() -{ - int ret = 0; - mrapp_eal_init(); - mrapp_slave_log_ready(NULL); - - mr_global_ctx_slave_init(); - mr_global_cfg_slave_init(); - mr_core_stage_slaveinit(); - return 0; -} - - -int main(int argc,char *argv[]) -{ - mr_lib_init(); - mr_dev_t * device_list[MR_DEVICE_MAX]; - int device_list_count=mr_device_list(, device_list,MR_DEVICE_MAX), 0; - struct dev_stat_statics *g_dev_stat_statics=dev_stat_init(device_list,device_list_count); - while(1) - { - dev_stat_output(g_dev_stat_statics,device_list,device_list_count); - sleep(1); - } - return 0; -} - diff --git a/tools/stat/event_stat.c b/tools/stat/event_stat.c deleted file mode 100644 index fb39d13..0000000 --- a/tools/stat/event_stat.c +++ /dev/null @@ -1,80 +0,0 @@ -#include <mr_stat.h> - -#include "libstat.h" - -static void write_timeinfo(FILE * stream) -{ - time_t currect; - time(&currect); - - char str_localtime[MR_STRING_MAX]; - libstat_strtime(str_localtime, sizeof(str_localtime), currect); - fprintf(stream, "Time: %12s\n", str_localtime); - return; -} - -#define EVENT_NAME_WIDTH 25 -#define EVENT_COUNT_WIDTH 25 - -static void write_table_header(FILE * stream) -{ - char linebuf[MR_STRING_MAX]; - unsigned int linecur = 0; - - __WRITE_TABLE_ITEM("EventSymbol", "c", EVENT_NAME_WIDTH); - __WRITE_TABLE_ITEM("Count", "c", EVENT_COUNT_WIDTH); - fprintf(stream, "%s\n", linebuf); - - linecur = 0; - __WRITE_TABLE_CLINE('-', "c", EVENT_NAME_WIDTH); - __WRITE_TABLE_CLINE('-', "c", EVENT_COUNT_WIDTH); - fprintf(stream, "%s\n", linebuf); -} - -static void write_event_item(FILE * stream, const char * ev_symbol, uint64_t value) -{ - char linebuf[MR_STRING_MAX]; - char numbuf[MR_STRING_MAX]; - unsigned int linecur = 0; - - __WRITE_TABLE_ITEM(ev_symbol, "r", EVENT_NAME_WIDTH); - __TRANS_DATA(value, numbuf); - __WRITE_TABLE_ITEM(numbuf, "r", EVENT_COUNT_WIDTH); - fprintf(stream, "%s\n", linebuf); -} - -static void event_stat_loop(FILE * stream) -{ - struct mr_trace_stat * stat_handle; - stat_handle = mr_trace_stat_get(); - if(stat_handle == NULL) - { - fprintf(stderr, "Master(serivce) is not run or event stat " - "function is disable(handle is null).\n"); - exit(EXIT_FAILURE); - } - - uint64_t total_ev_rx_dup_failed = 0; - uint64_t total_ev_rx_entunnel_failed = 0; - - for(int i = 0; i < RTE_DIM(stat_handle->_per_thread); i++) - { - total_ev_rx_dup_failed += stat_handle->_per_thread[i].ev_rx_dup_failed; - total_ev_rx_entunnel_failed += stat_handle->_per_thread[i].ev_rx_entunnel_failed; - } - - fprintf(stream, "\n"); - write_timeinfo(stream); - fprintf(stream, "\n"); - write_table_header(stdout); - write_event_item(stream, "ev_rx_dup_failed", total_ev_rx_dup_failed); - write_event_item(stream, "ev_rx_entunnel_failed", total_ev_rx_entunnel_failed); - fprintf(stream, "\n"); - return; -} - -int main(int argc, char * argv[]) -{ - libstat_init(); - event_stat_loop(stdout); -}
\ No newline at end of file diff --git a/tools/stat/libstat.c b/tools/stat/libstat.c deleted file mode 100644 index 2046c2d..0000000 --- a/tools/stat/libstat.c +++ /dev/null @@ -1,164 +0,0 @@ - -#include <mr_common.h> -#include <assert.h> -#include <stdio.h> -#include <rte_log.h> -#include <mr_runtime.h> -#include <string.h> - -#include "libstat.h" -#include "mr_core.h" - -#define MR_LIB_MAX_EAL_ARGC 128 - -static void __write_arg(char * eal_argv[], unsigned int * eal_argc, - unsigned int max_argc, const char * value) -{ - assert(max_argc >= *eal_argc); - char * mem = (char *)malloc(MR_STRING_MAX * sizeof(char)); - assert(mem != NULL); - - snprintf(mem, MR_STRING_MAX * sizeof(char), "%s", value); - eal_argv[(*eal_argc)++] = mem; - return; -} - -#define WRITE_ARG(x) \ - do {__write_arg(eal_argv, &eal_argc, MR_LIB_MAX_EAL_ARGC, x);} \ - while(0) - - -static void libstat_eal_init() -{ - char * eal_argv[8]; - unsigned int eal_argc = 0; - rte_openlog_stream(stderr); - - WRITE_ARG("mrlib"); - WRITE_ARG("-c"); - WRITE_ARG("0x1"); - WRITE_ARG("--proc-type=secondary"); - WRITE_ARG("--log-level"); - WRITE_ARG("4"); - - int ret = rte_eal_init(eal_argc, eal_argv); - MR_CHECK(ret >= 0, "Cannot init EAL Enviorment, Failed"); - return; -} - -int libstat_init() -{ - libstat_eal_init(); - mr_runtime_slave_init(); - - struct mr_global_ctx * g_ctx = mr_global_ctx_get(); - mr_core_default_instance_set(g_ctx->ctx_core); - return 0; -} - - -#define TBPS (1ull * 1000 * 1000 * 1000 * 1000) -#define GBPS (1ull * 1000 * 1000 * 1000) -#define MBPS (1ull * 1000 * 1000) -#define KBPS (1ull * 1000) - -void libstat_unit_translate(uint64_t number, float * f_number, char * unit) -{ - if (number > TBPS) - { - *f_number = number * 1.0 / TBPS; - *unit = 'T'; - } - else if (number > GBPS) - { - *f_number = number * 1.0 / GBPS; - *unit = 'G'; - } - else if (number > MBPS) - { - *f_number = number * 1.0 / MBPS; - *unit = 'M'; - } - else if (number > KBPS) - { - *f_number = number * 1.0 / KBPS; - *unit = 'K'; - } - else - { - *f_number = number * 1.0; - *unit = ' '; - } -} - -void libstat_strtime(char * strtime, int str_max, time_t time) -{ - int pos = snprintf(strtime, str_max, "%s", ctime(&time)); - strtime[pos - 1] = '\0'; - return; -} - -int libstat_table_format_item(const char * str, const char * fmt, - int width, int spacewidth, char * output, int sz_output) -{ - char _format[MR_STRING_MAX]; - int len = strlen(str); - if (len > width) return 0; - -#define __LOCATION_LEFT 0 -#define __LOCATION_RIGHT 1 -#define __LOCATION_CENTER 2 - - // �ַ���λ�� - int location = __LOCATION_LEFT; - for(int i = 0; i < strlen(fmt); i++) - { - switch(fmt[i]) - { - case 'l': location = __LOCATION_LEFT; break; - case 'r': location = __LOCATION_RIGHT; break; - case 'c': location = __LOCATION_CENTER; break; - default: location = __LOCATION_LEFT; break; - } - } - - // ����printf�ĸ�ʽ˵�� - if(location == __LOCATION_LEFT) - { - snprintf(_format, sizeof(fmt), "%%-%ds", width); - } - if(location == __LOCATION_RIGHT) - { - snprintf(_format, sizeof(fmt), "%%%ds", width); - } - if(location == __LOCATION_CENTER) - { - int cur = 0; - int space_before = (width - len) / 2; - for (int i = 0; i < space_before; i++) _format[cur++] = ' '; - cur += snprintf(_format + cur, sizeof(_format) - space_before, "%%s"); - for (int i = 0; i < width - space_before - len; i++) _format[cur++] = ' '; - _format[cur] = '\0'; - } - - // β�����ӿո� - if(spacewidth != 0) - { - char str_fill[MR_STRING_MAX]; - for (int i = 0; i < spacewidth; i++) str_fill[i] = ' '; - str_fill[spacewidth] = '\0'; - strncat(_format, str_fill, sizeof(_format)); - } - - // ��ʽ��� - return snprintf(output, sz_output, _format, str); -} - -int libstat_table_fill_item(const char ch, const char * fmt, - int width, int spacewidth, char * output, int sz_output) -{ - char str_fill[MR_STRING_MAX]; - for (int i = 0; i < width; i++) str_fill[i] = ch; - str_fill[width] = '\0'; - return libstat_table_format_item(str_fill, fmt, width, spacewidth, output, sz_output); -}
\ No newline at end of file diff --git a/tools/stat/libstat.h b/tools/stat/libstat.h deleted file mode 100644 index 42fa054..0000000 --- a/tools/stat/libstat.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -#include <stdint.h> -#include <inttypes.h> -#include <time.h> - -int libstat_init(); -void libstat_unit_translate(uint64_t number, float * f_number, char * unit); -void libstat_strtime(char * strtime, int str_max, time_t time); - -/** - * \brief 格式化字符串 - * \param str 被格式化的字符串 - * \param fmt 格式说明字符串,"l"为左对齐,"r"为右对齐,"c"为居中 - * \param width 宽度,需大于等于被格式化字符串的长度 - * \param spacewidth 尾部添加的空格数量 - * \param output 输出缓冲区指针 - * \param sz_output 输出缓冲区大小 - * \return 实际输出的长度 - */ -int libstat_table_format_item(const char * str, const char * fmt, - int width, int spacewidth, char * output, int sz_output); - -/** - * \brief 填充字符串 - * \param ch 被填充的字符 - * \param fmt 填充字符串格式 - * \param width 宽度 - * \param spacewidth 尾部添加的空格数量 - * \param output 输出缓冲区指针 - * \param sz_output 输出缓冲区大小 - * \return 实际输出的长度 - */ -int libstat_table_fill_item(const char ch, const char * fmt, - int width, int spacewidth, char * output, int sz_output); - -#define SPEED_ITEM_WIDTH 12 -#define COUNT_ITEM_WIDTH 20 -#define NAME_ITEM_WIDTH 8 -#define ID_ITEM_WIDTH 6 -#define SPACE_WIDTH 2 - -#define __WRITE_TABLE_ITEM(_name, _fmt, _iwidth) \ -do { \ - linecur += libstat_table_format_item(_name, _fmt, _iwidth, SPACE_WIDTH, \ - linebuf + linecur, sizeof(linebuf) - linecur); \ -} while(0); \ - -#define __WRITE_TABLE_CLINE(_ch, _fmt, _iwidth) \ -do { \ - linecur += libstat_table_fill_item(_ch, _fmt, _iwidth, SPACE_WIDTH, \ - linebuf + linecur, sizeof(linebuf) - linecur); \ -} while(0); - -#define __TRANS_HUMAN(_data, _str) \ -do { \ - float f_data; char unit; \ - libstat_unit_translate(_data, &f_data, &unit); \ - sprintf(_str, "%7.2f%c", f_data, unit); \ -}while(0) \ - -static inline char * __trans_data(uint64_t data, char * buffer, size_t sz_buffer) -{ - snprintf(buffer, sz_buffer, "%"PRIu64, data); - return buffer; -} - -#define __TRANS_DATA(_data, _buffer) (__trans_data(_data, _buffer, sizeof(_buffer)))
\ No newline at end of file diff --git a/tools/systemd/CMakeLists.txt b/tools/systemd/CMakeLists.txt new file mode 100644 index 0000000..ebb0564 --- /dev/null +++ b/tools/systemd/CMakeLists.txt @@ -0,0 +1,11 @@ +configure_file(mrenv.service.in mrenv.service) +configure_file(mrzcpd.service.in mrzcpd.service) + +install(FILES ${CMAKE_BINARY_DIR}/tools/systemd/mrenv.service + DESTINATION ${MR_INSTALL_SYSUNITDIR} COMPONENT Program) + +install(FILES ${CMAKE_BINARY_DIR}/tools/systemd/mrzcpd.service + DESTINATION ${MR_INSTALL_SYSUNITDIR} COMPONENT Program) + +install(FILES mrenv-script DESTINATION ${MR_INSTALL_BINDIR} + PERMISSIONS WORLD_EXECUTE COMPONENT Program)
\ No newline at end of file |
