diff --git a/CHANGELOG.md b/CHANGELOG.md index 5233326d7..b43bb2fca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,11 @@ Added spdk_rpc_set_allowlist to restrict allowed RPCs to the specified list. Promoted the application to example to match similar programs: fio_plugin and perf. It can now be found inside `examples/bdev/bdevperf`. +### trace + +New `trace_get_info` RPC was added to get name of shared memory file, list of the +available trace point groups and mask of the available trace points for each group. + ### util New API `spdk_fd_group_get_epoll_event` that returns the epoll(7) event that diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index 986009dd5..297e97596 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -1173,6 +1173,76 @@ Example response: } ~~~ +### trace_get_info {#rpc_trace_get_info} + +Get name of shared memory file, list of the available trace point groups +and mask of the available trace points for each group + +#### Parameters + +No parameters required + +#### Example + +Example request: + +~~~json +{ + "jsonrpc": "2.0", + "method": "trace_get_info", + "id": 1 +} +~~~ + +Example response: + +~~~json +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "tpoint_shm_path": "/dev/shm/spdk_tgt_trace.pid3071944", + "tpoint_group_mask": "0x8", + "iscsi_conn": { + "mask": "0x2", + "tpoint_mask": "0x0" + }, + "scsi": { + "mask": "0x4", + "tpoint_mask": "0x0" + }, + "bdev": { + "mask": "0x8", + "tpoint_mask": "0xffffffffffffffff" + }, + "nvmf_tcp": { + "mask": "0x20", + "tpoint_mask": "0x0" + }, + "blobfs": { + "mask": "0x80", + "tpoint_mask": "0x0" + }, + "thread": { + "mask": "0x400", + "tpoint_mask": "0x0" + }, + "nvme_pcie": { + "mask": "0x800", + "tpoint_mask": "0x0" + }, + "nvme_tcp": { + "mask": "0x2000", + "tpoint_mask": "0x0" + }, + "bdev_nvme": { + "mask": "0x4000", + "tpoint_mask": "0x0" + } + } +} +~~~ + ### log_set_print_level {#rpc_log_set_print_level} Set the current level at which output will additionally be diff --git a/lib/trace/Makefile b/lib/trace/Makefile index 4b21801ff..70dfbf07b 100644 --- a/lib/trace/Makefile +++ b/lib/trace/Makefile @@ -7,7 +7,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk SO_VER := 7 -SO_MINOR := 0 +SO_MINOR := 1 C_SRCS = trace.c trace_flags.c trace_rpc.c LIBNAME = trace diff --git a/lib/trace/trace.c b/lib/trace/trace.c index c7123b827..b332151ff 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -13,6 +13,7 @@ #include "spdk/log.h" #include "spdk/cpuset.h" #include "spdk/likely.h" +#include "trace_internal.h" static int g_trace_fd = -1; static char g_shm_name[64]; @@ -271,3 +272,9 @@ spdk_trace_cleanup(void) shm_unlink(g_shm_name); } } + +const char * +trace_get_shm_name(void) +{ + return g_shm_name; +} diff --git a/lib/trace/trace_internal.h b/lib/trace/trace_internal.h new file mode 100644 index 000000000..4d015229e --- /dev/null +++ b/lib/trace/trace_internal.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (C) 2022 Intel Corporation. + * All rights reserved. + */ + +#ifndef __TRACE_INTERNAL_H__ +#define __TRACE_INTERNAL_H__ + +#include "spdk/trace.h" + +/* Get shared memory file name. */ +const char *trace_get_shm_name(void); + +#endif diff --git a/lib/trace/trace_rpc.c b/lib/trace/trace_rpc.c index 51a53377b..3dff267a0 100644 --- a/lib/trace/trace_rpc.c +++ b/lib/trace/trace_rpc.c @@ -7,6 +7,7 @@ #include "spdk/util.h" #include "spdk/trace.h" #include "spdk/log.h" +#include "trace_internal.h" struct rpc_tpoint_group { char *name; @@ -211,3 +212,52 @@ rpc_trace_get_tpoint_group_mask(struct spdk_jsonrpc_request *request, } SPDK_RPC_REGISTER("trace_get_tpoint_group_mask", rpc_trace_get_tpoint_group_mask, SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME) + +static void +rpc_trace_get_info(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + char shm_path[128]; + uint64_t tpoint_group_mask; + uint64_t tpoint_mask; + char tpoint_mask_str[20]; + char mask_str[20]; + struct spdk_json_write_ctx *w; + struct spdk_trace_register_fn *register_fn; + + if (params != NULL) { + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + "trace_get_info requires no parameters"); + return; + } + + snprintf(shm_path, sizeof(shm_path), "/dev/shm%s", trace_get_shm_name()); + tpoint_group_mask = spdk_trace_get_tpoint_group_mask(); + + w = spdk_jsonrpc_begin_result(request); + spdk_json_write_object_begin(w); + spdk_json_write_named_string(w, "tpoint_shm_path", shm_path); + + snprintf(mask_str, sizeof(mask_str), "0x%" PRIx64, tpoint_group_mask); + spdk_json_write_named_string(w, "tpoint_group_mask", mask_str); + + register_fn = spdk_trace_get_first_register_fn(); + while (register_fn) { + + tpoint_mask = spdk_trace_get_tpoint_mask(register_fn->tgroup_id); + + spdk_json_write_named_object_begin(w, register_fn->name); + snprintf(mask_str, sizeof(mask_str), "0x%lx", (1UL << register_fn->tgroup_id)); + spdk_json_write_named_string(w, "mask", mask_str); + snprintf(tpoint_mask_str, sizeof(tpoint_mask_str), "0x%lx", tpoint_mask); + spdk_json_write_named_string(w, "tpoint_mask", tpoint_mask_str); + spdk_json_write_object_end(w); + + register_fn = spdk_trace_get_next_register_fn(register_fn); + } + + spdk_json_write_object_end(w); + spdk_jsonrpc_end_result(request, w); +} +SPDK_RPC_REGISTER("trace_get_info", rpc_trace_get_info, + SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME) diff --git a/python/spdk/rpc/trace.py b/python/spdk/rpc/trace.py index 15a218a3d..42a495f77 100644 --- a/python/spdk/rpc/trace.py +++ b/python/spdk/rpc/trace.py @@ -53,3 +53,12 @@ def trace_get_tpoint_group_mask(client): List of trace point group mask """ return client.call('trace_get_tpoint_group_mask') + + +def trace_get_info(client): + """Get name of shared memory file and list of the available trace point groups + + Returns: + Name of shared memory file and list of the available trace point groups + """ + return client.call('trace_get_info') diff --git a/scripts/rpc.py b/scripts/rpc.py index 747f1465a..40ffd0a56 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -1803,6 +1803,13 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse p = subparsers.add_parser('trace_get_tpoint_group_mask', help='get trace point group mask') p.set_defaults(func=trace_get_tpoint_group_mask) + def trace_get_info(args): + print_dict(rpc.trace.trace_get_info(args.client)) + + p = subparsers.add_parser('trace_get_info', + help='get name of shared memory file and list of the available trace point groups') + p.set_defaults(func=trace_get_info) + # log def log_set_flag(args): rpc.log.log_set_flag(args.client, flag=args.flag) diff --git a/test/rpc/rpc.sh b/test/rpc/rpc.sh index e514e1c86..e5bc58b4b 100755 --- a/test/rpc/rpc.sh +++ b/test/rpc/rpc.sh @@ -40,7 +40,18 @@ function rpc_plugins() { } } -$SPDK_BIN_DIR/spdk_tgt & +function rpc_trace_cmd_test() { + local info + + info=$($rpc trace_get_info) + [ "$(jq length <<< "$info")" -gt 2 ] + [ "$(jq 'has("tpoint_group_mask")' <<< "$info")" = "true" ] + [ "$(jq 'has("tpoint_shm_path")' <<< "$info")" = "true" ] + [ "$(jq 'has("bdev")' <<< "$info")" = "true" ] + [ "$(jq -r .bdev.tpoint_mask <<< "$info")" != "0x0" ] +} + +$SPDK_BIN_DIR/spdk_tgt -e bdev & spdk_pid=$! trap 'killprocess $spdk_pid; exit 1' SIGINT SIGTERM EXIT waitforlisten $spdk_pid @@ -51,6 +62,7 @@ export PYTHONPATH=$PYTHONPATH:$testdir rpc=rpc_cmd run_test "rpc_integrity" rpc_integrity run_test "rpc_plugins" rpc_plugins +run_test "rpc_trace_cmd_test" rpc_trace_cmd_test # same integrity test, but with rpc_cmd() instead rpc="rpc_cmd" run_test "rpc_daemon_integrity" rpc_integrity