Skip to content

Commit

Permalink
use map in trace
Browse files Browse the repository at this point in the history
Signed-off-by: Plamen Petrov <[email protected]>
  • Loading branch information
plamenmpetrov committed Aug 7, 2020
1 parent a427e28 commit abeaefb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ctriface/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.6.1
github.com/ustiugov/fccd-orchestrator/helloworld v0.0.0-20200717125634-528c6e9f9cc9
github.com/ustiugov/fccd-orchestrator/memory/manager v0.0.0-20200807153416-2487f79330d2
github.com/ustiugov/fccd-orchestrator/memory/manager v0.0.0-20200807161629-63048e4af761
github.com/ustiugov/fccd-orchestrator/metrics v0.0.0-20200803195925-0629e1cf4599
github.com/ustiugov/fccd-orchestrator/misc v0.0.0-20200803195925-0629e1cf4599
github.com/ustiugov/fccd-orchestrator/taps v0.0.0-20200717125634-528c6e9f9cc9
Expand Down
2 changes: 2 additions & 0 deletions ctriface/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ github.com/ustiugov/fccd-orchestrator/memory/manager v0.0.0-20200807143959-7b810
github.com/ustiugov/fccd-orchestrator/memory/manager v0.0.0-20200807143959-7b810ec04e41/go.mod h1:xfUe/OzRfVjB8iX4mUXirP4rLj6aQUvYtTxKkDfvzLM=
github.com/ustiugov/fccd-orchestrator/memory/manager v0.0.0-20200807153416-2487f79330d2 h1:VEtfhwyu+qauQ8EYbrstkuHhZmju2Zhue6PSzsHDFdo=
github.com/ustiugov/fccd-orchestrator/memory/manager v0.0.0-20200807153416-2487f79330d2/go.mod h1:xfUe/OzRfVjB8iX4mUXirP4rLj6aQUvYtTxKkDfvzLM=
github.com/ustiugov/fccd-orchestrator/memory/manager v0.0.0-20200807161629-63048e4af761 h1:787jyz6+0oukORdirmYh8hy5Z1WYPlFLeX5mgIpuA14=
github.com/ustiugov/fccd-orchestrator/memory/manager v0.0.0-20200807161629-63048e4af761/go.mod h1:xfUe/OzRfVjB8iX4mUXirP4rLj6aQUvYtTxKkDfvzLM=
github.com/ustiugov/fccd-orchestrator/metrics v0.0.0-20200722141002-55dbdeb43861 h1:rC47RJSLGILLDcXJ87gPnDZ/3DlfYcSWnAge3z8kQq8=
github.com/ustiugov/fccd-orchestrator/metrics v0.0.0-20200722141002-55dbdeb43861/go.mod h1:veO20AvWGKpDk3iD0IWJpfEnvF8PJVMK38n3SOWKKR0=
github.com/ustiugov/fccd-orchestrator/metrics v0.0.0-20200723085111-a9d697412510 h1:2F3Bp/P7C2UMKU+vakjEW/++E2yCntucHKNiRxcxQOE=
Expand Down
19 changes: 7 additions & 12 deletions memory/manager/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ type Trace struct {
sync.Mutex
traceFileName string

trace []Record
regions map[uint64]int
containedOffsets map[uint64]int
trace []Record
regions map[uint64]int
}

func initTrace(traceFileName string) *Trace {
t := new(Trace)

t.traceFileName = traceFileName
t.regions = make(map[uint64]int)
t.containedOffsets = make(map[uint64]int)
t.trace = make([]Record, 0)

return t
Expand All @@ -42,6 +44,7 @@ func (t *Trace) AppendRecord(r Record) {
defer t.Unlock()

t.trace = append(t.trace, r)
t.containedOffsets[r.offset] = 0
}

// WriteTrace Writes all the records to a file
Expand Down Expand Up @@ -118,18 +121,10 @@ func (t *Trace) sortTrace() {
}

// Search trace for the record with the same offset
// Assumes sorted trace
func (t *Trace) containsRecord(rec Record) bool {
for _, trRec := range t.trace {
if rec.offset == trRec.offset {
return true
}
if rec.offset < trRec.offset {
return false
}
}
_, ok := t.containedOffsets[rec.offset]

return false
return ok
}

// processRegions
Expand Down

0 comments on commit abeaefb

Please sign in to comment.