Skip to content

Commit 7d2101f

Browse files
committed
cmd/omitsize: add flag to disable the removal table
And remove a bogus omit feature from feature/featuretags. Updates tailscale#12614 Change-Id: I0a08183fb75c73ae75b6fd4216d134e352dcf5a0 Signed-off-by: Brad Fitzpatrick <[email protected]>
1 parent 0cc1b2f commit 7d2101f

File tree

3 files changed

+65
-29
lines changed

3 files changed

+65
-29
lines changed

cmd/featuretags/featuretags.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,39 @@ func main() {
3535
return
3636
}
3737

38-
var keep = map[string]bool{}
38+
var keep = map[featuretags.FeatureTag]bool{}
3939
for t := range strings.SplitSeq(*add, ",") {
4040
if t != "" {
41-
keep[t] = true
41+
keep[featuretags.FeatureTag(t)] = true
4242
}
4343
}
4444
var tags []string
45-
if keep["cli"] {
46-
// The "cli" --add value is special in that it's a build tag
47-
// that adds something, rather than removes something.
45+
if keep[featuretags.CLI] {
4846
tags = append(tags, "ts_include_cli")
4947
}
5048
if *min {
5149
for _, f := range slices.Sorted(maps.Keys(features)) {
5250
if f == "" {
5351
continue
5452
}
55-
if !keep[f] {
56-
tags = append(tags, "ts_omit_"+f)
53+
if !keep[f] && f.IsOmittable() {
54+
tags = append(tags, f.OmitTag())
5755
}
5856
}
5957
}
60-
for f := range strings.SplitSeq(*remove, ",") {
61-
if f == "" {
58+
for v := range strings.SplitSeq(*remove, ",") {
59+
if v == "" {
6260
continue
6361
}
62+
f := featuretags.FeatureTag(v)
6463
if _, ok := features[f]; !ok {
6564
log.Fatalf("unknown feature %q in --remove", f)
6665
}
67-
tags = append(tags, "ts_omit_"+f)
66+
tags = append(tags, f.OmitTag())
6867
}
68+
slices.Sort(tags)
69+
tags = slices.Compact(tags)
6970
if len(tags) != 0 {
7071
fmt.Println(strings.Join(tags, ","))
7172
}
72-
7373
}

cmd/omitsize/omitsize.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
var (
2424
cacheDir = flag.String("cachedir", "", "if non-empty, use this directory to store cached size results to speed up subsequent runs. The tool does not consider the git status when deciding whether to use the cache. It's on you to nuke it between runs if the tree changed.")
2525
features = flag.String("features", "", "comma-separated list of features to consider, with or without the ts_omit_ prefix")
26+
27+
showRemovals = flag.Bool("show-removals", false, "if true, show a table of sizes removing one feature at a time from the full set")
2628
)
2729

2830
func main() {
@@ -31,7 +33,9 @@ func main() {
3133
var all []string
3234
if *features == "" {
3335
for k := range featuretags.Features {
34-
all = append(all, "ts_omit_"+k)
36+
if k.IsOmittable() {
37+
all = append(all, k.OmitTag())
38+
}
3539
}
3640
} else {
3741
for v := range strings.SplitSeq(*features, ",") {
@@ -49,27 +53,30 @@ func main() {
4953
baseC := measure("tailscale")
5054
baseBoth := measure("tailscaled", "ts_include_cli")
5155

52-
fmt.Printf("(a) starting with everything and removing a feature...\n\n")
53-
54-
fmt.Printf("%9s %9s %9s\n", "tailscaled", "tailscale", "combined (linux/amd64)")
55-
fmt.Printf("%9d %9d %9d\n", baseD, baseC, baseBoth)
56-
5756
minD := measure("tailscaled", all...)
5857
minC := measure("tailscale", all...)
5958
minBoth := measure("tailscaled", append(slices.Clone(all), "ts_include_cli")...)
60-
fmt.Printf("-%8d -%8d -%8d omit-all\n", baseD-minD, baseC-minC, baseBoth-minBoth)
6159

62-
for _, t := range all {
63-
sizeD := measure("tailscaled", t)
64-
sizeC := measure("tailscale", t)
65-
sizeBoth := measure("tailscaled", append([]string{t}, "ts_include_cli")...)
66-
saveD := max(baseD-sizeD, 0)
67-
saveC := max(baseC-sizeC, 0)
68-
saveBoth := max(baseBoth-sizeBoth, 0)
69-
fmt.Printf("-%8d -%8d -%8d %s\n", saveD, saveC, saveBoth, t)
60+
if *showRemovals {
61+
fmt.Printf("Starting with everything and removing a feature...\n\n")
62+
63+
fmt.Printf("%9s %9s %9s\n", "tailscaled", "tailscale", "combined (linux/amd64)")
64+
fmt.Printf("%9d %9d %9d\n", baseD, baseC, baseBoth)
65+
66+
fmt.Printf("-%8d -%8d -%8d omit-all\n", baseD-minD, baseC-minC, baseBoth-minBoth)
67+
68+
for _, t := range all {
69+
sizeD := measure("tailscaled", t)
70+
sizeC := measure("tailscale", t)
71+
sizeBoth := measure("tailscaled", append([]string{t}, "ts_include_cli")...)
72+
saveD := max(baseD-sizeD, 0)
73+
saveC := max(baseC-sizeC, 0)
74+
saveBoth := max(baseBoth-sizeBoth, 0)
75+
fmt.Printf("-%8d -%8d -%8d %s\n", saveD, saveC, saveBoth, t)
76+
}
7077
}
7178

72-
fmt.Printf("\n(b) or, starting at minimal and adding one feature back...\n")
79+
fmt.Printf("\nStarting at a minimal binary and adding one feature back...\n")
7380
fmt.Printf("%9s %9s %9s\n", "tailscaled", "tailscale", "combined (linux/amd64)")
7481
fmt.Printf("%9d %9d %9d omitting everything\n", minD, minC, minBoth)
7582
for _, t := range all {

feature/featuretags/featuretags.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,37 @@
44
// The featuretags package is a registry of all the ts_omit-able build tags.
55
package featuretags
66

7-
var Features = map[string]string{
7+
// CLI is a special feature in the [Features] map that works opposite
8+
// from the others: it is opt-in, rather than opt-out, having a different
9+
// build tag format.
10+
const CLI FeatureTag = "cli"
11+
12+
// FeatureTag names a Tailscale feature that can be selectively added or removed
13+
// via build tags.
14+
type FeatureTag string
15+
16+
// IsOmittable reports whether this feature tag is one that can be
17+
// omitted via a ts_omit_ build tag.
18+
func (ft FeatureTag) IsOmittable() bool {
19+
switch ft {
20+
case CLI:
21+
return false
22+
}
23+
return true
24+
}
25+
26+
// OmitTag returns the ts_omit_ build tag for this feature tag.
27+
// It panics if the feature tag is not omitable.
28+
func (ft FeatureTag) OmitTag() string {
29+
if !ft.IsOmittable() {
30+
panic("not omitable: " + string(ft))
31+
}
32+
return "ts_omit_" + string(ft)
33+
}
34+
35+
// Features are the known Tailscale features that can be selectively included or
36+
// excluded via build tags, and a description of each.
37+
var Features = map[FeatureTag]string{
838
"aws": "AWS integration",
939
"bird": "Bird BGP integration",
1040
"capture": "Packet capture",
@@ -21,7 +51,6 @@ var Features = map[string]string{
2151
"taildrop": "Taildrop (file sending) support",
2252
"tailnetlock": "Tailnet Lock support",
2353
"tap": "Experimental Layer 2 (ethernet) support",
24-
"tka": "Tailnet Lock (TKA) support",
2554
"tpm": "TPM support",
2655
"wakeonlan": "Wake-on-LAN support",
2756
"webclient": "Web client support",

0 commit comments

Comments
 (0)