Sha256: 9b8f5fe70fadaadea6a5148407652c48558226d4781a48208a802eebc788c1d9

Contents?: true

Size: 1.58 KB

Versions: 44

Compression:

Stored size: 1.58 KB

Contents

#!/bin/bash

# This script monitors and records the Resident Set Size (RSS) of a process given its PID.
# The RSS is logged every second to the specified output file until the process terminates.
#
# Usage:
# ./script_name.sh <PID> <OUTPUT_FILE>
#
# Arguments:
# <PID>         - Process ID of the process you want to monitor.
# <OUTPUT_FILE> - Name of the file where RSS values will be logged.
#
# The script first checks if the correct number of arguments are provided.
# It then verifies if the given PID exists. If it does, it starts recording the RSS.
# For every iteration, the script fetches the current RSS of the process using the 'ps' command,
# then appends the RSS value along with a timestamp to the output file.
# This recording is done every second.
# The loop stops if the process with the given PID terminates.
# An informative message is printed out when recording starts and when it stops.

# Check if the correct number of arguments are passed
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 <PID> <OUTPUT_FILE>"
    exit 1
fi

PID=$1
OUTPUT_FILE=$2

# Check if the given PID exists
if ! kill -0 $PID 2>/dev/null; then
    echo "Error: PID $PID does not exist."
    exit 1
fi

# Start recording the RSS
echo "Recording RSS for PID $PID every second to $OUTPUT_FILE..."

while kill -0 $PID 2>/dev/null; do
    RSS=$(ps -o rss= -p $PID)
    if [ -z "$RSS" ]; then
        echo "Error: Failed to get RSS for PID $PID."
        exit 1
    fi
    TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
    echo "$TIMESTAMP: $RSS KB" >> $OUTPUT_FILE
    sleep 1
done

echo "Process $PID has terminated. Stopping recording."

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
karafka-2.4.17 bin/record_rss
karafka-2.4.16 bin/record_rss
karafka-2.4.15 bin/record_rss
karafka-2.4.14 bin/record_rss
karafka-2.4.13 bin/record_rss
karafka-2.4.12 bin/record_rss
karafka-2.4.11 bin/record_rss
karafka-2.4.10 bin/record_rss
karafka-2.4.9 bin/record_rss
karafka-2.4.8 bin/record_rss
karafka-2.4.7 bin/record_rss
karafka-2.4.6 bin/record_rss
karafka-2.4.5 bin/record_rss
karafka-2.4.4 bin/record_rss
karafka-2.4.3 bin/record_rss
karafka-2.4.0 bin/record_rss
karafka-2.4.0.rc1 bin/record_rss
karafka-2.3.4 bin/record_rss
karafka-2.4.0.beta2 bin/record_rss
karafka-2.4.0.beta1 bin/record_rss