2 * Copyright (c) 2014 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/resource.h>
23 #include "openvswitch/vlog.h"
25 VLOG_DEFINE_THIS_MODULE(getrusage_windows
);
28 usage_to_timeval(FILETIME
*ft
, struct timeval
*tv
)
31 time
.LowPart
= ft
->dwLowDateTime
;
32 time
.HighPart
= ft
->dwHighDateTime
;
34 tv
->tv_sec
= time
.QuadPart
/ 10000000;
35 tv
->tv_usec
= (time
.QuadPart
% 10000000) / 10;
39 getrusage(int who
, struct rusage
*usage
)
41 FILETIME creation_time
, exit_time
, kernel_time
, user_time
;
42 PROCESS_MEMORY_COUNTERS pmc
;
44 memset(usage
, 0, sizeof(struct rusage
));
46 if (who
== RUSAGE_SELF
) {
47 if (!GetProcessTimes(GetCurrentProcess(), &creation_time
, &exit_time
,
48 &kernel_time
, &user_time
)) {
49 VLOG_ERR("failed at GetProcessTimes: %s",
50 ovs_lasterror_to_string());
54 if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc
, sizeof(pmc
))) {
55 VLOG_ERR("failed at GetProcessMemoryInfo: %s",
56 ovs_lasterror_to_string());
60 usage_to_timeval(&kernel_time
, &usage
->ru_stime
);
61 usage_to_timeval(&user_time
, &usage
->ru_utime
);
62 usage
->ru_majflt
= pmc
.PageFaultCount
;
63 usage
->ru_maxrss
= pmc
.PeakWorkingSetSize
/ 1024;
65 } else if (who
== RUSAGE_THREAD
) {
66 if (!GetThreadTimes(GetCurrentThread(), &creation_time
, &exit_time
,
67 &kernel_time
, &user_time
)) {
68 VLOG_ERR("failed at GetThreadTimes: %s",
69 ovs_lasterror_to_string());
72 usage_to_timeval(&kernel_time
, &usage
->ru_stime
);
73 usage_to_timeval(&user_time
, &usage
->ru_utime
);