lib/trace: add 3 RPC method for tpoint_group_mask

Now trace facility can be enabled/disabled at runtime,
besides app starting parameters

Change-Id: I086564665ba4375b946a5339d5921d6584e9bfda
Signed-off-by: Liu Xiaodong <xiaodong.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/435470
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Liu Xiaodong 2018-11-29 06:12:26 -05:00 committed by Jim Harris
parent 605e530a4e
commit ae0aae1532
15 changed files with 416 additions and 7 deletions

View File

@ -53,6 +53,13 @@ planned shutdown.
set_trace_flag, clear_trace_flag and get_trace_flags RPCs are now deprecated,
and set_log_flag, clear_log_flag and get_log_flags RPCs have been added.
### trace
New `get_tpoint_group_mask` RPC was added to get current tpoint_group_mask, and
each tpoint group status.
New `enable_tpoint_group` and `disable_tpoint_group` RPC were added to enable or
disable a specific tpoint group.
## v18.10:
### nvme

View File

@ -46,7 +46,7 @@ C_SRCS := iscsi_tgt.c
SPDK_LIB_LIST = $(ALL_MODULES_LIST)
SPDK_LIB_LIST += event_bdev event_copy event_iscsi event_net event_scsi event
SPDK_LIB_LIST += jsonrpc json rpc bdev_rpc bdev iscsi scsi copy trace conf
SPDK_LIB_LIST += thread util log log_rpc app_rpc net sock
SPDK_LIB_LIST += thread util log log_rpc trace_rpc app_rpc net sock
ifeq ($(OS),Linux)
SPDK_LIB_LIST += event_nbd nbd

View File

@ -42,7 +42,7 @@ C_SRCS := nvmf_main.c
SPDK_LIB_LIST = $(ALL_MODULES_LIST)
SPDK_LIB_LIST += event_bdev event_copy event_nvmf event_net
SPDK_LIB_LIST += nvmf event log trace conf thread util bdev copy rpc jsonrpc json net sock
SPDK_LIB_LIST += app_rpc log_rpc bdev_rpc
SPDK_LIB_LIST += app_rpc log_rpc trace_rpc bdev_rpc
ifeq ($(OS),Linux)
SPDK_LIB_LIST += event_nbd nbd

View File

@ -49,7 +49,7 @@ endif
SPDK_LIB_LIST += event_bdev event_copy event_iscsi event_net event_scsi event_nvmf event
SPDK_LIB_LIST += nvmf trace log conf thread util bdev iscsi scsi copy rpc jsonrpc json
SPDK_LIB_LIST += app_rpc log_rpc bdev_rpc net sock
SPDK_LIB_LIST += app_rpc log_rpc trace_rpc bdev_rpc net sock
ifeq ($(OS),Linux)
SPDK_LIB_LIST += event_nbd nbd

View File

@ -43,7 +43,7 @@ SPDK_LIB_LIST = $(ALL_MODULES_LIST)
SPDK_LIB_LIST += vhost rte_vhost event_vhost
SPDK_LIB_LIST += event_bdev event_copy event_net event_scsi event
SPDK_LIB_LIST += jsonrpc json rpc bdev_rpc bdev scsi copy trace conf
SPDK_LIB_LIST += thread util log log_rpc app_rpc
SPDK_LIB_LIST += thread util log log_rpc trace_rpc app_rpc
SPDK_LIB_LIST += event_nbd nbd net sock
include $(SPDK_ROOT_DIR)/mk/spdk.app.mk

View File

@ -275,6 +275,13 @@ uint64_t spdk_trace_get_tpoint_group_mask(void);
*/
void spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask);
/**
* For each tpoint group specified in the group mask, disable all of its tpoints.
*
* \param tpoint_group_mask Tpoint group mask that indicates which tpoints to disable.
*/
void spdk_trace_clear_tpoint_group_mask(uint64_t tpoint_group_mask);
/**
* Initialize the trace environment. Debug tool can read the information from
* the given shared memory to post-process the tpoint entries and display in a
@ -332,6 +339,27 @@ void spdk_trace_register_description(const char *name, const char *short_name,
uint8_t object_type, uint8_t new_object,
uint8_t arg1_is_ptr, const char *arg1_name);
struct spdk_trace_register_fn *spdk_trace_get_first_register_fn(void);
struct spdk_trace_register_fn *spdk_trace_get_next_register_fn(struct spdk_trace_register_fn
*register_fn);
/**
* Enable trace on specific tpoint group
*
* \param group_name Name of group to enable, "all" for enabling all groups.
* \return 0 on success, else non-zero indicates a failure.
*/
int spdk_trace_enable_tpoint_group(const char *group_name);
/**
* Disable trace on specific tpoint group
*
* \param group_name Name of group to disable, "all" for disabling all groups.
* \return 0 on success, else non-zero indicates a failure.
*/
int spdk_trace_disable_tpoint_group(const char *group_name);
/**
* Show trace mask and its usage.
*

View File

@ -37,4 +37,6 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
C_SRCS = trace.c trace_flags.c
LIBNAME = trace
DIRS-y = rpc
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk

40
lib/trace/rpc/Makefile Normal file
View File

@ -0,0 +1,40 @@
#
# BSD LICENSE
#
# Copyright (c) Intel Corporation.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Intel Corporation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
C_SRCS = trace_rpc.c
LIBNAME = trace_rpc
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk

179
lib/trace/rpc/trace_rpc.c Normal file
View File

@ -0,0 +1,179 @@
/*-
* BSD LICENSE
*
* Copyright (c) Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "spdk/rpc.h"
#include "spdk/util.h"
#include "spdk/trace.h"
#include "spdk_internal/log.h"
struct rpc_tpoint_group {
char *name;
};
static void
free_rpc_tpoint_group(struct rpc_tpoint_group *p)
{
free(p->name);
}
static const struct spdk_json_object_decoder rpc_tpoint_group_decoders[] = {
{"name", offsetof(struct rpc_tpoint_group, name), spdk_json_decode_string},
};
static void
spdk_rpc_enable_tpoint_group(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_tpoint_group req = {};
struct spdk_json_write_ctx *w;
if (spdk_json_decode_object(params, rpc_tpoint_group_decoders,
SPDK_COUNTOF(rpc_tpoint_group_decoders), &req)) {
SPDK_DEBUGLOG(SPDK_LOG_TRACE, "spdk_json_decode_object failed\n");
goto invalid;
}
if (req.name == NULL) {
SPDK_DEBUGLOG(SPDK_LOG_TRACE, "flag was NULL\n");
goto invalid;
}
if (spdk_trace_enable_tpoint_group(req.name)) {
goto invalid;
}
free_rpc_tpoint_group(&req);
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return;
}
spdk_json_write_bool(w, true);
spdk_jsonrpc_end_result(request, w);
return;
invalid:
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
free_rpc_tpoint_group(&req);
}
SPDK_RPC_REGISTER("enable_tpoint_group", spdk_rpc_enable_tpoint_group,
SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
static void
spdk_rpc_disable_tpoint_group(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_tpoint_group req = {};
struct spdk_json_write_ctx *w;
if (spdk_json_decode_object(params, rpc_tpoint_group_decoders,
SPDK_COUNTOF(rpc_tpoint_group_decoders), &req)) {
SPDK_DEBUGLOG(SPDK_LOG_TRACE, "spdk_json_decode_object failed\n");
goto invalid;
}
if (req.name == NULL) {
SPDK_DEBUGLOG(SPDK_LOG_TRACE, "flag was NULL\n");
goto invalid;
}
if (spdk_trace_disable_tpoint_group(req.name)) {
goto invalid;
}
free_rpc_tpoint_group(&req);
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return;
}
spdk_json_write_bool(w, true);
spdk_jsonrpc_end_result(request, w);
return;
invalid:
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
free_rpc_tpoint_group(&req);
}
SPDK_RPC_REGISTER("disable_tpoint_group", spdk_rpc_disable_tpoint_group,
SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
static void
spdk_rpc_get_tpoint_group_mask(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
uint64_t tpoint_group_mask;
char mask_str[7];
bool enabled;
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,
"get_tpoint_group_mask requires no parameters");
return;
}
w = spdk_jsonrpc_begin_result(request);
if (w == NULL) {
return;
}
tpoint_group_mask = spdk_trace_get_tpoint_group_mask();
spdk_json_write_object_begin(w);
snprintf(mask_str, sizeof(mask_str), "0x%lx", 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) {
enabled = spdk_trace_get_tpoint_mask(register_fn->tgroup_id) != 0;
spdk_json_write_named_object_begin(w, register_fn->name);
spdk_json_write_named_bool(w, "enabled", enabled);
snprintf(mask_str, sizeof(mask_str), "0x%lx", (1UL << register_fn->tgroup_id));
spdk_json_write_named_string(w, "mask", 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("get_tpoint_group_mask", spdk_rpc_get_tpoint_group_mask,
SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)

View File

@ -162,17 +162,26 @@ void
spdk_trace_cleanup(void)
{
bool unlink;
int i;
struct spdk_trace_history *lcore_history;
if (g_trace_histories == NULL) {
return;
}
/*
* Only unlink the shm if there were no tracepoints enabled. This ensures the file
* Only unlink the shm if there were no trace_entry recorded. This ensures the file
* can be used after this process exits/crashes for debugging.
* Note that we have to calculate this value before g_trace_histories gets unmapped.
*/
unlink = spdk_mem_all_zero(g_trace_flags->tpoint_mask, sizeof(g_trace_flags->tpoint_mask));
for (i = 0; i < SPDK_TRACE_MAX_LCORE; i++) {
lcore_history = spdk_get_per_lcore_history(g_trace_histories, i);
unlink = lcore_history->entries[0].tsc == 0;
if (!unlink) {
break;
}
}
munmap(g_trace_histories, sizeof(struct spdk_trace_histories));
g_trace_histories = NULL;
close(g_trace_fd);

View File

@ -36,10 +36,13 @@
#include "spdk/env.h"
#include "spdk/trace.h"
#include "spdk/log.h"
#include "spdk_internal/log.h"
struct spdk_trace_flags *g_trace_flags = NULL;
static struct spdk_trace_register_fn *g_reg_fn_head = NULL;
SPDK_LOG_REGISTER_COMPONENT("trace", SPDK_LOG_TRACE)
uint64_t
spdk_trace_get_tpoint_mask(uint32_t group_id)
{
@ -100,6 +103,88 @@ spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask)
}
}
void
spdk_trace_clear_tpoint_group_mask(uint64_t tpoint_group_mask)
{
int i;
for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) {
if (tpoint_group_mask & (1ULL << i)) {
spdk_trace_clear_tpoints(i, -1ULL);
}
}
}
struct spdk_trace_register_fn *
spdk_trace_get_first_register_fn(void)
{
return g_reg_fn_head;
}
struct spdk_trace_register_fn *
spdk_trace_get_next_register_fn(struct spdk_trace_register_fn *register_fn)
{
return register_fn->next;
}
static uint64_t
trace_create_tpoint_group_mask(const char *group_name)
{
uint64_t tpoint_group_mask = 0;
struct spdk_trace_register_fn *register_fn;
register_fn = spdk_trace_get_first_register_fn();
if (strcmp(group_name, "all") == 0) {
while (register_fn) {
tpoint_group_mask |= (1UL << register_fn->tgroup_id);
register_fn = spdk_trace_get_next_register_fn(register_fn);
}
} else {
while (register_fn) {
if (strcmp(group_name, register_fn->name) == 0) {
break;
}
register_fn = spdk_trace_get_next_register_fn(register_fn);
}
if (register_fn != NULL) {
tpoint_group_mask |= (1UL << register_fn->tgroup_id);
}
}
return tpoint_group_mask;
}
int
spdk_trace_enable_tpoint_group(const char *group_name)
{
uint64_t tpoint_group_mask = 0;
tpoint_group_mask = trace_create_tpoint_group_mask(group_name);
if (tpoint_group_mask == 0) {
return -1;
}
spdk_trace_set_tpoint_group_mask(tpoint_group_mask);
return 0;
}
int
spdk_trace_disable_tpoint_group(const char *group_name)
{
uint64_t tpoint_group_mask = 0;
tpoint_group_mask = trace_create_tpoint_group_mask(group_name);
if (tpoint_group_mask == 0) {
return -1;
}
spdk_trace_clear_tpoint_group_mask(tpoint_group_mask);
return 0;
}
void
spdk_trace_mask_usage(FILE *f, const char *tmask_arg)
{
@ -186,6 +271,12 @@ spdk_trace_add_register_fn(struct spdk_trace_register_fn *reg_fn)
return;
}
if (strcmp(reg_fn->name, "all") == 0) {
SPDK_ERRLOG("illegal name (%s) for tpoint group\n", reg_fn->name);
assert(false);
return;
}
/* Ensure that no trace point group IDs and names are ever duplicated */
for (_reg_fn = g_reg_fn_head; _reg_fn; _reg_fn = _reg_fn->next) {
if (reg_fn->tgroup_id == _reg_fn->tgroup_id) {

View File

@ -890,6 +890,31 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
p = subparsers.add_parser('get_scsi_devices', help='Display SCSI devices')
p.set_defaults(func=get_scsi_devices)
# trace
def enable_tpoint_group(args):
rpc.trace.enable_tpoint_group(args.client, name=args.name)
p = subparsers.add_parser('enable_tpoint_group', help='enable trace on a specific tpoint group')
p.add_argument(
'name', help="""trace group name we want to enable in tpoint_group_mask.
(for example "bdev" for bdev trace group, "all" for all trace groups).""")
p.set_defaults(func=enable_tpoint_group)
def disable_tpoint_group(args):
rpc.trace.disable_tpoint_group(args.client, name=args.name)
p = subparsers.add_parser('disable_tpoint_group', help='disable trace on a specific tpoint group')
p.add_argument(
'name', help="""trace group name we want to disable in tpoint_group_mask.
(for example "bdev" for bdev trace group, "all" for all trace groups).""")
p.set_defaults(func=disable_tpoint_group)
def get_tpoint_group_mask(args):
print_dict(rpc.trace.get_tpoint_group_mask(args.client))
p = subparsers.add_parser('get_tpoint_group_mask', help='get trace point group mask')
p.set_defaults(func=get_tpoint_group_mask)
# log
def set_log_flag(args):
rpc.log.set_log_flag(args.client, flag=args.flag)

View File

@ -13,6 +13,7 @@ from . import nvme
from . import nvmf
from . import pmem
from . import subsystem
from . import trace
from . import vhost
from . import client as rpc_client

27
scripts/rpc/trace.py Normal file
View File

@ -0,0 +1,27 @@
def enable_tpoint_group(client, name):
"""Enable trace on a specific tpoint group.
Args:
name: trace group name we want to enable in tpoint_group_mask. (for example "bdev").
"""
params = {'name': name}
return client.call('enable_tpoint_group', params)
def disable_tpoint_group(client, name):
"""Disable trace on a specific tpoint group.
Args:
name: trace group name we want to disable in tpoint_group_mask. (for example "bdev").
"""
params = {'name': name}
return client.call('disable_tpoint_group', params)
def get_tpoint_group_mask(client):
"""Get trace point group mask
Returns:
List of trace point group mask
"""
return client.call('get_tpoint_group_mask')

View File

@ -42,7 +42,7 @@ C_SRCS := bdev_svc.c
SPDK_LIB_LIST = $(ALL_MODULES_LIST)
SPDK_LIB_LIST += event_bdev event_copy
SPDK_LIB_LIST += nvmf event log trace conf thread util bdev copy rpc jsonrpc json sock
SPDK_LIB_LIST += app_rpc log_rpc bdev_rpc
SPDK_LIB_LIST += app_rpc log_rpc trace_rpc bdev_rpc
ifeq ($(OS),Linux)
SPDK_LIB_LIST += event_nbd nbd