Skip to content

Commit 999390e

Browse files
random commit
1 parent a7344b3 commit 999390e

2 files changed

Lines changed: 63 additions & 32 deletions

File tree

tests/on_target/scripts/memory_plot_generator.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,39 @@
66
import os
77
import sys
88

9+
def append_to_memory_csv(filename, used, total, current_date, output_dir):
10+
"""Append memory data to a CSV file."""
11+
data = {'Date': current_date, 'Used (B)': used, 'Total (B)': total, 'Usage (%)': (used/total)*100}
12+
df = pd.DataFrame([data])
13+
14+
csv_path = os.path.join(output_dir, filename)
15+
16+
if os.path.exists(csv_path):
17+
print(f"CSV exists at {csv_path}, appending data")
18+
# Read existing data
19+
existing_df = pd.read_csv(csv_path)
20+
print(f"Existing data:\n{existing_df}")
21+
22+
# Combine existing and new data
23+
combined_df = pd.concat([existing_df, df], ignore_index=True)
24+
print(f"Combined data:\n{combined_df}")
25+
26+
# Write back the complete dataset
27+
combined_df.to_csv(csv_path, index=False)
28+
else:
29+
print(f"Creating new CSV at {csv_path}")
30+
df.to_csv(csv_path, index=False)
31+
932
def append_to_csv(ram_used, ram_total, flash_used, flash_total, output_dir):
1033
"""Append memory usage data to CSV files with timestamps."""
1134
current_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
1235

1336
# Ensure output directory exists
1437
os.makedirs(output_dir, exist_ok=True)
1538

16-
# RAM CSV
17-
ram_csv = os.path.join(output_dir, "ram_history.csv")
18-
ram_data = {'Date': current_date, 'Used (B)': ram_used, 'Total (B)': ram_total, 'Usage (%)': (ram_used/ram_total)*100}
19-
ram_df = pd.DataFrame([ram_data])
20-
21-
if os.path.exists(ram_csv):
22-
ram_df.to_csv(ram_csv, mode='a', header=False, index=False)
23-
else:
24-
ram_df.to_csv(ram_csv, mode='w', header=True, index=False)
25-
26-
# Flash CSV
27-
flash_csv = os.path.join(output_dir, "flash_history.csv")
28-
flash_data = {'Date': current_date, 'Used (B)': flash_used, 'Total (B)': flash_total, 'Usage (%)': (flash_used/flash_total)*100}
29-
flash_df = pd.DataFrame([flash_data])
30-
31-
if os.path.exists(flash_csv):
32-
flash_df.to_csv(flash_csv, mode='a', header=False, index=False)
33-
else:
34-
flash_df.to_csv(flash_csv, mode='w', header=True, index=False)
39+
# Append to RAM and Flash CSVs
40+
append_to_memory_csv("ram_history.csv", ram_used, ram_total, current_date, output_dir)
41+
append_to_memory_csv("flash_history.csv", flash_used, flash_total, current_date, output_dir)
3542

3643
def generate_memory_plots(output_dir):
3744
"""Generate HTML plots from the CSV data."""
@@ -41,7 +48,9 @@ def generate_memory_plots(output_dir):
4148
# RAM Plot
4249
ram_csv = os.path.join(output_dir, "ram_history.csv")
4350
if os.path.exists(ram_csv):
51+
print(f"Reading RAM CSV for plotting from: {ram_csv}")
4452
df_ram = pd.read_csv(ram_csv)
53+
print(f"RAM data for plotting:\n{df_ram}")
4554
df_ram['Date'] = pd.to_datetime(df_ram['Date'])
4655

4756
# Calculate y-axis range for RAM

tests/on_target/scripts/update_memory_badges.sh

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,53 @@ handle_error() {
2929
exit 0
3030
}
3131

32-
# Generate badge files using Python script
33-
echo "Generating badge files..."
34-
./tests/on_target/scripts/parse_memory_stats.py "$BUILD_LOG" "tests/on_target" || handle_error "Failed to generate badge files"
35-
36-
3732
# Configure Git
3833
git config --global --add safe.directory "$(pwd)"
3934
git config --global user.email "github-actions@github.com"
4035
git config --global user.name "GitHub Actions"
4136

42-
# Ensure the gh-pages branch exists and switch to it
37+
# Create a temporary directory for gh-pages content
38+
TEMP_DIR=$(mktemp -d)
39+
40+
# Fetch existing CSV files from gh-pages branch
4341
git fetch origin gh-pages
42+
43+
echo "Fetching existing CSV files..."
44+
if git show origin/gh-pages:docs/ram_history.csv > "$TEMP_DIR/ram_history.csv" 2>/dev/null; then
45+
echo "Found existing RAM history:"
46+
cat "$TEMP_DIR/ram_history.csv"
47+
else
48+
echo "No existing RAM history, creating new file"
49+
touch "$TEMP_DIR/ram_history.csv"
50+
fi
51+
52+
if git show origin/gh-pages:docs/flash_history.csv > "$TEMP_DIR/flash_history.csv" 2>/dev/null; then
53+
echo "Found existing Flash history:"
54+
cat "$TEMP_DIR/flash_history.csv"
55+
else
56+
echo "No existing Flash history, creating new file"
57+
touch "$TEMP_DIR/flash_history.csv"
58+
fi
59+
60+
# Generate badge files and append to existing CSV files
61+
echo "Generating badge files..."
62+
./tests/on_target/scripts/parse_memory_stats.py "$BUILD_LOG" "$TEMP_DIR" || handle_error "Failed to generate badge files"
63+
64+
# Switch to gh-pages branch and update files
4465
git checkout gh-pages || handle_error "Not able to checkout gh-pages"
4566
git pull origin gh-pages || handle_error "Failed to pull latest gh-pages"
4667

47-
# Stage, commit, and push changes to the branch
48-
cp $FLASH_BADGE_FILE $FLASH_BADGE_FILE_DEST
49-
cp $RAM_BADGE_FILE $RAM_BADGE_FILE_DEST
50-
cp $FLASH_HISTORY_CSV $FLASH_HISTORY_CSV_DEST
51-
cp $RAM_HISTORY_CSV $RAM_HISTORY_CSV_DEST
52-
cp $FLASH_PLOT_HTML $FLASH_PLOT_HTML_DEST
53-
cp $RAM_PLOT_HTML $RAM_PLOT_HTML_DEST
68+
# Copy all files to docs/
69+
mkdir -p docs
70+
cp "$TEMP_DIR"/*.json docs/
71+
cp "$TEMP_DIR"/*.csv docs/
72+
cp "$TEMP_DIR"/*.html docs/
5473

5574
git add $FLASH_BADGE_FILE_DEST $RAM_BADGE_FILE_DEST \
5675
$FLASH_HISTORY_CSV_DEST $RAM_HISTORY_CSV_DEST \
5776
$FLASH_PLOT_HTML_DEST $RAM_PLOT_HTML_DEST
5877
git commit -m "Update memory usage badges"
5978
git push origin gh-pages
79+
80+
# Clean up
81+
rm -rf "$TEMP_DIR"

0 commit comments

Comments
 (0)