Line data Source code
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 0 : rpc_env_dpdk_get_mem_stats(struct spdk_jsonrpc_request *request, 13 : const struct spdk_json_val *params) 14 : { 15 0 : FILE *file = NULL; 16 : struct spdk_json_write_ctx *w; 17 0 : char default_filename[] = "/tmp/spdk_mem_dump.txt"; 18 : 19 0 : if (params != NULL) { 20 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 21 : "env_dpdk_get_mem_stats doesn't accept any parameters.\n"); 22 0 : return; 23 : } 24 : 25 0 : file = fopen(default_filename, "w"); 26 0 : if (!file) { 27 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, 28 : "Unable to open file for writing.\n"); 29 0 : return; 30 : } 31 : 32 0 : spdk_env_dpdk_dump_mem_stats(file); 33 0 : fclose(file); 34 0 : w = spdk_jsonrpc_begin_result(request); 35 0 : spdk_json_write_object_begin(w); 36 0 : spdk_json_write_named_string(w, "filename", default_filename); 37 0 : spdk_json_write_object_end(w); 38 0 : spdk_jsonrpc_end_result(request, w); 39 : } 40 0 : SPDK_RPC_REGISTER("env_dpdk_get_mem_stats", rpc_env_dpdk_get_mem_stats, SPDK_RPC_RUNTIME)