Branch data 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 : 19 : rpc_env_dpdk_get_mem_stats(struct spdk_jsonrpc_request *request, 13 : : const struct spdk_json_val *params) 14 : : { 15 : 19 : FILE *file = NULL; 16 : : struct spdk_json_write_ctx *w; 17 : 19 : char default_filename[] = "/tmp/spdk_mem_dump.txt"; 18 : : 19 [ - + ]: 19 : 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 : 19 : file = fopen(default_filename, "w"); 26 [ - + ]: 19 : 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 : 19 : spdk_env_dpdk_dump_mem_stats(file); 33 : 19 : fclose(file); 34 : 19 : w = spdk_jsonrpc_begin_result(request); 35 : 19 : spdk_json_write_object_begin(w); 36 : 19 : spdk_json_write_named_string(w, "filename", default_filename); 37 : 19 : spdk_json_write_object_end(w); 38 : 19 : spdk_jsonrpc_end_result(request, w); 39 : : } 40 : 1359 : SPDK_RPC_REGISTER("env_dpdk_get_mem_stats", rpc_env_dpdk_get_mem_stats, SPDK_RPC_RUNTIME)