Skip to content

Commit d823a79

Browse files
authored
Merge pull request #400 from mintyleaf/snapshot_rich_memory_output
add rich memory stats for snapshot option
2 parents 339ee0b + df62414 commit d823a79

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/interface.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*
2020
*/
2121

22-
#include "nvtop/interface.h"
2322
#include "nvtop/common.h"
2423
#include "nvtop/extract_gpuinfo_common.h"
24+
#include "nvtop/interface.h"
2525
#include "nvtop/interface_common.h"
2626
#include "nvtop/interface_internal_common.h"
2727
#include "nvtop/interface_layout_selection.h"
@@ -1716,7 +1716,7 @@ static unsigned populate_plot_data_from_ring_buffer(const struct nvtop_interface
17161716
assert(total_to_draw > 0);
17171717
assert(size_data_buff % total_to_draw == 0);
17181718
unsigned max_data_to_copy = size_data_buff / total_to_draw;
1719-
double(*data_split)[total_to_draw] = (double(*)[total_to_draw])data;
1719+
double (*data_split)[total_to_draw] = (double (*)[total_to_draw])data;
17201720

17211721
unsigned in_processing = 0;
17221722
for (unsigned i = 0; i < plot_win->num_devices_to_plot; ++i) {
@@ -2074,6 +2074,9 @@ void print_snapshot(struct list_head *devices, bool use_fahrenheit_option) {
20742074
const char *power_field = "power_draw";
20752075
const char *gpu_util_field = "gpu_util";
20762076
const char *mem_util_field = "mem_util";
2077+
const char *mem_total_field = "mem_total";
2078+
const char *mem_used_field = "mem_used";
2079+
const char *mem_free_field = "mem_free";
20772080

20782081
printf("%s{\n", indent_level_two);
20792082

@@ -2137,6 +2140,21 @@ void print_snapshot(struct list_head *devices, bool use_fahrenheit_option) {
21372140
printf("%s\"%s\": \"%u%%\"\n", indent_level_four, mem_util_field, device->dynamic_info.mem_util_rate);
21382141
else
21392142
printf("%s\"%s\": null\n", indent_level_four, mem_util_field);
2143+
// Memory Total
2144+
if (GPUINFO_DYNAMIC_FIELD_VALID(&device->dynamic_info, total_memory))
2145+
printf("%s\"%s\": \"%llu\"\n", indent_level_four, mem_total_field, device->dynamic_info.total_memory);
2146+
else
2147+
printf("%s\"%s\": null\n", indent_level_four, mem_total_field);
2148+
// Memory Used
2149+
if (GPUINFO_DYNAMIC_FIELD_VALID(&device->dynamic_info, used_memory))
2150+
printf("%s\"%s\": \"%llu\"\n", indent_level_four, mem_used_field, device->dynamic_info.used_memory);
2151+
else
2152+
printf("%s\"%s\": null\n", indent_level_four, mem_used_field);
2153+
// Memory Available
2154+
if (GPUINFO_DYNAMIC_FIELD_VALID(&device->dynamic_info, free_memory))
2155+
printf("%s\"%s\": \"%llu\"\n", indent_level_four, mem_free_field, device->dynamic_info.free_memory);
2156+
else
2157+
printf("%s\"%s\": null\n", indent_level_four, mem_free_field);
21402158

21412159
if (device->list.next == devices)
21422160
printf("%s}\n", indent_level_two);

0 commit comments

Comments
 (0)