## some trouble shooting tips on remote linux server
- find project depency
- in case we want to change code of dependency libs directly on remote server and quick testing. taking zkevm-circuit as example, find zkevm-circuit project depency location, check the repo's cargo.lock. if the depency lib is `halo2_proofs` as following:
- search local cargo cache file for target repo. there are usually some versions of dependency for long time run. in above cargo lock info, current version of `halo2_proof` being using is commit starting with `a244**`.
type command:
`find .cargo/git/checkouts/halo2* -name "a244*"` 
- go to cached repo in destinatination folder getting from last step. and find code file you want to change locally, such as `.cargo/git/checkouts/halo2-189ea3cf7f17e3ad/a244c33/src/dev.rs`. edit it by your favourite editor. BTW, I like `vim` whose shortcuts are convinent.
- to make local changes come into effect, `cargo clean` first, then `cargo build`. otherwise new changes to local file can not work.
- start your normal work.
- useful memory code snippets
- get current process memory, this is often the most useful commom case:
```
fn get_current_process_memory_size() -> Result<(usize, usize), Box<dynstd::error::Error>> {
use std::{fs::File,
io::{BufReader, BufRead, Lines},
process,
str::FromStr,
};
fn parse_size(size_str: &str) -> Result<usize, Box<dyn std::error::Error>> {
let size_kb: usize = usize::from_str(size_str)?;
Ok(size_kb * 1024) // 转换为字节
}
let pid = process::id();
// only can use on Linux ?
let status_path = format! ("/proc/{}/status", pid);
let file = File::open(status_path)?;
let reader = BufReader::new(file);
let mut vm_size = 0;
let mut vm_rss = 0;
for line in reader.lines() {
let line = line?;
if line.starts_with("VmSize:") {
let size_str = line.split_whitespace().nth(1).unwrap();
vm_size = parse_size(size_str)?;
} else if line.starts_with("VmRSS:") {
let size_str = line.split_whitespace().nth(1).unwrap();
vm_rss = parse_size(size_str)?;
}
if vm_size > 0 && vm_rss > 0 {
break; // find it and stop query.
}
}
if vm_size == 0 || vm_rss == 0 {
println!("Failed to find VmSize or VmRSS in /proc/[pid]/status");
return Err("Failed to find VmSize or VmRSS in /proc/[pid]/status".into());
}
Ok((vm_size, vm_rss))
}
```
below codes shows how to call above codes.
```
let (vm_size, vm_rss) = get_current_process_memory_size().expect("can not get current
process memory info");
log::debug!(
"memory usage vm_size {} GB : vm_rss: {:?}GB",
_i, vm_size / 1024 / 1024 / 1024, vm_rss / 1024 / 1024 / 1024,
);
```
sometimes we need to monitor more precise memory number, i.e. in M bytes instead of G bytes. change log line by removing one division by 1024.
```
log::debug!(
"memory usage vm_size {} MB : vm_rss: {:?}MB",
_i, vm_size / 1024 / 1024, vm_rss / 1024 / 1024 ,
);
```
- check overall memory info
- add dependency in cargo.toml: ` procfs = "0.7"`
- add following code where want to check in your codes.
```
pub fn memory_tick(desc: &str) {
#[cfg(target_os = "linux")]
let memory = match procfs::Meminfo::new() {
Ok(m) => m.mem_total - m.mem_free,
Err(_) => 0,
};
#[cfg(not(target_os = "linux"))]
let memory = 0;
log::debug!(
"memory usage when {}: {:?}GB",
desc,
memory / 1024 / 1024 / 1024
);
}
```