Update scripts to accept wolfSSL directory as argument

Co-Authored-By: jacob@wolfssl.com <jacob@wolfssl.com>
devin/1741050294-optimize-memory-buckets
Devin AI 2025-03-04 15:18:28 +00:00
parent abb76a4089
commit 6aa87008b2
8 changed files with 177 additions and 47 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
# compare_memory.sh
#
# Copyright (C) 2006-2025 wolfSSL Inc.
# Copyright (C) 2025 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
@ -19,9 +19,27 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
# Default values
WOLFSSL_DIR="../../../wolfssl"
RESULTS_DIR="comparison_results"
# 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
RESULTS_DIR="$SCRIPT_DIR/comparison_results"
# Create results directory
mkdir -p "$RESULTS_DIR"

View File

@ -21,16 +21,33 @@
# 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
WOLFSSL_DIR=~/repos/wolfssl
RESULTS_DIR=./results
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
RESULTS_DIR="$SCRIPT_DIR/results"
# Create results directory
mkdir -p $RESULTS_DIR
mkdir -p "$RESULTS_DIR"
# Build wolfSSL with memory logging enabled
cd $WOLFSSL_DIR || exit 1
cd "$WOLFSSL_DIR" || exit 1
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
# Function to run a test and collect memory usage data

View File

@ -1,8 +1,7 @@
#!/bin/bash
# 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.
#
@ -20,9 +19,27 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
# Default values
WOLFSSL_DIR="../../../wolfssl"
RESULTS_DIR="results"
# 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
RESULTS_DIR="$SCRIPT_DIR/results"
# Test configurations
declare -A TESTS=(
@ -51,14 +68,14 @@ for test_name in "${!TESTS[@]}"; do
# Run the example client
./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
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"
# Run the memory bucket optimizer
cd src || exit 1
cd "$SCRIPT_DIR/src" || exit 1
./memory_bucket_optimizer "../$RESULTS_DIR/${test_name}_memory.txt" > \
"../$RESULTS_DIR/${test_name}_buckets.txt"
@ -68,7 +85,7 @@ done
# Generate visualization plots
cd "$SCRIPT_DIR/visualization" || exit 1
./generate_data.sh
./generate_data.sh "$WOLFSSL_DIR"
echo "All tests completed. Results saved in $RESULTS_DIR/"
echo "Visualization plots can be found in visualization/*.png"

View File

@ -1,7 +1,7 @@
#!/bin/bash
# run_optimizer.sh
#
# Copyright (C) 2006-2025 wolfSSL Inc.
# Copyright (C) 2025 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
@ -19,11 +19,14 @@
# along with this program; if not, write to the Free Software
# 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
WOLFSSL_DIR="../../../wolfssl"
WOLFSSL_DIR="$(dirname "$(dirname "$(dirname "$SCRIPT_DIR")")")/wolfssl"
HOST="google.com"
PORT="443"
RESULTS_DIR="results"
RESULTS_DIR="$SCRIPT_DIR/results"
# Print usage
usage() {
@ -35,7 +38,7 @@ usage() {
echo " --help Show this help message"
echo
echo "Example:"
echo " $0 -h google.com -p 443"
echo " $0 -w ~/repos/wolfssl -h google.com -p 443"
exit 1
}
@ -64,6 +67,13 @@ while [[ $# -gt 0 ]]; do
esac
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
mkdir -p "$RESULTS_DIR"
@ -76,22 +86,22 @@ make
# Run the example client and collect memory logs
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
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"
# Run the memory bucket optimizer
echo "Running memory bucket optimizer..."
cd src || exit 1
cd "$SCRIPT_DIR/src" || exit 1
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
echo "Generating visualization plots..."
cd ../../visualization || exit 1
./generate_data.sh
cd "$SCRIPT_DIR/visualization" || exit 1
./generate_data.sh "$WOLFSSL_DIR"
echo "Optimization complete. Results saved in $RESULTS_DIR/"
echo "Optimized bucket configuration can be found in $RESULTS_DIR/optimized_buckets.txt"

View File

@ -103,15 +103,43 @@ void optimize_buckets(AllocSize* alloc_sizes, int num_sizes, int* buckets, int*
/* Sort by frequency (descending) */
qsort(alloc_sizes_by_freq, num_sizes, sizeof(AllocSize), compare_alloc_counts);
/* Select the most frequent allocation sizes as buckets (up to MAX_BUCKETS) */
*num_buckets = (num_sizes < MAX_BUCKETS) ? num_sizes : MAX_BUCKETS;
/* Find the largest allocation size */
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 */
for (int i = 0; i < *num_buckets; i++) {
buckets[i] = alloc_sizes_by_freq[i].size;
/* Determine how many buckets we can have (max MAX_BUCKETS) */
int max_buckets = (num_sizes < MAX_BUCKETS) ? num_sizes : MAX_BUCKETS;
/* 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 */
dist[i] = (alloc_sizes_by_freq[i].count > 10) ? 8 :
(alloc_sizes_by_freq[i].count > 5) ? 4 : 2;
dist[*num_buckets] = (alloc_sizes_by_freq[i].count > 10) ? 8 :
(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) */

View File

@ -21,16 +21,33 @@
# 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
WOLFSSL_DIR=~/repos/wolfssl
RESULTS_DIR=./results
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
RESULTS_DIR="$SCRIPT_DIR/results"
# 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
mkdir -p $RESULTS_DIR
mkdir -p "$RESULTS_DIR"
# Build wolfSSL with memory logging enabled
cd $WOLFSSL_DIR || exit 1
cd "$WOLFSSL_DIR" || exit 1
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
# Function to run a test and collect memory usage data

View File

@ -21,16 +21,33 @@
# 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
WOLFSSL_DIR=~/repos/wolfssl
RESULTS_DIR=./results
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
RESULTS_DIR="$SCRIPT_DIR/results"
# Create results directory
mkdir -p $RESULTS_DIR
mkdir -p "$RESULTS_DIR"
# Build wolfSSL with memory logging enabled
cd $WOLFSSL_DIR || exit 1
cd "$WOLFSSL_DIR" || exit 1
./autogen.sh && ./configure --enable-memorylog --enable-staticmemory && make
# Function to run a test and collect memory usage data

View File

@ -21,10 +21,16 @@
# Script to generate data files and plots for memory bucket optimization
# Set up directories
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Get the directory of this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
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
mkdir -p "$SCRIPT_DIR/data"