-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* to log memory stats, num goroutines, num open files * for the latter, add platform dependent bits * with refactoring Signed-off-by: Alex Aizman <[email protected]>
- Loading branch information
1 parent
2620901
commit 7a54c91
Showing
4 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Package hk provides mechanism for registering cleanup | ||
// functions which are invoked at specified intervals. | ||
/* | ||
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package hk | ||
|
||
import "errors" | ||
|
||
func numOpenFiles() (int, error) { | ||
return 0, errors.New("num-open-files not implemented yet") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Package hk provides mechanism for registering cleanup | ||
// functions which are invoked at specified intervals. | ||
/* | ||
* Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package hk | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
) | ||
|
||
// TODO: consider moving to `cos` and logging (`stats`) every 4h or so | ||
func numOpenFiles() (int, error) { | ||
var ( | ||
pid = os.Getpid() | ||
proddir = filepath.Join("/proc", strconv.Itoa(pid), "fd") | ||
dir, err = os.Open(proddir) | ||
) | ||
if err != nil { | ||
return 0, err | ||
} | ||
defer dir.Close() | ||
|
||
// read just the names | ||
names, e := dir.Readdirnames(0) | ||
if e != nil { | ||
return 0, e | ||
} | ||
return len(names), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Package hk provides mechanism for registering cleanup | ||
// functions which are invoked at specified intervals. | ||
/* | ||
* Copyright (c) 2018-2025, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package hk | ||
|
||
import ( | ||
"os/signal" | ||
"runtime" | ||
"strings" | ||
"syscall" | ||
|
||
"github.com/NVIDIA/aistore/cmn/cos" | ||
"github.com/NVIDIA/aistore/cmn/nlog" | ||
"github.com/NVIDIA/aistore/sys" | ||
) | ||
|
||
func (hk *hk) setSignal() { | ||
signal.Notify(hk.sigCh, | ||
// ignore | ||
syscall.SIGHUP, // kill -SIGHUP | ||
// terminate | ||
syscall.SIGINT, // kill -SIGINT (Ctrl-C) | ||
syscall.SIGTERM, // kill -SIGTERM | ||
syscall.SIGQUIT, // kill -SIGQUIT | ||
) | ||
} | ||
|
||
func (hk *hk) handleSignal(s syscall.Signal) error { | ||
if s == syscall.SIGHUP { | ||
// no-op: show up in the log with some useful info | ||
var ( | ||
sb strings.Builder | ||
mem sys.MemStat | ||
ngr = runtime.NumGoroutine() | ||
) | ||
erm := mem.Get() | ||
mem.Str(&sb) | ||
nfd, erf := numOpenFiles() | ||
nlog.Infoln("ngr [", ngr, sys.NumCPU(), "] mem [", sb.String(), erm, "]", "num-fd [", nfd, erf, "]") | ||
return nil | ||
} | ||
|
||
signal.Stop(hk.sigCh) | ||
err := cos.NewSignalError(s) | ||
hk.Stop(err) | ||
return err | ||
} |