Skip to content

Commit f7b6a44

Browse files
Restructure visualization paths
1 parent f8e50a3 commit f7b6a44

File tree

5 files changed

+43
-23
lines changed

5 files changed

+43
-23
lines changed

.github/workflows/measure-disk-usage.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Measure Disk Usage
22

33
on:
4-
push:
4+
pull_request:
55
branches:
66
- master
77
env:
@@ -29,24 +29,22 @@ jobs:
2929
ddev config set repo core
3030
- name: Measure disk usage (uncompressed)
3131
run: |
32-
mkdir -p status_visualizations
33-
ddev size status --csv > size-uncompressed.csv
34-
ddev size status --save_to_png_path status_visualizations/uncompressed.png > size-uncompressed.txt
32+
ddev size status >> size-uncompressed.txt
33+
ddev size status --format png,csv,markdown
3534
cat size-uncompressed.txt
3635
echo "# Size (uncompressed)" >> $GITHUB_STEP_SUMMARY
3736
echo '```' >> $GITHUB_STEP_SUMMARY
38-
cat size-uncompressed.txt >> $GITHUB_STEP_SUMMARY
37+
cat uncompressed_status.md >> $GITHUB_STEP_SUMMARY
3938
echo '```' >> $GITHUB_STEP_SUMMARY
4039
4140
- name: Measure disk usage (compressed)
4241
run: |
43-
mkdir -p status_visualizations
44-
ddev size status --csv --compressed > size-compressed.csv
45-
ddev size status --compressed --save_to_png_path status_visualizations/compressed.png > size-compressed.txt
42+
ddev size status --compressed > size-compressed.txt
43+
ddev size status --compressed --format png,csv,markdown
4644
cat size-compressed.txt
4745
echo "# Size (compressed)" >> $GITHUB_STEP_SUMMARY
4846
echo '```' >> $GITHUB_STEP_SUMMARY
49-
cat size-compressed.txt >> $GITHUB_STEP_SUMMARY
47+
cat compressed_status.md >> $GITHUB_STEP_SUMMARY
5048
echo '```' >> $GITHUB_STEP_SUMMARY
5149
5250
@@ -81,15 +79,15 @@ jobs:
8179
- name: Upload file sizes (uncompressed)
8280
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
8381
with:
84-
name: size-uncompressed.csv
85-
path: size-uncompressed.csv
82+
name: uncompressed_status.csv
83+
path: uncompressed_status.csv
8684
if-no-files-found: error
8785

8886
- name: Upload file sizes (compressed)
8987
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
9088
with:
91-
name: size-compressed.csv
92-
path: size-compressed.csv
89+
name: compressed_status.csv
90+
path: compressed_status.csv
9391
if-no-files-found: error
9492

9593
- name: Upload file sizes diff (uncompressed)
@@ -112,7 +110,7 @@ jobs:
112110
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
113111
with:
114112
name: size-visuals
115-
path: status_visualizations/
113+
path: size_status_visualizations/
116114
if-no-files-found: error
117115

118116
- name: Upload diff PNGs

ddev/src/ddev/cli/size/diff.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

5+
import os
56
from datetime import datetime
67
from typing import Optional
78

@@ -161,11 +162,12 @@ def diff_mode(
161162

162163
if params["show_gui"] or treemap_path:
163164
plot_treemap(
165+
params["app"],
164166
formatted_modules,
165167
f"Disk Usage Differences for {params['platform']} and Python version {params['version']}",
166168
params["show_gui"],
167169
"diff",
168-
treemap_path,
170+
"size_diff_visualizations" + os.sep + treemap_path,
169171
)
170172

171173
return formatted_modules

ddev/src/ddev/cli/size/status.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

5+
import os
56
from pathlib import Path
67
from typing import Optional
78

@@ -29,6 +30,7 @@
2930

3031
@click.command()
3132
@click.option("--to-dd-org", type=str, help="Send metrics to Datadog using the specified organization name.")
33+
@click.option("--to-dd-key", type=str, help="Send metrics to datadoghq.com using the specified API key.")
3234
@click.option("--python", "version", help="Python version (e.g 3.12). If not specified, all versions will be analyzed")
3335
@common_params # platform, compressed, format, show_gui
3436
@click.pass_obj
@@ -40,6 +42,7 @@ def status(
4042
format: list[str],
4143
show_gui: bool,
4244
to_dd_org: str,
45+
to_dd_key: str,
4346
) -> None:
4447
"""
4548
Show the current size of all integrations and dependencies.
@@ -52,10 +55,12 @@ def status(
5255
raise ValueError(f"Invalid platform: {platform}")
5356
elif version and version not in valid_versions:
5457
raise ValueError(f"Invalid version: {version}")
55-
if format:
58+
elif format:
5659
for fmt in format:
5760
if fmt not in ["png", "csv", "markdown", "json"]:
5861
raise ValueError(f"Invalid format: {fmt}. Only png, csv, markdown, and json are supported.")
62+
elif to_dd_org and not to_dd_key:
63+
raise ValueError("Specify either --to-dd-org or --to-dd-key, not both")
5964
modules_plat_ver: list[FileDataEntryPlatformVersion] = []
6065
platforms = valid_platforms if platform is None else [platform]
6166
versions = valid_versions if version is None else [version]
@@ -78,8 +83,8 @@ def status(
7883

7984
if format:
8085
export_format(app, format, modules_plat_ver, "status", platform, version, compressed)
81-
if to_dd_org:
82-
send_metrics_to_dd(app, modules_plat_ver, to_dd_org, compressed)
86+
if to_dd_org or to_dd_key:
87+
send_metrics_to_dd(app, modules_plat_ver, to_dd_org, to_dd_key, compressed)
8388
except Exception as e:
8489
app.abort(str(e))
8590

@@ -107,11 +112,12 @@ def status_mode(
107112

108113
if params["show_gui"] or treemap_path:
109114
plot_treemap(
115+
params["app"],
110116
formatted_modules,
111117
f"Disk Usage Status for {params['platform']} and Python version {params['version']}",
112118
params["show_gui"],
113119
"status",
114-
treemap_path,
120+
"size_status_visualizations" + os.sep + treemap_path,
115121
)
116122

117123
return formatted_modules

ddev/src/ddev/cli/size/timeline.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,14 @@ def timeline_mode(
289289
)
290290

291291
if params["show_gui"] or timeline_path:
292-
plot_linegraph(formatted_modules, params["module"], params["platform"], params["show_gui"], timeline_path)
292+
plot_linegraph(
293+
params["app"],
294+
formatted_modules,
295+
params["module"],
296+
params["platform"],
297+
params["show_gui"],
298+
"size_timeline_visualizations" + os.sep + timeline_path,
299+
)
293300

294301
return formatted_modules
295302

@@ -788,6 +795,7 @@ def export_format(
788795

789796

790797
def plot_linegraph(
798+
app: Application,
791799
modules: list[CommitEntryWithDelta] | list[CommitEntryPlatformWithDelta],
792800
module: str,
793801
platform: Optional[str],
@@ -821,7 +829,9 @@ def plot_linegraph(
821829
plt.tight_layout()
822830

823831
if path:
824-
plt.savefig(path)
832+
os.makedirs(os.path.dirname(path), exist_ok=True)
833+
plt.savefig(path, bbox_inches="tight", format="png")
834+
app.display(f"Linegraph saved to {path}")
825835
if show:
826836
plt.show()
827837
plt.close()

ddev/src/ddev/cli/size/utils/common_funcs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ def export_format(
545545

546546

547547
def plot_treemap(
548+
app: Application,
548549
modules: list[FileDataEntryPlatformVersion],
549550
title: str,
550551
show: bool,
@@ -579,7 +580,9 @@ def plot_treemap(
579580
plt.tight_layout()
580581

581582
if path:
583+
os.makedirs(os.path.dirname(path), exist_ok=True)
582584
plt.savefig(path, bbox_inches="tight", format="png")
585+
app.display(f"Treemap saved to {path}")
583586
if show:
584587
plt.show()
585588

@@ -750,14 +753,15 @@ def draw_treemap_rects_with_labels(
750753

751754

752755
def send_metrics_to_dd(
753-
app: Application, modules: list[FileDataEntryPlatformVersion], org: str, compressed: bool
756+
app: Application, modules: list[FileDataEntryPlatformVersion], org: str, key: str, compressed: bool
754757
) -> None:
755758
metric_name = (
756759
"datadog.agent_integrations.size_analyzer.compressed"
757760
if compressed
758761
else "datadog.agent_integrations.size_analyzer.uncompressed"
759762
)
760-
config_file_info = get_org(app, org)
763+
764+
config_file_info = get_org(app, org) if org else {"api_key": key, "site": "datadoghq.com"}
761765
# if not is_everything_committed():
762766
# raise RuntimeError("All files have to be committed in order to send the metrics to Datadog")
763767
if "api_key" not in config_file_info:

0 commit comments

Comments
 (0)