-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-profiling.sh
More file actions
42 lines (37 loc) · 1.23 KB
/
process-profiling.sh
File metadata and controls
42 lines (37 loc) · 1.23 KB
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
35
36
37
38
39
40
41
42
#!/bin/bash
if [ ! -n "$1" ]; then
echo ""
echo "Usage: $0 <process ID> <INTERVAL>"
exit 1
fi
profile_process_pid=$1
# Output file in /tmp
OUTPUT_FILE="/tmp/top_pthreads_profile_$profile_process_pid.txt"
SMAP_OUTPUT_FILE="/tmp/process_smaps_dump_$profile_process_pid.txt"
Task_SMAP_OUTPUT_FILE="/tmp/task_smaps_dump_$profile_process_pid.txt"
# Interval in seconds
if [ ! -n "$2" ]; then
INTERVAL=5
else
INTERVAL=$2
fi
if [ -n $profile_process_pid ]; then
# Clear the output file at the beginning
> $OUTPUT_FILE
> $SMAP_OUTPUT_FILE
> $Task_SMAP_OUTPUT_FILE
# Infinite loop to capture top output every INTERVAL seconds
while true; do
echo "Start Profiling"
echo "Timestamp: $(date)" >> $OUTPUT_FILE
top -H -b -n 1 -p $profile_process_pid >> $OUTPUT_FILE
echo "========================================" >> $OUTPUT_FILE
echo "Timestamp: $(date)" >> $SMAP_OUTPUT_FILE
#./calculate_private_dirty_memory.sh $profile_process_pid >> $OUTPUT_FILE
cat /proc/$profile_process_pid/smaps >> $SMAP_OUTPUT_FILE
echo "========================================" >> $SMAP_OUTPUT_FILE
./task-profiling.sh $profile_process_pid
echo "profiling done"
sleep $INTERVAL
done
fi