syscall_nonlinux.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //go:build !linux
  2. // +build !linux
  3. /*
  4. *
  5. * Copyright 2018 gRPC authors.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. */
  20. // Package syscall provides functionalities that grpc uses to get low-level
  21. // operating system stats/info.
  22. package syscall
  23. import (
  24. "net"
  25. "sync"
  26. "time"
  27. "google.golang.org/grpc/grpclog"
  28. )
  29. var once sync.Once
  30. var logger = grpclog.Component("core")
  31. func log() {
  32. once.Do(func() {
  33. logger.Info("CPU time info is unavailable on non-linux environments.")
  34. })
  35. }
  36. // GetCPUTime returns the how much CPU time has passed since the start of this
  37. // process. It always returns 0 under non-linux environments.
  38. func GetCPUTime() int64 {
  39. log()
  40. return 0
  41. }
  42. // Rusage is an empty struct under non-linux environments.
  43. type Rusage struct{}
  44. // GetRusage is a no-op function under non-linux environments.
  45. func GetRusage() *Rusage {
  46. log()
  47. return nil
  48. }
  49. // CPUTimeDiff returns the differences of user CPU time and system CPU time used
  50. // between two Rusage structs. It a no-op function for non-linux environments.
  51. func CPUTimeDiff(first *Rusage, latest *Rusage) (float64, float64) {
  52. log()
  53. return 0, 0
  54. }
  55. // SetTCPUserTimeout is a no-op function under non-linux environments.
  56. func SetTCPUserTimeout(conn net.Conn, timeout time.Duration) error {
  57. log()
  58. return nil
  59. }
  60. // GetTCPUserTimeout is a no-op function under non-linux environments.
  61. // A negative return value indicates the operation is not supported
  62. func GetTCPUserTimeout(conn net.Conn) (int, error) {
  63. log()
  64. return -1, nil
  65. }