xref: /spdk/module/env_dpdk/env_dpdk_rpc.c (revision 45a053c5777494f4e8ce4bc1191c9de3920377f7)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2019 Intel Corporation. All rights reserved.
3  *   Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
4  */
5 
6 #include "spdk/stdinc.h"
7 #include "spdk/rpc.h"
8 #include "spdk/env_dpdk.h"
9 #include "spdk/log.h"
10 
11 static void
12 rpc_env_dpdk_get_mem_stats(struct spdk_jsonrpc_request *request,
13 			   const struct spdk_json_val *params)
14 {
15 	FILE *file = NULL;
16 	struct spdk_json_write_ctx *w;
17 	char default_filename[] = "/tmp/spdk_mem_dump.txt";
18 
19 	if (params != NULL) {
20 		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
21 						 "env_dpdk_get_mem_stats doesn't accept any parameters.\n");
22 		return;
23 	}
24 
25 	file = fopen(default_filename, "w");
26 	if (!file) {
27 		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
28 						 "Unable to open file for writing.\n");
29 		return;
30 	}
31 
32 	spdk_env_dpdk_dump_mem_stats(file);
33 	fclose(file);
34 	w = spdk_jsonrpc_begin_result(request);
35 	spdk_json_write_object_begin(w);
36 	spdk_json_write_named_string(w, "filename", default_filename);
37 	spdk_json_write_object_end(w);
38 	spdk_jsonrpc_end_result(request, w);
39 }
40 SPDK_RPC_REGISTER("env_dpdk_get_mem_stats", rpc_env_dpdk_get_mem_stats, SPDK_RPC_RUNTIME)
41