1//  Copyright (c) 2016 Couchbase, Inc.
2//  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
3//  except in compliance with the License. You may obtain a copy of the License at
4//    http://www.apache.org/licenses/LICENSE-2.0
5//  Unless required by applicable law or agreed to in writing, software distributed under the
6//  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
7//  either express or implied. See the License for the specific language governing permissions
8//  and limitations under the License.
9
10// +build !windows,!solaris
11
12package util
13
14import (
15	"syscall"
16
17	"github.com/couchbase/query/logging"
18)
19
20func CpuTimes() (int64, int64) {
21	ru := syscall.Rusage{}
22	if err := syscall.Getrusage(syscall.RUSAGE_SELF, &ru); err != nil {
23		logging.Errorf(err.Error())
24		return int64(0), int64(0)
25	}
26
27	newUtime := int64(ru.Utime.Nano())
28	newStime := int64(ru.Stime.Nano())
29	return newUtime, newStime
30}
31