Skip to content

Commit 8d4f0af

Browse files
committed
[update] llm_sys add cmminfo
1 parent ce9e076 commit 8d4f0af

1 file changed

Lines changed: 65 additions & 1 deletion

File tree

projects/llm_framework/main_sys/src/event_loop.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
43
*
@@ -196,6 +195,70 @@ int sys_hwinfo(int com_id, const nlohmann::json &json_obj)
196195
return out;
197196
}
198197

198+
void get_mem_cmm_info(unsigned long *total_size, unsigned long *used, unsigned long *remain)
199+
{
200+
std::ifstream file("/proc/ax_proc/mem_cmm_info");
201+
std::vector<std::string> lines;
202+
std::string line;
203+
204+
while (std::getline(file, line)) {
205+
lines.push_back(line);
206+
}
207+
208+
if (!lines.empty()) {
209+
std::string last_line = lines.back();
210+
211+
size_t pos = last_line.find("total size=");
212+
if (pos != std::string::npos) {
213+
pos += 11;
214+
size_t end = last_line.find('K', pos);
215+
*total_size = std::stoul(last_line.substr(pos, end - pos));
216+
}
217+
218+
pos = last_line.find("used=");
219+
if (pos != std::string::npos) {
220+
pos += 5;
221+
size_t end = last_line.find('K', pos);
222+
*used = std::stoul(last_line.substr(pos, end - pos));
223+
}
224+
225+
pos = last_line.find("remain=");
226+
if (pos != std::string::npos) {
227+
pos += 7;
228+
size_t end = last_line.find('K', pos);
229+
*remain = std::stoul(last_line.substr(pos, end - pos));
230+
}
231+
}
232+
}
233+
234+
void _sys_cmminfo(int com_id, const nlohmann::json &json_obj)
235+
{
236+
unsigned long total_size, used, remain;
237+
get_mem_cmm_info(&total_size, &used, &remain);
238+
239+
nlohmann::json out_body;
240+
nlohmann::json data_body;
241+
out_body["request_id"] = json_obj["request_id"];
242+
out_body["work_id"] = std::string("sys");
243+
out_body["created"] = time(NULL);
244+
out_body["error"] = nlohmann::json::parse("{\"code\":0, \"message\":\"\"}");
245+
out_body["object"] = std::string("sys.cmminfo");
246+
data_body["total"] = total_size;
247+
data_body["used"] = used;
248+
data_body["remain"] = remain;
249+
out_body["data"] = data_body;
250+
std::string out = out_body.dump();
251+
zmq_com_send(com_id, out);
252+
}
253+
254+
int sys_cmminfo(int com_id, const nlohmann::json &json_obj)
255+
{
256+
int out = 0;
257+
std::thread t(_sys_cmminfo, com_id, json_obj);
258+
t.detach();
259+
return out;
260+
}
261+
199262
int sys_lsmode(int com_id, const nlohmann::json &json_obj)
200263
{
201264
int out;
@@ -643,6 +706,7 @@ void server_work()
643706
key_sql["sys.reboot"] = sys_reboot;
644707
key_sql["sys.version"] = sys_version;
645708
key_sql["sys.rmmode"] = sys_rmmode;
709+
key_sql["sys.cmminfo"] = sys_cmminfo;
646710
}
647711

648712
void server_stop_work()

0 commit comments

Comments
 (0)