-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add gnmi_dump tool for debug and unit test #60
Merged
+282
−13
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f750373
Add gnmi_dump tool for debug and unit test.
ganglyu fd01aa9
Add test case to improve coverage.
ganglyu 5ffcc3a
Fix test bug
ganglyu 9b3a841
Merge branch 'master' into gnmi_dump
ganglyu 52e5d89
Update test case.
ganglyu ce50a22
Use enum to replace string.
ganglyu 7ce8590
Use t.Fatalf
ganglyu b3e3ce4
Merge branch 'master' into gnmi_dump
ganglyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,64 @@ | ||
package common_utils | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
// Use share memory to dump GNMI internal counters, | ||
// GNMI server and gnmi_dump should use memKey to access the share memory, | ||
// memSize is 1024 bytes, so we can support 128 counters | ||
// memMode is 0x380, this value is O_RDWR|IPC_CREAT, | ||
// O_RDWR means: Owner can write and read the file, everyone else can't. | ||
// IPC_CREAT means: Create a shared memory segment if a shared memory identifier does not exist for memKey. | ||
var ( | ||
memKey = 7749 | ||
memSize = 1024 | ||
memMode = 0x380 | ||
) | ||
|
||
func SetMemCounters(counters *[int(COUNTER_SIZE)]uint64) error { | ||
shmid, _, err := syscall.Syscall(syscall.SYS_SHMGET, uintptr(memKey), uintptr(memSize), uintptr(memMode)) | ||
if int(shmid) == -1 { | ||
return fmt.Errorf("syscall error, err: %v\n", err) | ||
} | ||
|
||
shmaddr, _, err := syscall.Syscall(syscall.SYS_SHMAT, shmid, 0, 0) | ||
if int(shmaddr) == -1 { | ||
return fmt.Errorf("syscall error, err: %v\n", err) | ||
} | ||
defer syscall.Syscall(syscall.SYS_SHMDT, shmaddr, 0, 0) | ||
|
||
const size = unsafe.Sizeof(uint64(0)) | ||
addr := uintptr(unsafe.Pointer(shmaddr)) | ||
|
||
for i := 0; i < len(counters); i++ { | ||
*(*uint64)(unsafe.Pointer(addr)) = counters[i] | ||
addr += size | ||
} | ||
return nil | ||
} | ||
|
||
func GetMemCounters(counters *[int(COUNTER_SIZE)]uint64) error { | ||
shmid, _, err := syscall.Syscall(syscall.SYS_SHMGET, uintptr(memKey), uintptr(memSize), uintptr(memMode)) | ||
if int(shmid) == -1 { | ||
return fmt.Errorf("syscall error, err: %v\n", err) | ||
} | ||
|
||
shmaddr, _, err := syscall.Syscall(syscall.SYS_SHMAT, shmid, 0, 0) | ||
if int(shmaddr) == -1 { | ||
return fmt.Errorf("syscall error, err: %v\n", err) | ||
} | ||
defer syscall.Syscall(syscall.SYS_SHMDT, shmaddr, 0, 0) | ||
|
||
const size = unsafe.Sizeof(uint64(0)) | ||
addr := uintptr(unsafe.Pointer(shmaddr)) | ||
|
||
for i := 0; i < len(counters); i++ { | ||
counters[i] = *(*uint64)(unsafe.Pointer(addr)) | ||
addr += size | ||
} | ||
return 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,30 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/sonic-net/sonic-gnmi/common_utils" | ||
) | ||
|
||
const help = ` | ||
gnmi_dump is used to dump internal counters for debugging purpose, | ||
including GNMI request counter, GNOI request counter and DBUS request counter. | ||
` | ||
|
||
func main() { | ||
flag.Usage = func() { | ||
fmt.Print(help) | ||
} | ||
flag.Parse() | ||
var counters [common_utils.COUNTER_SIZE]uint64 | ||
err := common_utils.GetMemCounters(&counters) | ||
if err != nil { | ||
fmt.Printf("Error: Fail to read counters, %v", err) | ||
return | ||
} | ||
fmt.Printf("Dump GNMI counters\n") | ||
for i := 0; i < int(common_utils.COUNTER_SIZE); i++ { | ||
cnt := common_utils.CounterType(i) | ||
fmt.Printf("%v---%v\n", cnt.String(), counters[i]) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing this check? If this is significant change, add some PR description, even add it into PR title. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I move the check to line 353 to simplify logic for set fail, when EnableTranslibWrite is false, no need to authenticate and no need to update result.