Newer
Older
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
package rtdt_benchmark
import (
"encoding/json"
"fmt"
"os"
"time"
)
type Rtdt_Benchmark struct {
CtlRcvPathRequest time.Time
CtlRcvCommitRequest time.Time
CtlSendGnmi time.Time
CtlRcvGnmi time.Time
}
var CurrentBenchmark Rtdt_Benchmark
func AppendToJsonFile(r *Rtdt_Benchmark) {
var benchmarks []Rtdt_Benchmark
if _, err := os.Stat("/app/gosdn_share/measure_controller.json"); err == nil {
data, err := os.ReadFile("/app/gosdn_share/measure_controller.json")
if err != nil {
fmt.Println("Error reading file:", err)
return
}
if len(data) > 0 {
err = json.Unmarshal(data, &benchmarks)
if err != nil {
fmt.Println("Error unmarshaling JSON:", err)
return
}
}
} else if !os.IsNotExist(err) {
fmt.Println("Error checking file status:", err)
return
}
// Append the new benchmark
benchmarks = append(benchmarks, *r)
// Marshal and write back to file
outData, err := json.MarshalIndent(benchmarks, "", " ")
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return
}
err = os.WriteFile("/app/gosdn_share/measure_controller.json", outData, 0644)
if err != nil {
fmt.Println("Error writing to file:", err)
}
}