From 3b35ea570d6892cc0dfd1b09497b6ff5b93b1b30 Mon Sep 17 00:00:00 2001 From: cmwslw Date: Sat, 26 Aug 2017 14:29:46 -0700 Subject: [PATCH] Improve profiling system. --- examples/test_rubi.m | 4 ++-- expreduce/builtin_system.go | 5 +++-- expreduce/caslogger.go | 2 ++ expreduce/time_counter.go | 7 ++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/test_rubi.m b/examples/test_rubi.m index 28a9e06..a166e02 100644 --- a/examples/test_rubi.m +++ b/examples/test_rubi.m @@ -12,10 +12,10 @@ If[res === testp[[4]], Print[thei]]; ); -(*While[testi <= Length[testproblems], +While[testi <= Length[testproblems], (*Print["hi ", testi]*) If[(testi>34&&testi<47)||MemberQ[{50, 52, 53, 54, 55, 56, 57, 58, 59, 211, 214, 215, 216, 218, 222, 223, 224, 225, 228, 229, 231, 232, 233}, testi] || (testi>=160&&testi<=166), Null, runRubiTest[testi]; ]; testi = testi+1; -];*) +]; diff --git a/expreduce/builtin_system.go b/expreduce/builtin_system.go index 89abc5c..0983500 100644 --- a/expreduce/builtin_system.go +++ b/expreduce/builtin_system.go @@ -198,9 +198,10 @@ func GetSystemDefinitions() (defs []Definition) { sym, ok := this.Parts[1].(*Symbol) if ok { if sym.Name == "System`True" { + errorStr := "Invalid level. Must be one of {Debug, Info, Notice}." levelSym, lsOk := this.Parts[2].(*Symbol) if !lsOk { - return NewExpression([]Ex{&Symbol{"System`Error"}, &String{"Invalid level."}}) + return NewExpression([]Ex{&Symbol{"System`Error"}, &String{errorStr}}) } if levelSym.Name == "System`Debug" { es.DebugOn(logging.DEBUG) @@ -209,7 +210,7 @@ func GetSystemDefinitions() (defs []Definition) { } else if levelSym.Name == "System`Notice" { es.DebugOn(logging.NOTICE) } else { - return NewExpression([]Ex{&Symbol{"System`Error"}, &String{"Invalid level."}}) + return NewExpression([]Ex{&Symbol{"System`Error"}, &String{errorStr}}) } return &Symbol{"System`Null"} } else if sym.Name == "System`False" { diff --git a/expreduce/caslogger.go b/expreduce/caslogger.go index aab985d..7db09b0 100644 --- a/expreduce/caslogger.go +++ b/expreduce/caslogger.go @@ -40,11 +40,13 @@ func (this *CASLogger) Errorf(fmt string, args ...interface{}) { func (this *CASLogger) DebugOn(level logging.Level) { this.leveled.SetLevel(level, "") this.debugState = true + this.SetProfiling(true) } func (this *CASLogger) DebugOff() { this.leveled.SetLevel(logging.ERROR, "") this.debugState = false + this.SetProfiling(false) } func (this *CASLogger) DebugState() bool { diff --git a/expreduce/time_counter.go b/expreduce/time_counter.go index b630c1a..e80d863 100644 --- a/expreduce/time_counter.go +++ b/expreduce/time_counter.go @@ -7,17 +7,21 @@ import ( ) type TimeMap map[string]float64 +type CountMap map[string]int64 type TimeCounter struct { times TimeMap + counts CountMap } func (tc *TimeCounter) Init() { tc.times = make(TimeMap) + tc.counts = make(CountMap) } func (tc *TimeCounter) AddTime(key string, elapsed float64) { tc.times[key] += elapsed + tc.counts[key] += 1 } func (tc *TimeCounter) Update(other *TimeCounter) { @@ -43,7 +47,8 @@ func (tc *TimeCounter) TruncatedString(numToPrint int) string { break } for _, s := range n[k] { - buffer.WriteString(fmt.Sprintf("%v, %v\n", k, s)) + count := tc.counts[s] + buffer.WriteString(fmt.Sprintf("%v, %v, %v\n", k, count, s)) numPrinted++ } }