mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
optimization: optimized locking and op atomicity for the packets queue and network statistics view
This commit is contained in:
parent
3131660493
commit
305e22ee2e
3 changed files with 33 additions and 20 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
|
@ -112,9 +113,6 @@ func (d *Discovery) showTable(header []string, rows [][]string) {
|
|||
}
|
||||
|
||||
func (d *Discovery) Show(by string) error {
|
||||
d.Session.Queue.Lock()
|
||||
defer d.Session.Queue.Unlock()
|
||||
|
||||
targets := d.Session.Targets.List()
|
||||
if by == "seen" {
|
||||
sort.Sort(BySeenSorter(targets))
|
||||
|
@ -146,11 +144,11 @@ func (d *Discovery) Show(by string) error {
|
|||
|
||||
fmt.Printf("\n%s %s / %s %s / %d pkts / %d errs\n\n",
|
||||
core.Red("↑"),
|
||||
humanize.Bytes(d.Session.Queue.Sent),
|
||||
humanize.Bytes(atomic.LoadUint64(&d.Session.Queue.Sent)),
|
||||
core.Green("↓"),
|
||||
humanize.Bytes(d.Session.Queue.Received),
|
||||
d.Session.Queue.PktReceived,
|
||||
d.Session.Queue.Errors)
|
||||
humanize.Bytes(atomic.LoadUint64(&d.Session.Queue.Received)),
|
||||
atomic.LoadUint64(&d.Session.Queue.PktReceived),
|
||||
atomic.LoadUint64(&d.Session.Queue.Errors))
|
||||
|
||||
s := EventsStream{}
|
||||
events := d.Session.Events.Sorted()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue