1 /* cmd_global_meminfo.c - NeonServ v5.3
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_global.h"
19 #include "memoryInfo.h"
25 CMD_BIND(global_cmd_meminfo) {
26 #ifndef ENABLE_MEMORY_DEBUG
27 reply(getTextBot(), user, "NS_MEMINFO_DISABLED");
32 struct memoryInfoLines *element, *elements;
33 elements = getMemoryInfoLines(argv[0]);
34 for(element = elements; element; element = element->next) {
37 table = table_init(4, elementcount+2, 0);
39 content[0] = get_language_string(user, "NS_MEMINFO_LINE");
40 content[1] = get_language_string(user, "NS_MEMINFO_COUNT");
41 content[2] = get_language_string(user, "NS_MEMINFO_SIZE");
42 content[3] = get_language_string(user, "NS_MEMINFO_TOTAL");
43 table_add(table, content);
48 unsigned int total_allocations = 0;
49 unsigned int total_allocated = 0;
50 for(element = elements; element; element = element->next) {
51 sprintf(lineBuf, "%u", element->line);
53 sprintf(countBuf, "%u", element->allocations);
54 total_allocations += element->allocations;
55 content[1] = countBuf;
56 sprintf(sizeBuf, "%uB", element->allocate);
58 sprintf(totalBuf, "%u (%.2f kB)", (element->allocate * element->allocations), ((float)(element->allocate * element->allocations) / 1024));
59 total_allocated += (element->allocate * element->allocations);
60 content[3] = totalBuf;
61 table_add(table, content);
64 sprintf(countBuf, "%u", total_allocations);
65 content[1] = countBuf;
67 sprintf(sizeBuf, "%u (%.2f kB)", total_allocated, ((float)total_allocated / 1024));
69 table_add(table, content);
70 char **table_lines = table_end(table);
72 for(i = 0; i < table->entrys; i++) {
73 reply(getTextBot(), user, table_lines[i]);
79 struct memoryInfoFiles *element, *elements;
80 elements = getMemoryInfoFiles();
81 for(element = elements; element; element = element->next) {
84 table = table_init(3, elementcount+2, 0);
86 content[0] = get_language_string(user, "NS_MEMINFO_NAME");
87 content[1] = get_language_string(user, "NS_MEMINFO_COUNT");
88 content[2] = get_language_string(user, "NS_MEMINFO_SIZE");
89 table_add(table, content);
92 unsigned int total_allocations = 0;
93 unsigned int total_allocated = 0;
94 for(element = elements; element; element = element->next) {
95 content[0] = element->filename;
96 sprintf(countBuf, "%u", element->allocations);
97 total_allocations += element->allocations;
98 content[1] = countBuf;
99 sprintf(sizeBuf, "%u (%.2f kB)", element->allocated, ((float)element->allocated / 1024));
100 total_allocated += element->allocated;
101 content[2] = sizeBuf;
102 table_add(table, content);
104 content[0] = "Total";
105 sprintf(countBuf, "%u", total_allocations);
106 content[1] = countBuf;
107 sprintf(sizeBuf, "%u (%.2f kB)", total_allocated, ((float)total_allocated / 1024));
108 content[2] = sizeBuf;
109 table_add(table, content);
110 char **table_lines = table_end(table);
112 for(i = 0; i < table->entrys; i++) {
113 reply(getTextBot(), user, table_lines[i]);