git://git.iain.cx/iain
/
pstop.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Adjust README.md and allow left and right arrow keys to navigate
[pstop.git]
/
main.go
diff --git
a/main.go
b/main.go
index
662743e
..
545170c
100644
(file)
--- a/
main.go
+++ b/
main.go
@@
-1,4
+1,4
@@
-// Top like progream which collects information from MySQL's
+//
pstop -
Top like progream which collects information from MySQL's
// performance_schema database.
package main
// performance_schema database.
package main
@@
-22,6
+22,7
@@
import (
"github.com/sjmudd/pstop/lib"
"github.com/sjmudd/pstop/state"
"github.com/sjmudd/pstop/version"
"github.com/sjmudd/pstop/lib"
"github.com/sjmudd/pstop/state"
"github.com/sjmudd/pstop/version"
+ "github.com/sjmudd/pstop/wait_info"
)
const (
)
const (
@@
-85,7
+86,7
@@
func usage() {
func validate_mysql_version(dbh *sql.DB) error {
var tables = [...]string{
"performance_schema.file_summary_by_instance",
func validate_mysql_version(dbh *sql.DB) error {
var tables = [...]string{
"performance_schema.file_summary_by_instance",
- "performance_
S
chema.table_io_waits_summary_by_table",
+ "performance_
s
chema.table_io_waits_summary_by_table",
"performance_schema.table_lock_waits_summary_by_table",
}
"performance_schema.table_lock_waits_summary_by_table",
}
@@
-150,7
+151,9
@@
func main() {
}
var state state.State
}
var state state.State
- interval := time.Second
+ var wi wait_info.WaitInfo
+ wi.SetWaitInterval(time.Second)
+
sigChan := make(chan os.Signal, 1)
done := make(chan struct{})
defer close(done)
sigChan := make(chan os.Signal, 1)
done := make(chan struct{})
defer close(done)
@@
-158,8
+161,6
@@
func main() {
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
- ticker := time.NewTicker(interval) // generate a periodic signal
-
state.Setup(dbh)
finished := false
state.Setup(dbh)
finished := false
@@
-171,8
+172,9
@@
func main() {
case sig := <-sigChan:
fmt.Println("Caught a signal", sig)
done <- struct{}{}
case sig := <-sigChan:
fmt.Println("Caught a signal", sig)
done <- struct{}{}
- case <-
ticker.C
:
+ case <-
wi.WaitNextPeriod()
:
state.Collect()
state.Collect()
+ wi.CollectedNow()
state.Display()
case event := <-termboxChan:
// switch on event type
state.Display()
case event := <-termboxChan:
// switch on event type
@@
-181,21
+183,20
@@
func main() {
switch event.Key {
case termbox.KeyCtrlZ, termbox.KeyCtrlC, termbox.KeyEsc:
finished = true
switch event.Key {
case termbox.KeyCtrlZ, termbox.KeyCtrlC, termbox.KeyEsc:
finished = true
- case termbox.KeyTab: // tab - change display modes
+ case termbox.KeyArrowLeft: // left arrow change to previous display mode
+ state.DisplayPrevious()
+ state.Display()
+ case termbox.KeyTab, termbox.KeyArrowRight: // tab or right arrow - change to next display mode
state.DisplayNext()
state.Display()
}
switch event.Ch {
case '-': // decrease the interval if > 1
state.DisplayNext()
state.Display()
}
switch event.Ch {
case '-': // decrease the interval if > 1
- if interval > time.Second {
- ticker.Stop()
- interval -= time.Second
- ticker = time.NewTicker(interval)
+ if wi.WaitInterval() > time.Second {
+ wi.SetWaitInterval(wi.WaitInterval() - time.Second)
}
case '+': // increase interval by creating a new ticker
}
case '+': // increase interval by creating a new ticker
- ticker.Stop()
- interval += time.Second
- ticker = time.NewTicker(interval)
+ wi.SetWaitInterval(wi.WaitInterval() + time.Second)
case 'h': // help
state.SetHelp(!state.Help())
case 'q': // quit
case 'h': // help
state.SetHelp(!state.Help())
case 'q': // quit
@@
-216,6
+217,5
@@
func main() {
}
}
state.Cleanup()
}
}
state.Cleanup()
- ticker.Stop()
lib.Logger.Println("Terminating " + lib.MyName())
}
lib.Logger.Println("Terminating " + lib.MyName())
}