LCOV - code coverage report
Current view: top level - spdk/module/env_dpdk - env_dpdk_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 14 18 77.8 %
Date: 2024-07-15 10:20:08 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 4 50.0 %

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

Generated by: LCOV version 1.14