syscall_nonlinux.go 1.9 KB

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