-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
96 lines (87 loc) · 2.8 KB
/
Copy pathmain.go
File metadata and controls
96 lines (87 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"crypto/rand"
_ "embed"
"flag"
"fmt"
"log"
"os"
"runtime"
"time"
"github.com/servicelayernetworking/topogen/pkg"
)
func WriteToFile(filename string, fileSize int) {
file, err := os.Create(filename)
if err != nil {
file, err = os.Open(filename)
if err != nil {
fmt.Printf("failed to open file: %v\n", err)
return
}
}
data := make([]byte, fileSize)
rand.Read(data)
if n, err := file.Write(data); err != nil {
fmt.Printf("failed to write to file: %v\n", err)
} else {
fmt.Printf("wrote %d bytes to %s\n", n, filename)
}
}
func RunCPULoad(millicoreCount int, timeMillis int) {
if timeMillis == 0 || millicoreCount == 0 {
return
}
// 500 millicore -> 500 microseconds
runFor := time.Duration(millicoreCount) * time.Microsecond
sleepFor := time.Duration(1000-millicoreCount) * time.Microsecond
// runtime.LockOSThread()
// make timer
timer := time.NewTimer(time.Duration(timeMillis) * time.Millisecond)
d := time.Duration(timeMillis) * time.Millisecond
fmt.Printf("Timer duration %s, sleepFor %s, runFor %s\n", d.String(), sleepFor.String(), runFor.String())
fmt.Printf("starting load for %dms, current time %d\n", timeMillis, time.Now().UnixMilli())
for {
select {
case <-timer.C:
fmt.Printf("finished load at for %dms, current time %d\n", timeMillis, time.Now().UnixMilli())
runtime.UnlockOSThread()
return
default:
begin := time.Now()
for {
if time.Since(begin) > runFor {
break
}
}
time.Sleep(sleepFor)
}
}
}
func main() {
// parse command-line arguments for topology file
filename := flag.String("topology", "topology.yaml", "path to topology file")
codeOutputDir := flag.String("codeout", "./generated-topology", "path to output generated code")
experimentName := flag.String("experiment", "experiment", "name of the experiment")
containerRegistryPrefix := flag.String("registry", "ghcr.io/adiprerepa", "container registry prefix (for example ghcr.io/adiprerepa or gangmuk)")
kubernetesOutput := flag.String("out", "./generated-topology/kubernetes.yaml", "path to kubernetes output file")
buildAndPush := flag.Bool("build", true, "build and push the docker images")
flag.Parse()
// if the code output directory does not exist, create it
if _, err := os.Stat(*codeOutputDir); os.IsNotExist(err) {
os.MkdirAll(*codeOutputDir, 0755)
}
topology, err := pkg.ParseTopology(*filename)
if err != nil {
log.Fatalf("failed to parse topology file: %v", err)
}
generator := &pkg.TopoCodeGenerator{
CodeOutputDir: *codeOutputDir,
Topo: topology,
K8sOutfile: *kubernetesOutput,
ExperimentName: *experimentName,
ContainerRegistryPrefix: *containerRegistryPrefix,
BuildAndPush: *buildAndPush,
}
generator.Generate()
fmt.Printf("Generated code in %s\n", *codeOutputDir)
}