lib/log: add RPC to toggle timestamps
Allow toggling log timestamps on and off by adding new RPC call. Change-Id: I34c84bf89fae352ade266fbf7fd20594ff67bced Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2024 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
cf99beb87e
commit
d267d0e874
@ -708,6 +708,41 @@ Example response:
|
|||||||
}
|
}
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
## log_enable_timestamps {#rpc_log_enable_timestamps}
|
||||||
|
|
||||||
|
Enable or disable timestamps.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Optional | Type | Description
|
||||||
|
----------------------- | -------- | ----------- | -----------
|
||||||
|
enabled | Required | boolean | on or off
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
Example request:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "log_enable_timestamps",
|
||||||
|
"id": 1,
|
||||||
|
"params": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
|
||||||
|
Example response:
|
||||||
|
|
||||||
|
~~~
|
||||||
|
{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"id": 1,
|
||||||
|
"result": true
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
|
||||||
## thread_get_pollers {#rpc_thread_get_pollers}
|
## thread_get_pollers {#rpc_thread_get_pollers}
|
||||||
|
|
||||||
Retrieve current pollers of all the threads.
|
Retrieve current pollers of all the threads.
|
||||||
|
@ -70,6 +70,11 @@ void spdk_log_open(logfunc *logf);
|
|||||||
*/
|
*/
|
||||||
void spdk_log_close(void);
|
void spdk_log_close(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable timestamps
|
||||||
|
*/
|
||||||
|
void spdk_log_enable_timestamps(bool value);
|
||||||
|
|
||||||
enum spdk_log_level {
|
enum spdk_log_level {
|
||||||
/** All messages will be suppressed. */
|
/** All messages will be suppressed. */
|
||||||
SPDK_LOG_DISABLED = -1,
|
SPDK_LOG_DISABLED = -1,
|
||||||
|
@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
|||||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||||
|
|
||||||
SO_VER := 3
|
SO_VER := 3
|
||||||
SO_MINOR := 0
|
SO_MINOR := 1
|
||||||
SO_SUFFIX := $(SO_VER).$(SO_MINOR)
|
SO_SUFFIX := $(SO_VER).$(SO_MINOR)
|
||||||
|
|
||||||
C_SRCS = log.c log_flags.c
|
C_SRCS = log.c log_flags.c
|
||||||
|
@ -46,6 +46,7 @@ static const char *const spdk_level_names[] = {
|
|||||||
#define MAX_TMPBUF 1024
|
#define MAX_TMPBUF 1024
|
||||||
|
|
||||||
static logfunc *g_log = NULL;
|
static logfunc *g_log = NULL;
|
||||||
|
static bool g_log_timestamps = true;
|
||||||
|
|
||||||
void
|
void
|
||||||
spdk_log_open(logfunc *logf)
|
spdk_log_open(logfunc *logf)
|
||||||
@ -65,6 +66,12 @@ spdk_log_close(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
spdk_log_enable_timestamps(bool value)
|
||||||
|
{
|
||||||
|
g_log_timestamps = value;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_timestamp_prefix(char *buf, int buf_size)
|
get_timestamp_prefix(char *buf, int buf_size)
|
||||||
{
|
{
|
||||||
@ -73,6 +80,11 @@ get_timestamp_prefix(char *buf, int buf_size)
|
|||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
long usec;
|
long usec;
|
||||||
|
|
||||||
|
if (!g_log_timestamps) {
|
||||||
|
buf[0] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
info = localtime(&ts.tv_sec);
|
info = localtime(&ts.tv_sec);
|
||||||
usec = ts.tv_nsec / 1000;
|
usec = ts.tv_nsec / 1000;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
spdk_log_set_flag;
|
spdk_log_set_flag;
|
||||||
spdk_log_clear_flag;
|
spdk_log_clear_flag;
|
||||||
spdk_log_usage;
|
spdk_log_usage;
|
||||||
|
spdk_log_enable_timestamps;
|
||||||
|
|
||||||
# functions used by other SPDK libraries
|
# functions used by other SPDK libraries
|
||||||
spdk_log_register_flag;
|
spdk_log_register_flag;
|
||||||
|
@ -540,4 +540,36 @@ err:
|
|||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
SPDK_RPC_REGISTER("thread_set_cpumask", rpc_thread_set_cpumask, SPDK_RPC_RUNTIME)
|
SPDK_RPC_REGISTER("thread_set_cpumask", rpc_thread_set_cpumask, SPDK_RPC_RUNTIME)
|
||||||
|
|
||||||
|
struct rpc_log_enable_timestamps {
|
||||||
|
bool enabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct spdk_json_object_decoder rpc_log_enable_timestamps_decoders[] = {
|
||||||
|
{"enabled", offsetof(struct rpc_log_enable_timestamps, enabled), spdk_json_decode_bool},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
rpc_log_enable_timestamps(struct spdk_jsonrpc_request *request,
|
||||||
|
const struct spdk_json_val *params)
|
||||||
|
{
|
||||||
|
struct rpc_log_enable_timestamps req = {};
|
||||||
|
struct spdk_json_write_ctx *w;
|
||||||
|
|
||||||
|
if (spdk_json_decode_object(params, rpc_log_enable_timestamps_decoders,
|
||||||
|
SPDK_COUNTOF(rpc_log_enable_timestamps_decoders),
|
||||||
|
&req)) {
|
||||||
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
||||||
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||||
|
"spdk_json_decode_object failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
spdk_log_enable_timestamps(req.enabled);
|
||||||
|
|
||||||
|
w = spdk_jsonrpc_begin_result(request);
|
||||||
|
spdk_json_write_bool(w, true);
|
||||||
|
spdk_jsonrpc_end_result(request, w);
|
||||||
|
}
|
||||||
|
SPDK_RPC_REGISTER("log_enable_timestamps", rpc_log_enable_timestamps, SPDK_RPC_RUNTIME)
|
||||||
SPDK_LOG_REGISTER_COMPONENT("APP_RPC", SPDK_LOG_APP_RPC)
|
SPDK_LOG_REGISTER_COMPONENT("APP_RPC", SPDK_LOG_APP_RPC)
|
||||||
|
@ -2411,6 +2411,15 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
|||||||
p.add_argument('-m', '--cpumask', help='cpumask for this thread')
|
p.add_argument('-m', '--cpumask', help='cpumask for this thread')
|
||||||
p.set_defaults(func=thread_set_cpumask)
|
p.set_defaults(func=thread_set_cpumask)
|
||||||
|
|
||||||
|
def log_enable_timestamps(args):
|
||||||
|
ret = rpc.app.log_enable_timestamps(args.client,
|
||||||
|
enabled=args.enabled)
|
||||||
|
p = subparsers.add_parser('log_enable_timestamps',
|
||||||
|
help='Enable or disable timestamps.')
|
||||||
|
p.add_argument('-d', '--disable', dest='enabled', default=False, action='store_false', help="Disable timestamps")
|
||||||
|
p.add_argument('-e', '--enable', dest='enabled', action='store_true', help="Enable timestamps")
|
||||||
|
p.set_defaults(func=log_enable_timestamps)
|
||||||
|
|
||||||
def thread_get_pollers(args):
|
def thread_get_pollers(args):
|
||||||
print_dict(rpc.app.thread_get_pollers(args.client))
|
print_dict(rpc.app.thread_get_pollers(args.client))
|
||||||
|
|
||||||
|
@ -60,6 +60,19 @@ def thread_set_cpumask(client, id, cpumask):
|
|||||||
return client.call('thread_set_cpumask', params)
|
return client.call('thread_set_cpumask', params)
|
||||||
|
|
||||||
|
|
||||||
|
def log_enable_timestamps(client, enabled):
|
||||||
|
"""Enable or disable timestamps.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value: on or off
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
params = {'enabled': enabled}
|
||||||
|
return client.call('log_enable_timestamps', params)
|
||||||
|
|
||||||
|
|
||||||
def thread_get_pollers(client):
|
def thread_get_pollers(client):
|
||||||
"""Query current pollers.
|
"""Query current pollers.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user