William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 1 | // +build !linux appengine |
| 2 | |
| 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 | |
| 21 | package syscall |
| 22 | |
| 23 | import ( |
| 24 | "net" |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 25 | "sync" |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 26 | "time" |
| 27 | |
| 28 | "google.golang.org/grpc/grpclog" |
| 29 | ) |
| 30 | |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 31 | var once sync.Once |
| 32 | |
| 33 | func log() { |
| 34 | once.Do(func() { |
| 35 | grpclog.Info("CPU time info is unavailable on non-linux or appengine environment.") |
| 36 | }) |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | // GetCPUTime returns the how much CPU time has passed since the start of this process. |
| 40 | // It always returns 0 under non-linux or appengine environment. |
| 41 | func GetCPUTime() int64 { |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 42 | log() |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 43 | return 0 |
| 44 | } |
| 45 | |
| 46 | // Rusage is an empty struct under non-linux or appengine environment. |
| 47 | type Rusage struct{} |
| 48 | |
| 49 | // GetRusage is a no-op function under non-linux or appengine environment. |
| 50 | func GetRusage() (rusage *Rusage) { |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 51 | log() |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 52 | return nil |
| 53 | } |
| 54 | |
| 55 | // CPUTimeDiff returns the differences of user CPU time and system CPU time used |
| 56 | // between two Rusage structs. It a no-op function for non-linux or appengine environment. |
| 57 | func CPUTimeDiff(first *Rusage, latest *Rusage) (float64, float64) { |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 58 | log() |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 59 | return 0, 0 |
| 60 | } |
| 61 | |
| 62 | // SetTCPUserTimeout is a no-op function under non-linux or appengine environments |
| 63 | func SetTCPUserTimeout(conn net.Conn, timeout time.Duration) error { |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 64 | log() |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 65 | return nil |
| 66 | } |
| 67 | |
| 68 | // GetTCPUserTimeout is a no-op function under non-linux or appengine environments |
| 69 | // a negative return value indicates the operation is not supported |
| 70 | func GetTCPUserTimeout(conn net.Conn) (int, error) { |
Abhilash S.L | 3b49463 | 2019-07-16 15:51:09 +0530 | [diff] [blame] | 71 | log() |
William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 72 | return -1, nil |
| 73 | } |