Skip to content

Commit

Permalink
datarecorder
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanhuanO committed Nov 24, 2024
1 parent 327b5c8 commit b46af20
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 114 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
Expand Down Expand Up @@ -42,7 +43,7 @@ require (

// replace github.com/syifan/goseth => ../goseth

// replace github.com/sarchlab/akita/v4 => ../akita
replace github.com/sarchlab/akita/v4 => ../akita

go 1.22.0

Expand Down
50 changes: 3 additions & 47 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
Expand All @@ -20,13 +23,8 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
<<<<<<< HEAD
github.com/google/pprof v0.0.0-20240829160300-da1f7e9f2b25 h1:sEDPKUw6iPjczdu33njxFjO6tYa9bfc0z/QyB/zSsBw=
github.com/google/pprof v0.0.0-20240829160300-da1f7e9f2b25/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
=======
github.com/google/pprof v0.0.0-20240903155634-a8630aee4ab9 h1:q5g0N9eal4bmJwXHC5z0QCKs8qhS35hFfq0BAYsIwZI=
github.com/google/pprof v0.0.0-20240903155634-a8630aee4ab9/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
>>>>>>> origin/v4
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
Expand All @@ -40,13 +38,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
<<<<<<< HEAD
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
=======
github.com/mattn/go-sqlite3 v1.14.23 h1:gbShiuAP1W5j9UOksQ06aiiqPMxYecovVGwmTxWtuw0=
github.com/mattn/go-sqlite3 v1.14.23/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
>>>>>>> origin/v4
github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4=
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
Expand All @@ -55,13 +48,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
<<<<<<< HEAD
github.com/sarchlab/mgpusim/v3 v3.0.3 h1:ixXppzSRnQbjYrAQ2qlsocxIHNKOKWuqS2rj0XGC2tM=
github.com/sarchlab/mgpusim/v3 v3.0.3/go.mod h1:bZWSPkEW4VsM0Ew4jPiVBJ+umZak2Rs7MP7mbdOKeRA=
=======
github.com/sarchlab/akita/v4 v4.0.0-alpha.5 h1:+jOx/D4Vv44/lNNgzDgXYTwR6y4XnN4YJHyddhhqiBI=
github.com/sarchlab/akita/v4 v4.0.0-alpha.5/go.mod h1:xHBNi4GYv6rRohUU+8FzGuKK2uHXANEHL7zYq6/0rEw=
>>>>>>> origin/v4
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -81,27 +67,17 @@ github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
<<<<<<< HEAD
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
=======
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA=
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
>>>>>>> origin/v4
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.20.0 h1:7cVCUjQwfL18gyBJOmYvptfSHS8Fb3YUDtfLIZ7Nbpw=
golang.org/x/image v0.20.0/go.mod h1:0a88To4CYVBAHp5FXJm8o7QbUl37Vd85ply1vyD8auM=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
<<<<<<< HEAD
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
=======
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
>>>>>>> origin/v4
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -113,25 +89,6 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
<<<<<<< HEAD
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.14.0 h1:2NiG67LD1tEH0D7kM+ps2V+fXmsAnpUeec7n8tcr4S0=
gonum.org/v1/gonum v0.14.0/go.mod h1:AoWeoz0becf9QMWtE8iWXNXc27fK4fNeHNf/oMejGfU=
=======
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -149,7 +106,6 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.15.1 h1:FNy7N6OUZVUaWG9pTiD+jlhdQ3lMP+/LcTpJ6+a8sQ0=
gonum.org/v1/gonum v0.15.1/go.mod h1:eZTZuRFrzu5pcyjN5wJhcIhnUdNijYxX1T2IcrOGY0o=
>>>>>>> origin/v4
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
45 changes: 24 additions & 21 deletions samples/runner/timingplatform.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/sarchlab/akita/v4/noc/networking/pcie"
"github.com/sarchlab/akita/v4/sim"
"github.com/sarchlab/akita/v4/tracing"
"github.com/sarchlab/akita/v4/datarecording"

Check failure on line 18 in samples/runner/timingplatform.go

View workflow job for this annotation

GitHub Actions / Compile

github.com/sarchlab/akita/v4@v4.0.0-alpha.5: replacement directory ../akita does not exist
"github.com/sarchlab/mgpusim/v4/driver"
)

Expand Down Expand Up @@ -213,28 +214,30 @@ func (b *R9NanoPlatformBuilder) setupVisTracing() {
return
}

var backend tracing.TracerBackend
switch *visTracerDB {
case "sqlite":
be := tracing.NewSQLiteTraceWriter(*visTracerDBFileName)
be.Init()
backend = be
case "csv":
be := tracing.NewCSVTraceWriter(*visTracerDBFileName)
be.Init()
backend = be
case "mysql":
be := tracing.NewMySQLTraceWriter()
be.Init()
backend = be
default:
panic(fmt.Sprintf(
"Tracer database type must be [sqlite|csv|mysql]. "+
"Provided value %s is not supported.",
*visTracerDB))
}
be := datarecording.NewSQLiteWriter(*visTracerDBFileName)
be.Init()
// switch *visTracerDB {
// case "sqlite":
// be := tracing.NewSQLiteTraceWriter(*visTracerDBFileName)
// be.Init()
// backend = be
// case "csv":
// be := tracing.NewCSVTraceWriter(*visTracerDBFileName)
// be.Init()
// backend = be
// case "mysql":
// be := tracing.NewMySQLTraceWriter()
// be.Init()
// backend = be
// default:
// panic(fmt.Sprintf(
// "Tracer database type must be [sqlite|csv|mysql]. "+
// "Provided value %s is not supported.",
// *visTracerDB))
// }

visTracer := tracing.NewDBTracer(b.engine, backend)
visTracer := tracing.NewDBTracer(b.engine, be)
tracing.SetTracer(visTracer)
visTracer.SetTimeRange(b.traceVisStartTime, b.traceVisEndTime)

b.visTracer = visTracer
Expand Down
5 changes: 5 additions & 0 deletions timing/cp/internal/dispatching/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ type DispatcherImpl struct {

monitor *monitoring.Monitor
progressBar *monitoring.ProgressBar
timeTeller sim.TimeTeller
}

func (d *DispatcherImpl) CurrentTime() sim.VTimeInSec {
return d.timeTeller.CurrentTime()
}

// Name returns the name of the dispatcher
Expand Down
7 changes: 6 additions & 1 deletion timing/cu/simdunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type SIMDUnit struct {
NumSinglePrecisionUnit int

isIdle bool
timeTeller sim.TimeTeller
}

func (u *SIMDUnit) CurrentTime() sim.VTimeInSec {
return u.timeTeller.CurrentTime()
}

// NewSIMDUnit creates a new branch unit, injecting the dependency of
Expand All @@ -39,7 +44,7 @@ func NewSIMDUnit(
u.cu = cu
u.scratchpadPreparer = scratchpadPreparer
u.alu = alu

u.timeTeller = cu.Engine
u.NumSinglePrecisionUnit = 16

return u
Expand Down
1 change: 0 additions & 1 deletion timing/rob/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func (b Builder) Build(name string) *ReorderBuffer {
rb.transactions = list.New()
rb.transactions.Init()
rb.toBottomReqIDToTransactionTable = make(map[string]*list.Element)
rb.hooks = make(map[*sim.HookPos][]sim.Hook)
rb.bufferSize = b.bufferSize
rb.numReqPerCycle = b.numReqPerCycle

Expand Down
8 changes: 0 additions & 8 deletions timing/rob/rob.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type ReorderBuffer struct {
toBottomReqIDToTransactionTable map[string]*list.Element
transactions *list.List
isFlushing bool
hooks map[*sim.HookPos][]sim.Hook
}

func (b *ReorderBuffer) getTaskID() string {
Expand All @@ -46,13 +45,6 @@ func (rob *ReorderBuffer) CurrentTime() sim.VTimeInSec {
return rob.Engine.CurrentTime()
}

func (b *ReorderBuffer) AddHook(pos *sim.HookPos, hook sim.Hook) {
if b.hooks == nil {
b.hooks = make(map[*sim.HookPos][]sim.Hook)
}
b.hooks[pos] = append(b.hooks[pos], hook)
}

// Tick updates the status of the ReorderBuffer.
func (b *ReorderBuffer) Tick() (madeProgress bool) {
madeProgress = b.processControlMsg() || madeProgress
Expand Down
46 changes: 11 additions & 35 deletions timing/rob/rob_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package rob

import (
"fmt"
"os"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -12,6 +12,8 @@ import (
)

var dataRecorder *datarecording.SQLiteWriter
var dbFile = "test_database.sqlite3"
var engine sim.Engine

type myHook struct {
f func(ctx sim.HookCtx)
Expand All @@ -21,33 +23,20 @@ func (h *myHook) Func(ctx sim.HookCtx) {
h.f(ctx)
}

type sqliteTracerBackend struct {
backend *datarecording.SQLiteWriter
}

func (b *sqliteTracerBackend) Write(task tracing.Task) {
b.backend.InsertData("tasks", task)
}

func (b *sqliteTracerBackend) WriteMilestone(milestone tracing.Milestone) {
b.backend.InsertData("milestones", milestone)
}

func (b *sqliteTracerBackend) Flush() {
b.backend.Flush()
}

var _ = BeforeSuite(func() {
os.Remove(dbFile)
dataRecorder = datarecording.NewSQLiteWriter("test_database")
dataRecorder.Init()
dataRecorder.CreateTable("milestones", tracing.Milestone{})
tracing.SetDataRecorder(dataRecorder)
engine = sim.NewSerialEngine()
tracer := tracing.NewDBTracer(engine, dataRecorder)
tracing.SetTracer(tracer)
})

var _ = AfterSuite(func() {
dataRecorder.Flush()
dataRecorder.DB.Close()
// os.Remove("test_database.sqlite3")
if dataRecorder != nil {
dataRecorder.Flush()
dataRecorder.Close()
}
})

var _ = Describe("Reorder Buffer", func() {
Expand All @@ -65,7 +54,6 @@ var _ = Describe("Reorder Buffer", func() {
topPort = NewMockPort(mockCtrl)
bottomPort = NewMockPort(mockCtrl)
ctrlPort = NewMockPort(mockCtrl)
engine := sim.NewSerialEngine()
rob = MakeBuilder().
WithBufferSize(10).
WithEngine(engine).
Expand All @@ -74,18 +62,6 @@ var _ = Describe("Reorder Buffer", func() {
rob.bottomPort = bottomPort
rob.controlPort = ctrlPort
rob.BottomUnit = NewMockPort(mockCtrl)
rob.AddHook(tracing.HookPosMilestone, &myHook{
f: func(ctx sim.HookCtx) {
milestone := ctx.Item.(tracing.Milestone)
fmt.Printf("Milestone in test: ID=%s, TaskID=%s, Category=%s, Reason=%s, Location=%s, Time=%f\n",
milestone.ID,
milestone.TaskID,
milestone.BlockingCategory,
milestone.BlockingReason,
milestone.BlockingLocation,
milestone.Time)
},
})
rob.TickLater()
})

Expand Down

0 comments on commit b46af20

Please sign in to comment.