-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-profiling.sh
More file actions
34 lines (27 loc) · 778 Bytes
/
task-profiling.sh
File metadata and controls
34 lines (27 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Function to read memory usage from smaps
read_memory_usage() {
local tid=$1
local smaps_file="/proc/$pid/task/$tid/smaps"
if [[ -f "$smaps_file" ]]; then
cat "$smaps_file" >> $SMAP_OUTPUT_FILE
fi
}
pid=$1
SMAP_OUTPUT_FILE="/tmp/task_smaps_dump_$pid.txt"
if [[ -z "$pid" ]]; then
echo "Usage: $0 <pid>"
exit 1
fi
if [[ ! -d "/proc/$pid/task" ]]; then
echo "Invalid PID or process does not exist."
exit 1
fi
echo "Memory usage for each thread in process $pid"
echo "Timestamp: $(date)" >> $SMAP_OUTPUT_FILE
for tid in /proc/$pid/task/*; do
tid=$(basename "$tid")
echo "Task ID: $tid" >> $SMAP_OUTPUT_FILE
read_memory_usage "$tid"
echo "========================================" >> $SMAP_OUTPUT_FILE
done