feat: add more configs
This commit is contained in:
parent
deba5665d9
commit
f73845b1c3
19
README.md
19
README.md
|
@ -13,22 +13,9 @@ go build -o ./build/joj3 ./cmd/joj3
|
||||||
+ DIRNAME=./_example/simple
|
+ DIRNAME=./_example/simple
|
||||||
+ cd ./_example/simple
|
+ cd ./_example/simple
|
||||||
+ ./../../build/joj3
|
+ ./../../build/joj3
|
||||||
2024/03/04 14:33:27 INFO stage start name=compile
|
+ cat ./joj3_result.json
|
||||||
2024/03/04 14:33:27 INFO executor run start cmd="{Args:[/usr/bin/g++ a.cc -o a] Env:[PATH=/usr/bin:/bin] Files:[0xc000114340 0xc000114380 0xc0001143c0] CPULimit:10000000000 RealCPULimit:0 ClockLimit:0 MemoryLimit:104857600 StackLimit:0 ProcLimit:50 CPURateLimit:0 CPUSetLimit: CopyIn:map[] CopyInCached:map[] CopyInCwd:true CopyOut:[stdout stderr] CopyOutCached:[a] CopyOutMax:0 CopyOutDir: TTY:false StrictMemoryLimit:false DataSegmentLimit:false AddressSpaceLimit:false}"
|
[{"Name":"compile","Score":100,"Comment":"compile done, executor status: run time: 239591301 ns, memory: 57176064 bytes"},{"Name":"run","Score":100,"Comment":"executor status: run time: 1839200 ns, memory: 16826368 bytes"}]
|
||||||
2024/03/04 14:33:27 INFO executor run done result="{Status:Accepted ExitStatus:0 Error: Time:355.171ms RunTime:356.069198ms Memory:53.9 MiB Files:map[stderr:len:0 stdout:len:0] FileIDs:map[a:VNQ3A3QC] FileError:[]}"
|
+ rm -f ./joj3_result.json
|
||||||
2024/03/04 14:33:27 INFO parser run start config="map[comment:compile done score:100]"
|
|
||||||
2024/03/04 14:33:27 INFO parser run done result="&{Score:100 Comment:compile done, executor status: run time: 356069198 ns, memory: 56561664 bytes}"
|
|
||||||
2024/03/04 14:33:27 INFO stage start name=run
|
|
||||||
2024/03/04 14:33:27 INFO executor run start cmd="{Args:[./a] Env:[PATH=/usr/bin:/bin] Files:[0xc000114400 0xc000114440 0xc000114480] CPULimit:10000000000 RealCPULimit:0 ClockLimit:0 MemoryLimit:104857600 StackLimit:0 ProcLimit:50 CPURateLimit:0 CPUSetLimit: CopyIn:map[] CopyInCached:map[a:a] CopyInCwd:false CopyOut:[stdout stderr] CopyOutCached:[] CopyOutMax:0 CopyOutDir: TTY:false StrictMemoryLimit:false DataSegmentLimit:false AddressSpaceLimit:false}"
|
|
||||||
2024/03/04 14:33:27 INFO executor run done result="{Status:Accepted ExitStatus:0 Error: Time:1.393ms RunTime:2.2294ms Memory:12.8 MiB Files:map[stderr:len:0 stdout:len:2] FileIDs:map[] FileError:[]}"
|
|
||||||
2024/03/04 14:33:27 INFO parser run start config="map[score:100 stdoutPath:1.stdout]"
|
|
||||||
2024/03/04 14:33:27 INFO parser run done result="&{Score:100 Comment:}"
|
|
||||||
2024/03/04 14:33:27 INFO stage result name=compile score=100 comment="compile done, executor status: run time: 356069198 ns, memory: 56561664 bytes"
|
|
||||||
2024/03/04 14:33:27 INFO stage result name=run score=100 comment=""
|
|
||||||
2024/03/04 14:33:27 INFO executor cleanup start name=dummy
|
|
||||||
2024/03/04 14:33:27 INFO executor cleanup done name=dummy
|
|
||||||
2024/03/04 14:33:27 INFO executor cleanup start name=sandbox
|
|
||||||
2024/03/04 14:33:27 INFO executor cleanup done name=sandbox
|
|
||||||
+ cd -
|
+ cd -
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
logLevel = 8
|
||||||
[[stages]]
|
[[stages]]
|
||||||
name = "compile"
|
name = "compile"
|
||||||
[stages.executor]
|
[stages.executor]
|
||||||
|
|
|
@ -5,4 +5,6 @@ DIRNAME=`dirname -- "$0"`
|
||||||
# cd to make CopyInCwd work
|
# cd to make CopyInCwd work
|
||||||
cd $DIRNAME
|
cd $DIRNAME
|
||||||
./../../build/joj3
|
./../../build/joj3
|
||||||
|
cat ./joj3_result.json
|
||||||
|
rm -f ./joj3_result.json
|
||||||
cd -
|
cd -
|
||||||
|
|
19
cmd/joj3/conf.go
Normal file
19
cmd/joj3/conf.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
|
||||||
|
|
||||||
|
type Conf struct {
|
||||||
|
LogLevel int
|
||||||
|
OutputPath string
|
||||||
|
Stages []struct {
|
||||||
|
Name string
|
||||||
|
Executor struct {
|
||||||
|
Name string
|
||||||
|
With stage.Cmd
|
||||||
|
}
|
||||||
|
Parser struct {
|
||||||
|
Name string
|
||||||
|
With interface{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
@ -8,25 +9,65 @@ import (
|
||||||
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors"
|
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors"
|
||||||
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers"
|
_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers"
|
||||||
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
|
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
|
||||||
|
|
||||||
|
"github.com/pelletier/go-toml/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func parseConfFile(tomlPath *string) (Conf, []stage.Stage) {
|
||||||
tomlPath := flag.String("c", "conf.toml", "file path of the toml config")
|
|
||||||
flag.Parse()
|
|
||||||
tomlConfig, err := os.ReadFile(*tomlPath)
|
tomlConfig, err := os.ReadFile(*tomlPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("read toml config", "error", err)
|
slog.Error("read toml config", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
conf := Conf{
|
||||||
|
LogLevel: 0,
|
||||||
|
OutputPath: "joj3_result.json",
|
||||||
|
}
|
||||||
|
err = toml.Unmarshal(tomlConfig, &conf)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("parse stages config", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
stages := []stage.Stage{}
|
||||||
|
for _, s := range conf.Stages {
|
||||||
|
stages = append(stages, stage.Stage{
|
||||||
|
Name: s.Name,
|
||||||
|
ExecutorName: s.Executor.Name,
|
||||||
|
ExecutorCmd: s.Executor.With,
|
||||||
|
ParserName: s.Parser.Name,
|
||||||
|
ParserConfig: s.Parser.With,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return conf, stages
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupSlog(conf Conf) {
|
||||||
|
lvl := new(slog.LevelVar)
|
||||||
|
lvl.Set(slog.Level(conf.LogLevel))
|
||||||
|
opts := &slog.HandlerOptions{Level: lvl}
|
||||||
|
handler := slog.NewTextHandler(os.Stderr, opts)
|
||||||
|
logger := slog.New(handler)
|
||||||
|
slog.SetDefault(logger)
|
||||||
|
}
|
||||||
|
|
||||||
|
func outputResult(conf Conf, results []stage.StageResult) error {
|
||||||
|
content, err := json.Marshal(results)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.WriteFile(conf.OutputPath,
|
||||||
|
append(content, []byte("\n")...), 0o666)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
tomlPath := flag.String("c", "conf.toml", "file path of the toml config")
|
||||||
|
flag.Parse()
|
||||||
|
conf, stages := parseConfFile(tomlPath)
|
||||||
|
setupSlog(conf)
|
||||||
defer stage.Cleanup()
|
defer stage.Cleanup()
|
||||||
stages := stage.ParseStages(tomlConfig)
|
|
||||||
results := stage.Run(stages)
|
results := stage.Run(stages)
|
||||||
for _, result := range results {
|
err := outputResult(conf, results)
|
||||||
slog.Info(
|
if err != nil {
|
||||||
"stage result",
|
slog.Error("output result", "error", err)
|
||||||
"name", result.Name,
|
|
||||||
"score", result.Score,
|
|
||||||
"comment", result.Comment,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package diff
|
package diff
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
|
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
|
||||||
|
@ -30,7 +31,10 @@ func (e *Diff) Run(result *stage.ExecutorResult, configAny any) (
|
||||||
score = config.Score
|
score = config.Score
|
||||||
}
|
}
|
||||||
return &stage.ParserResult{
|
return &stage.ParserResult{
|
||||||
Score: score,
|
Score: score,
|
||||||
Comment: "",
|
Comment: fmt.Sprintf(
|
||||||
|
"executor status: run time: %d ns, memory: %d bytes",
|
||||||
|
result.RunTime, result.Memory,
|
||||||
|
),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,10 +151,8 @@ func (r ExecutorResult) String() string {
|
||||||
type Stage struct {
|
type Stage struct {
|
||||||
Name string
|
Name string
|
||||||
ExecutorName string
|
ExecutorName string
|
||||||
Executor Executor
|
|
||||||
ExecutorCmd Cmd
|
ExecutorCmd Cmd
|
||||||
ParserName string
|
ParserName string
|
||||||
Parser Parser
|
|
||||||
ParserConfig any
|
ParserConfig any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,17 +165,3 @@ type StageResult struct {
|
||||||
Name string
|
Name string
|
||||||
*ParserResult
|
*ParserResult
|
||||||
}
|
}
|
||||||
|
|
||||||
type StagesConfig struct {
|
|
||||||
Stages []struct {
|
|
||||||
Name string
|
|
||||||
Executor struct {
|
|
||||||
Name string
|
|
||||||
With Cmd
|
|
||||||
}
|
|
||||||
Parser struct {
|
|
||||||
Name string
|
|
||||||
With interface{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,46 +2,23 @@ package stage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/pelletier/go-toml/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseStages(tomlConfig []byte) []Stage {
|
|
||||||
var stagesConfig StagesConfig
|
|
||||||
err := toml.Unmarshal(tomlConfig, &stagesConfig)
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("parse stages config", "error", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
stages := []Stage{}
|
|
||||||
for _, stage := range stagesConfig.Stages {
|
|
||||||
stages = append(stages, Stage{
|
|
||||||
Name: stage.Name,
|
|
||||||
ExecutorName: stage.Executor.Name,
|
|
||||||
Executor: executorMap[stage.Executor.Name],
|
|
||||||
ExecutorCmd: stage.Executor.With,
|
|
||||||
ParserName: stage.Parser.Name,
|
|
||||||
Parser: parserMap[stage.Parser.Name],
|
|
||||||
ParserConfig: stage.Parser.With,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return stages
|
|
||||||
}
|
|
||||||
|
|
||||||
func Run(stages []Stage) []StageResult {
|
func Run(stages []Stage) []StageResult {
|
||||||
var parserResults []StageResult
|
var parserResults []StageResult
|
||||||
for _, stage := range stages {
|
for _, stage := range stages {
|
||||||
slog.Info("stage start", "name", stage.Name)
|
slog.Info("stage start", "name", stage.Name)
|
||||||
slog.Info("executor run start", "cmd", stage.ExecutorCmd)
|
slog.Info("executor run start", "cmd", stage.ExecutorCmd)
|
||||||
executorResult, err := stage.Executor.Run(stage.ExecutorCmd)
|
executor := executorMap[stage.ExecutorName]
|
||||||
|
executorResult, err := executor.Run(stage.ExecutorCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("executor run error", "name", stage.ExecutorName, "error", err)
|
slog.Error("executor run error", "name", stage.ExecutorName, "error", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
slog.Info("executor run done", "result", executorResult)
|
slog.Info("executor run done", "result", executorResult)
|
||||||
slog.Info("parser run start", "config", stage.ParserConfig)
|
slog.Info("parser run start", "config", stage.ParserConfig)
|
||||||
parserResult, err := stage.Parser.Run(executorResult, stage.ParserConfig)
|
parser := parserMap[stage.ParserName]
|
||||||
|
parserResult, err := parser.Run(executorResult, stage.ParserConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("parser run error", "name", stage.ExecutorName, "error", err)
|
slog.Error("parser run error", "name", stage.ExecutorName, "error", err)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue
Block a user