increase heap for mtxcli; add memory usage reporting

This commit is contained in:
bunnie 2022-12-28 19:48:40 +08:00
parent ac1df054ab
commit 8d42feb051
3 changed files with 47 additions and 1 deletions

View file

@ -620,3 +620,16 @@ pub fn tokenize(line: &mut XousString::<1024>) -> Option<XousString::<1024>> {
None
}
}
pub(crate) fn heap_usage() -> usize {
match xous::rsyscall(xous::SysCall::IncreaseHeap(0, xous::MemoryFlags::R)).expect("couldn't get heap size") {
xous::Result::MemoryRange(m) => {
let usage = m.len();
usage
}
_ => {
log::error!("Couldn't measure heap usage");
0
},
}
}

View file

@ -330,6 +330,7 @@ pub fn get_filter(user: &str, server: &str, token: &str) -> Option<String> {
}
fn get_messages(body: Map<String, Value>, room_id: &str) -> String {
log::debug!("heap usage: {}", crate::cmds::heap_usage());
let mut messages = String::new();
if let Some(Value::Object(rooms)) = body.get("rooms") {
if let Some(Value::Object(join)) = rooms.get("join") {
@ -371,6 +372,7 @@ fn get_messages(body: Map<String, Value>, room_id: &str) -> String {
pub fn client_sync(server: &str, filter: &str, since: &str, timeout: i32,
room_id: &str, token: &str) -> Option<(String, String)> {
log::debug!("heap usage: {}", crate::cmds::heap_usage());
let mut url = String::from(server);
url.push_str("/_matrix/client/r0/sync?filter=");
url.push_str(filter);
@ -417,6 +419,7 @@ impl MessageRequest {
}
pub fn send_message(server: &str, room_id: &str, text: &str, txn_id: &str, token: &str) -> bool {
log::debug!("heap usage: {}", crate::cmds::heap_usage());
let room_id_encoded = url::encode(room_id);
let mut url = String::from(server);
url.push_str("/_matrix/client/r0/rooms/");

View file

@ -23,11 +23,41 @@ pub(crate) enum MtxcliOp {
// This name should be (1) unique (2) under 64 characters long and (3) ideally descriptive.
pub(crate) const SERVER_NAME_MTXCLI: &str = "_Matrix chat_";
fn main() -> ! {
fn main () -> ! {
let stack_size = 1024 * 1024;
std::thread::Builder::new()
.stack_size(stack_size)
.spawn(wrapped_main)
.unwrap()
.join()
.unwrap()
}
fn wrapped_main() -> ! {
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Info);
log::info!("my PID is {}", xous::process::id());
const HEAP_LARGER_LIMIT: usize = 2048 * 1024;
let new_limit = HEAP_LARGER_LIMIT;
let result = xous::rsyscall(xous::SysCall::AdjustProcessLimit(
xous::Limits::HeapMaximum as usize,
0,
new_limit,
));
if let Ok(xous::Result::Scalar2(1, current_limit)) = result {
xous::rsyscall(xous::SysCall::AdjustProcessLimit(
xous::Limits::HeapMaximum as usize,
current_limit,
new_limit,
))
.unwrap();
log::info!("Heap limit increased to: {}", new_limit);
} else {
panic!("Unsupported syscall!");
}
let xns = xous_names::XousNames::new().unwrap();
// unlimited connections allowed, this is a user app and it's up to the app to decide its policy
let sid = xns.register_name(SERVER_NAME_MTXCLI, None).expect("can't register server");