Skip to content

Commit

Permalink
pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Aug 25, 2024
1 parent 17b6545 commit 8542417
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
11 changes: 11 additions & 0 deletions cmd/WatchYourLAN/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"flag"
// "net/http"

// _ "net/http/pprof"
_ "time/tzdata"

"github.com/aceberg/WatchYourLAN/internal/web"
Expand All @@ -16,5 +18,14 @@ func main() {
nodePtr := flag.String("n", nodePath, "Path to node modules")
flag.Parse()

// pprof - memory leak detect
// go tool pprof -alloc_space http://localhost:8085/debug/pprof/heap
// (pprof) web
// (pprof) list db.Select
//
// go func() {
// http.ListenAndServe("localhost:8085", nil)
// }()

web.Gui(*dirPtr, *nodePtr) // webgui.go
}
2 changes: 2 additions & 0 deletions internal/web/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func apiAll(c *gin.Context) {
func apiHistory(c *gin.Context) {
var hosts []models.Host

histHosts := db.Select(appConfig.DBPath, "history")

mac := c.Param("mac")

if mac != "/" {
Expand Down
4 changes: 2 additions & 2 deletions internal/web/const-var.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var (
// appConfig - config for Web Gui
appConfig models.Conf

allHosts []models.Host
histHosts []models.Host
allHosts []models.Host
// histHosts []models.Host

quitScan chan bool
)
Expand Down
1 change: 0 additions & 1 deletion internal/web/routines-upd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func updateRoutines() {
db.Create(appConfig.DBPath)

allHosts = db.Select(appConfig.DBPath, "now")
histHosts = db.Select(appConfig.DBPath, "history")

quitScan = make(chan bool)
go startScan(quitScan) // scan-routine.go
Expand Down
15 changes: 5 additions & 10 deletions internal/web/scan-routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import (
"github.com/aceberg/WatchYourLAN/internal/notify"
)

var foundHostsMap map[string]models.Host
var aHost, fHost models.Host
var exists bool

func startScan(quit chan bool) {
var lastDate, nowDate, plusDate time.Time
var foundHosts []models.Host
Expand All @@ -33,7 +29,6 @@ func startScan(quit chan bool) {
foundHosts = arp.Scan(appConfig.Ifaces)
compareHosts(foundHosts)
allHosts = db.Select(appConfig.DBPath, "now")
histHosts = db.Select(appConfig.DBPath, "history")

lastDate = time.Now()
}
Expand All @@ -46,14 +41,14 @@ func startScan(quit chan bool) {
func compareHosts(foundHosts []models.Host) {

// Make map of found hosts
foundHostsMap = make(map[string]models.Host)
for _, fHost = range foundHosts {
foundHostsMap := make(map[string]models.Host)
for _, fHost := range foundHosts {
foundHostsMap[fHost.Mac] = fHost
}

for _, aHost = range allHosts {
for _, aHost := range allHosts {

fHost, exists = foundHostsMap[aHost.Mac]
fHost, exists := foundHostsMap[aHost.Mac]
if exists {

aHost.Iface = fHost.Iface
Expand All @@ -75,7 +70,7 @@ func compareHosts(foundHosts []models.Host) {
}
}

for _, fHost = range foundHostsMap {
for _, fHost := range foundHostsMap {

msg := fmt.Sprintf("Unknown host IP: '%s', MAC: '%s', Hw: '%s', Iface: '%s'", fHost.IP, fHost.Mac, fHost.Hw, fHost.Iface)
slog.Warn(msg)
Expand Down

0 comments on commit 8542417

Please sign in to comment.