Update scripts to accept wolfSSL directory as argument
Co-Authored-By: jacob@wolfssl.com <jacob@wolfssl.com>devin/1741050294-optimize-memory-buckets
parent
abb76a4089
commit
6aa87008b2
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# compare_memory.sh
|
# compare_memory.sh
|
||||||
#
|
#
|
||||||
# Copyright (C) 2006-2025 wolfSSL Inc.
|
# Copyright (C) 2025 wolfSSL Inc.
|
||||||
#
|
#
|
||||||
# This file is part of wolfSSL.
|
# This file is part of wolfSSL.
|
||||||
#
|
#
|
||||||
|
@ -19,9 +19,27 @@
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
|
||||||
# Default values
|
# Get the directory of this script
|
||||||
WOLFSSL_DIR="../../../wolfssl"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
RESULTS_DIR="comparison_results"
|
|
||||||
|
# Check if wolfSSL directory is provided
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <wolfssl_dir>"
|
||||||
|
echo "Example: $0 ~/repos/wolfssl"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
WOLFSSL_DIR="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if wolfSSL directory exists
|
||||||
|
if [ ! -d "$WOLFSSL_DIR" ]; then
|
||||||
|
echo "Error: wolfSSL directory not found at $WOLFSSL_DIR"
|
||||||
|
echo "Please provide a valid wolfSSL directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set up directories
|
||||||
|
RESULTS_DIR="$SCRIPT_DIR/comparison_results"
|
||||||
|
|
||||||
# Create results directory
|
# Create results directory
|
||||||
mkdir -p "$RESULTS_DIR"
|
mkdir -p "$RESULTS_DIR"
|
||||||
|
|
|
@ -21,16 +21,33 @@
|
||||||
|
|
||||||
# Script to generate test memory logs and run the optimizer
|
# Script to generate test memory logs and run the optimizer
|
||||||
|
|
||||||
|
# Get the directory of this script
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
# Check if wolfSSL directory is provided
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <wolfssl_dir>"
|
||||||
|
echo "Example: $0 ~/repos/wolfssl"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
WOLFSSL_DIR="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if wolfSSL directory exists
|
||||||
|
if [ ! -d "$WOLFSSL_DIR" ]; then
|
||||||
|
echo "Error: wolfSSL directory not found at $WOLFSSL_DIR"
|
||||||
|
echo "Please provide a valid wolfSSL directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Set up directories
|
# Set up directories
|
||||||
WOLFSSL_DIR=~/repos/wolfssl
|
RESULTS_DIR="$SCRIPT_DIR/results"
|
||||||
RESULTS_DIR=./results
|
|
||||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
||||||
|
|
||||||
# Create results directory
|
# Create results directory
|
||||||
mkdir -p $RESULTS_DIR
|
mkdir -p "$RESULTS_DIR"
|
||||||
|
|
||||||
# Build wolfSSL with memory logging enabled
|
# Build wolfSSL with memory logging enabled
|
||||||
cd $WOLFSSL_DIR || exit 1
|
cd "$WOLFSSL_DIR" || exit 1
|
||||||
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
|
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
|
||||||
|
|
||||||
# Function to run a test and collect memory usage data
|
# Function to run a test and collect memory usage data
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# run_multiple.sh
|
# run_multiple.sh
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2006-2025 wolfSSL Inc.
|
# Copyright (C) 2025 wolfSSL Inc.
|
||||||
#
|
#
|
||||||
# This file is part of wolfSSL.
|
# This file is part of wolfSSL.
|
||||||
#
|
#
|
||||||
|
@ -20,9 +19,27 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
|
||||||
# Default values
|
# Get the directory of this script
|
||||||
WOLFSSL_DIR="../../../wolfssl"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
RESULTS_DIR="results"
|
|
||||||
|
# Check if wolfSSL directory is provided
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <wolfssl_dir>"
|
||||||
|
echo "Example: $0 ~/repos/wolfssl"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
WOLFSSL_DIR="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if wolfSSL directory exists
|
||||||
|
if [ ! -d "$WOLFSSL_DIR" ]; then
|
||||||
|
echo "Error: wolfSSL directory not found at $WOLFSSL_DIR"
|
||||||
|
echo "Please provide a valid wolfSSL directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set up directories
|
||||||
|
RESULTS_DIR="$SCRIPT_DIR/results"
|
||||||
|
|
||||||
# Test configurations
|
# Test configurations
|
||||||
declare -A TESTS=(
|
declare -A TESTS=(
|
||||||
|
@ -51,14 +68,14 @@ for test_name in "${!TESTS[@]}"; do
|
||||||
|
|
||||||
# Run the example client
|
# Run the example client
|
||||||
./examples/client/client -h "$host" -d -p "$port" $extra_args -g > \
|
./examples/client/client -h "$host" -d -p "$port" $extra_args -g > \
|
||||||
"../wolfssl-examples/staticmemory/memory-bucket-optimizer/$RESULTS_DIR/${test_name}_log.txt" 2>&1
|
"$SCRIPT_DIR/$RESULTS_DIR/${test_name}_log.txt" 2>&1
|
||||||
|
|
||||||
# Extract memory allocation logs
|
# Extract memory allocation logs
|
||||||
cd "../wolfssl-examples/staticmemory/memory-bucket-optimizer" || exit 1
|
cd "$SCRIPT_DIR" || exit 1
|
||||||
grep "^Alloc:" "$RESULTS_DIR/${test_name}_log.txt" > "$RESULTS_DIR/${test_name}_memory.txt"
|
grep "^Alloc:" "$RESULTS_DIR/${test_name}_log.txt" > "$RESULTS_DIR/${test_name}_memory.txt"
|
||||||
|
|
||||||
# Run the memory bucket optimizer
|
# Run the memory bucket optimizer
|
||||||
cd src || exit 1
|
cd "$SCRIPT_DIR/src" || exit 1
|
||||||
./memory_bucket_optimizer "../$RESULTS_DIR/${test_name}_memory.txt" > \
|
./memory_bucket_optimizer "../$RESULTS_DIR/${test_name}_memory.txt" > \
|
||||||
"../$RESULTS_DIR/${test_name}_buckets.txt"
|
"../$RESULTS_DIR/${test_name}_buckets.txt"
|
||||||
|
|
||||||
|
@ -68,7 +85,7 @@ done
|
||||||
|
|
||||||
# Generate visualization plots
|
# Generate visualization plots
|
||||||
cd "$SCRIPT_DIR/visualization" || exit 1
|
cd "$SCRIPT_DIR/visualization" || exit 1
|
||||||
./generate_data.sh
|
./generate_data.sh "$WOLFSSL_DIR"
|
||||||
|
|
||||||
echo "All tests completed. Results saved in $RESULTS_DIR/"
|
echo "All tests completed. Results saved in $RESULTS_DIR/"
|
||||||
echo "Visualization plots can be found in visualization/*.png"
|
echo "Visualization plots can be found in visualization/*.png"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# run_optimizer.sh
|
# run_optimizer.sh
|
||||||
#
|
#
|
||||||
# Copyright (C) 2006-2025 wolfSSL Inc.
|
# Copyright (C) 2025 wolfSSL Inc.
|
||||||
#
|
#
|
||||||
# This file is part of wolfSSL.
|
# This file is part of wolfSSL.
|
||||||
#
|
#
|
||||||
|
@ -19,11 +19,14 @@
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
|
||||||
|
# Get the directory of this script
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
# Default values
|
# Default values
|
||||||
WOLFSSL_DIR="../../../wolfssl"
|
WOLFSSL_DIR="$(dirname "$(dirname "$(dirname "$SCRIPT_DIR")")")/wolfssl"
|
||||||
HOST="google.com"
|
HOST="google.com"
|
||||||
PORT="443"
|
PORT="443"
|
||||||
RESULTS_DIR="results"
|
RESULTS_DIR="$SCRIPT_DIR/results"
|
||||||
|
|
||||||
# Print usage
|
# Print usage
|
||||||
usage() {
|
usage() {
|
||||||
|
@ -35,7 +38,7 @@ usage() {
|
||||||
echo " --help Show this help message"
|
echo " --help Show this help message"
|
||||||
echo
|
echo
|
||||||
echo "Example:"
|
echo "Example:"
|
||||||
echo " $0 -h google.com -p 443"
|
echo " $0 -w ~/repos/wolfssl -h google.com -p 443"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +67,13 @@ while [[ $# -gt 0 ]]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Check if wolfSSL directory exists
|
||||||
|
if [ ! -d "$WOLFSSL_DIR" ]; then
|
||||||
|
echo "Error: wolfSSL directory not found at $WOLFSSL_DIR"
|
||||||
|
echo "Please provide a valid wolfSSL directory using the -w or --wolfssl-dir option."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Create results directory
|
# Create results directory
|
||||||
mkdir -p "$RESULTS_DIR"
|
mkdir -p "$RESULTS_DIR"
|
||||||
|
|
||||||
|
@ -76,22 +86,22 @@ make
|
||||||
|
|
||||||
# Run the example client and collect memory logs
|
# Run the example client and collect memory logs
|
||||||
echo "Running example client..."
|
echo "Running example client..."
|
||||||
./examples/client/client -h "$HOST" -d -p "$PORT" -g > "../wolfssl-examples/staticmemory/memory-bucket-optimizer/$RESULTS_DIR/client_log.txt" 2>&1
|
./examples/client/client -h "$HOST" -d -p "$PORT" -g > "$RESULTS_DIR/client_log.txt" 2>&1
|
||||||
|
|
||||||
# Extract memory allocation logs
|
# Extract memory allocation logs
|
||||||
cd "../wolfssl-examples/staticmemory/memory-bucket-optimizer" || exit 1
|
cd "$SCRIPT_DIR" || exit 1
|
||||||
grep "^Alloc:" "$RESULTS_DIR/client_log.txt" > "$RESULTS_DIR/memory_log.txt"
|
grep "^Alloc:" "$RESULTS_DIR/client_log.txt" > "$RESULTS_DIR/memory_log.txt"
|
||||||
|
|
||||||
# Run the memory bucket optimizer
|
# Run the memory bucket optimizer
|
||||||
echo "Running memory bucket optimizer..."
|
echo "Running memory bucket optimizer..."
|
||||||
cd src || exit 1
|
cd "$SCRIPT_DIR/src" || exit 1
|
||||||
make
|
make
|
||||||
./memory_bucket_optimizer "../../$RESULTS_DIR/memory_log.txt" > "../../$RESULTS_DIR/optimized_buckets.txt"
|
./memory_bucket_optimizer "../$RESULTS_DIR/memory_log.txt" > "../$RESULTS_DIR/optimized_buckets.txt"
|
||||||
|
|
||||||
# Generate visualization plots
|
# Generate visualization plots
|
||||||
echo "Generating visualization plots..."
|
echo "Generating visualization plots..."
|
||||||
cd ../../visualization || exit 1
|
cd "$SCRIPT_DIR/visualization" || exit 1
|
||||||
./generate_data.sh
|
./generate_data.sh "$WOLFSSL_DIR"
|
||||||
|
|
||||||
echo "Optimization complete. Results saved in $RESULTS_DIR/"
|
echo "Optimization complete. Results saved in $RESULTS_DIR/"
|
||||||
echo "Optimized bucket configuration can be found in $RESULTS_DIR/optimized_buckets.txt"
|
echo "Optimized bucket configuration can be found in $RESULTS_DIR/optimized_buckets.txt"
|
||||||
|
|
|
@ -103,15 +103,43 @@ void optimize_buckets(AllocSize* alloc_sizes, int num_sizes, int* buckets, int*
|
||||||
/* Sort by frequency (descending) */
|
/* Sort by frequency (descending) */
|
||||||
qsort(alloc_sizes_by_freq, num_sizes, sizeof(AllocSize), compare_alloc_counts);
|
qsort(alloc_sizes_by_freq, num_sizes, sizeof(AllocSize), compare_alloc_counts);
|
||||||
|
|
||||||
/* Select the most frequent allocation sizes as buckets (up to MAX_BUCKETS) */
|
/* Find the largest allocation size */
|
||||||
*num_buckets = (num_sizes < MAX_BUCKETS) ? num_sizes : MAX_BUCKETS;
|
int largest_size = 0;
|
||||||
|
for (int i = 0; i < num_sizes; i++) {
|
||||||
|
if (alloc_sizes[i].size > largest_size) {
|
||||||
|
largest_size = alloc_sizes[i].size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy the selected bucket sizes */
|
/* Determine how many buckets we can have (max MAX_BUCKETS) */
|
||||||
for (int i = 0; i < *num_buckets; i++) {
|
int max_buckets = (num_sizes < MAX_BUCKETS) ? num_sizes : MAX_BUCKETS;
|
||||||
buckets[i] = alloc_sizes_by_freq[i].size;
|
|
||||||
|
/* Initialize bucket count */
|
||||||
|
*num_buckets = 0;
|
||||||
|
|
||||||
|
/* Always include the largest allocation size */
|
||||||
|
int largest_included = 0;
|
||||||
|
|
||||||
|
/* First, add the most frequent allocation sizes */
|
||||||
|
for (int i = 0; i < max_buckets - 1 && *num_buckets < max_buckets - 1; i++) {
|
||||||
|
/* Skip if this is the largest size (we'll add it later) */
|
||||||
|
if (alloc_sizes_by_freq[i].size == largest_size) {
|
||||||
|
largest_included = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buckets[*num_buckets] = alloc_sizes_by_freq[i].size;
|
||||||
/* Distribution is based on frequency */
|
/* Distribution is based on frequency */
|
||||||
dist[i] = (alloc_sizes_by_freq[i].count > 10) ? 8 :
|
dist[*num_buckets] = (alloc_sizes_by_freq[i].count > 10) ? 8 :
|
||||||
(alloc_sizes_by_freq[i].count > 5) ? 4 : 2;
|
(alloc_sizes_by_freq[i].count > 5) ? 4 : 2;
|
||||||
|
(*num_buckets)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add the largest allocation size if not already included */
|
||||||
|
if (!largest_included) {
|
||||||
|
buckets[*num_buckets] = largest_size;
|
||||||
|
dist[*num_buckets] = 2; /* Use a small distribution for the largest size */
|
||||||
|
(*num_buckets)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sort buckets by size (ascending) */
|
/* Sort buckets by size (ascending) */
|
||||||
|
|
|
@ -21,16 +21,33 @@
|
||||||
|
|
||||||
# Script to test the memory bucket optimizer with different TLS operations
|
# Script to test the memory bucket optimizer with different TLS operations
|
||||||
|
|
||||||
|
# Get the directory of this script
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
# Check if wolfSSL directory is provided
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <wolfssl_dir>"
|
||||||
|
echo "Example: $0 ~/repos/wolfssl"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
WOLFSSL_DIR="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
# Set up directories
|
# Set up directories
|
||||||
WOLFSSL_DIR=~/repos/wolfssl
|
RESULTS_DIR="$SCRIPT_DIR/results"
|
||||||
RESULTS_DIR=./results
|
|
||||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
# Check if wolfSSL directory exists
|
||||||
|
if [ ! -d "$WOLFSSL_DIR" ]; then
|
||||||
|
echo "Error: wolfSSL directory not found at $WOLFSSL_DIR"
|
||||||
|
echo "Please provide a valid wolfSSL directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Create results directory
|
# Create results directory
|
||||||
mkdir -p $RESULTS_DIR
|
mkdir -p "$RESULTS_DIR"
|
||||||
|
|
||||||
# Build wolfSSL with memory logging enabled
|
# Build wolfSSL with memory logging enabled
|
||||||
cd $WOLFSSL_DIR || exit 1
|
cd "$WOLFSSL_DIR" || exit 1
|
||||||
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
|
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
|
||||||
|
|
||||||
# Function to run a test and collect memory usage data
|
# Function to run a test and collect memory usage data
|
||||||
|
|
|
@ -21,16 +21,33 @@
|
||||||
|
|
||||||
# Script to test the memory bucket optimizer with different TLS operations
|
# Script to test the memory bucket optimizer with different TLS operations
|
||||||
|
|
||||||
|
# Get the directory of this script
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
# Check if wolfSSL directory is provided
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <wolfssl_dir>"
|
||||||
|
echo "Example: $0 ~/repos/wolfssl"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
WOLFSSL_DIR="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if wolfSSL directory exists
|
||||||
|
if [ ! -d "$WOLFSSL_DIR" ]; then
|
||||||
|
echo "Error: wolfSSL directory not found at $WOLFSSL_DIR"
|
||||||
|
echo "Please provide a valid wolfSSL directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Set up directories
|
# Set up directories
|
||||||
WOLFSSL_DIR=~/repos/wolfssl
|
RESULTS_DIR="$SCRIPT_DIR/results"
|
||||||
RESULTS_DIR=./results
|
|
||||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
||||||
|
|
||||||
# Create results directory
|
# Create results directory
|
||||||
mkdir -p $RESULTS_DIR
|
mkdir -p "$RESULTS_DIR"
|
||||||
|
|
||||||
# Build wolfSSL with memory logging enabled
|
# Build wolfSSL with memory logging enabled
|
||||||
cd $WOLFSSL_DIR || exit 1
|
cd "$WOLFSSL_DIR" || exit 1
|
||||||
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
|
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
|
||||||
|
|
||||||
# Function to run a test and collect memory usage data
|
# Function to run a test and collect memory usage data
|
||||||
|
|
|
@ -21,10 +21,16 @@
|
||||||
|
|
||||||
# Script to generate data files and plots for memory bucket optimization
|
# Script to generate data files and plots for memory bucket optimization
|
||||||
|
|
||||||
# Set up directories
|
# Get the directory of this script
|
||||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
RESULTS_DIR="$SCRIPT_DIR/../results"
|
RESULTS_DIR="$SCRIPT_DIR/../results"
|
||||||
|
|
||||||
|
# Check if wolfSSL directory is provided
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
WOLFSSL_DIR="$1"
|
||||||
|
echo "Using wolfSSL directory: $WOLFSSL_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
# Create data directory
|
# Create data directory
|
||||||
mkdir -p "$SCRIPT_DIR/data"
|
mkdir -p "$SCRIPT_DIR/data"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue