some memory profiling and optimization

This commit is contained in:
Radu Ioan Fericean
2013-12-14 15:20:58 +02:00
parent 237508e590
commit 5a929dfeb0
3 changed files with 20 additions and 21 deletions

View File

@@ -48,15 +48,6 @@ func main() {
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
f.Close()
return
}
cd := engine.CallDescriptor{
TimeStart: time.Date(2013, time.December, 13, 22, 30, 0, 0, time.UTC),
TimeEnd: time.Date(2013, time.December, 13, 22, 31, 0, 0, time.UTC),
@@ -84,7 +75,18 @@ func main() {
j := 0
start := time.Now()
for i := 0; i < *runs; i++ {
runtime.MemProfileRate = 1
result, err = cd.GetCost()
if *memprofile != "" {
runtime.GC()
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
f.Close()
break
}
j = i
}
duration := time.Since(start)

View File

@@ -266,17 +266,13 @@ func (cd *CallDescriptor) addRatingInfos(ris RatingInfos) bool {
return true
}
/*
Constructs the key for the storage lookup.
The prefixLen is limiting the length of the destination prefix.
*/
// Constructs the key for the storage lookup.
// The prefixLen is limiting the length of the destination prefix.
func (cd *CallDescriptor) GetKey(subject string) string {
return fmt.Sprintf("%s:%s:%s:%s", cd.Direction, cd.Tenant, cd.TOR, subject)
}
/*
Splits the received timespan into sub time spans according to the activation periods intervals.
*/
// Splits the received timespan into sub time spans according to the activation periods intervals.
func (cd *CallDescriptor) splitInTimeSpans(firstSpan *TimeSpan) (timespans []*TimeSpan) {
if firstSpan == nil {
firstSpan = &TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cd.TimeEnd, CallDuration: cd.CallDuration}

View File

@@ -40,15 +40,16 @@ func (rpr *RPRate) Equal(orpr *RPRate) bool {
type RPRateList []*RPRate
func (rp *RatingPlan) RateIntervalList(dId string) (ril RateIntervalList) {
for _, rpr := range rp.DestinationRates[dId] {
ril = append(ril, &RateInterval{
func (rp *RatingPlan) RateIntervalList(dId string) RateIntervalList {
ril := make(RateIntervalList, len(rp.DestinationRates[dId]))
for i, rpr := range rp.DestinationRates[dId] {
ril[i] = &RateInterval{
Timing: rp.Timings[rpr.Timing],
Rating: rp.Ratings[rpr.Rating],
Weight: rpr.Weight,
})
}
}
return
return ril
}
/*