number of cores being used is added to log on startup

This commit is contained in:
JetSetIlly 2023-01-05 21:52:26 +00:00
parent 68a2277edb
commit 5410a9b936
4 changed files with 38 additions and 91 deletions

View file

@ -21,6 +21,7 @@ import (
"math/rand"
"os"
"os/signal"
"runtime"
"strings"
"time"
@ -210,6 +211,8 @@ func main() {
// launch is called from main() as a goroutine. uses mainSync instance to
// indicate gui creation and to quit.
func launch(sync *mainSync) {
logger.Log("runtime", fmt.Sprintf("number of cores being used: %d", runtime.NumCPU()))
// we generate random numbers in some places. seed the generator with the
// current time
rand.Seed(int64(time.Now().Nanosecond()))
@ -334,9 +337,9 @@ func emulate(emulationMode govern.Mode, md *modalflag.Modes, sync *mainSync) err
// and available via the debugger but will not be "echoed" to the terminal,
// unless this option is on
if *opts.Log {
logger.SetEcho(logger.NewColorizer(os.Stdout))
logger.SetEcho(os.Stdout, true)
} else {
logger.SetEcho(nil)
logger.SetEcho(nil, false)
}
// turn off fallback ctrl-c handling. this so that the debugger can handle
@ -525,9 +528,9 @@ func perform(md *modalflag.Modes, sync *mainSync) error {
// set debugging log echo
if *log {
logger.SetEcho(logger.NewColorizer(os.Stdout))
logger.SetEcho(os.Stdout, true)
} else {
logger.SetEcho(nil)
logger.SetEcho(nil, false)
}
switch len(md.RemainingArgs()) {
@ -716,10 +719,10 @@ with the LOG mode. Note that asking for log output will suppress regression prog
// set debugging log echo
if *log {
logger.SetEcho(logger.NewColorizer(os.Stdout))
logger.SetEcho(os.Stdout, true)
md.Output = &nopWriter{}
} else {
logger.SetEcho(nil)
logger.SetEcho(nil, false)
}
switch len(md.RemainingArgs()) {

View file

@ -60,9 +60,9 @@ func Tail(output io.Writer, number int) {
central.tail(output, number)
}
// SetEcho to print new entries to os.Stdout.
func SetEcho(output io.Writer) {
central.setEcho(output)
// SetEcho prints log entries to io.Writer.
func SetEcho(output io.Writer, writeRecent bool) {
central.setEcho(output, writeRecent)
}
// BorrowLog gives the provided function the critial section and access to the

View file

@ -1,72 +0,0 @@
// This file is part of Gopher2600.
//
// Gopher2600 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Gopher2600 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
package logger
import (
"io"
"strings"
"github.com/jetsetilly/gopher2600/debugger/terminal/colorterm/easyterm/ansi"
)
// Colorizer applies basic coloring rules to logging output.
type Colorizer struct {
out io.Writer
}
// NewColorizer is the preferred method if initialisation for the Colorizer type.
func NewColorizer(out io.Writer) Colorizer {
return Colorizer{out: out}
}
// Write implements the io.Writer interface.
func (c Colorizer) Write(p []byte) (n int, err error) {
n = 0
l := strings.Split(strings.TrimSpace(string(p)), "\n")
if len(l) == 0 {
return n, nil
}
m, err := c.out.Write([]byte(l[0] + "\n"))
if err != nil {
return n + m, err
}
n += m
if len(l) == 1 {
return n, nil
}
m, err = c.out.Write([]byte(ansi.DimPens["red"]))
if err != nil {
return n + m, err
}
for _, s := range l[1:] {
m, err := c.out.Write([]byte(s + "\n"))
if err != nil {
return n + m, err
}
n += m
}
defer func() {
_, _ = c.out.Write([]byte(ansi.NormalPen))
}()
return n, nil
}

View file

@ -96,6 +96,7 @@ func (l *logger) log(tag, detail string) {
if l.echo != nil {
l.echo.Write([]byte(e.String()))
l.echo.Write([]byte("\n"))
}
}
@ -112,6 +113,10 @@ func (l *logger) clear() {
}
func (l *logger) write(output io.Writer) {
if output == nil {
return
}
l.crit.Lock()
defer l.crit.Unlock()
@ -125,34 +130,45 @@ func (l *logger) writeRecent(output io.Writer) {
l.crit.Lock()
defer l.crit.Unlock()
for _, e := range l.entries[l.recentStart:] {
io.WriteString(output, e.String())
io.WriteString(output, "\n")
if output != nil {
for _, e := range l.entries[l.recentStart:] {
io.WriteString(output, e.String())
io.WriteString(output, "\n")
}
}
l.recentStart = len(l.entries)
}
func (l *logger) tail(output io.Writer, number int) {
if output == nil {
return
}
l.crit.Lock()
defer l.crit.Unlock()
s := len(l.entries) - number
if s < 0 {
s = 0
var n int
n = len(l.entries) - number
if n < 0 {
n = 0
}
for _, e := range l.entries[s:] {
for _, e := range l.entries[n:] {
io.WriteString(output, e.String())
io.WriteString(output, "\n")
}
}
func (l *logger) setEcho(output io.Writer) {
func (l *logger) setEcho(output io.Writer, writeRecent bool) {
l.crit.Lock()
defer l.crit.Unlock()
l.echo = output
l.crit.Unlock()
if writeRecent {
l.writeRecent(output)
}
}
func (l *logger) borrowLog(f func([]Entry)) {