Skip to content

Commit 37af582

Browse files
committed
remove threadtime and rename walltime to realtime and processtime to cputime
1 parent 27bf87a commit 37af582

File tree

4 files changed

+11
-75
lines changed

4 files changed

+11
-75
lines changed

src/timers/darwin.jl

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,13 @@ end
3131
return user+kernel
3232
end
3333

34-
struct time_value_t
35-
seconds::Cint
36-
microseconds::Cint
34+
@inline function realtime()
35+
Float64(Base.time_ns())
3736
end
3837

39-
struct thread_basic_info
40-
user_time::time_value_t
41-
system_time::time_value_t
42-
cpu_usage::Cint
43-
policy::Cint
44-
run_state::Cint
45-
flags::Cint
46-
suspend_count::Cint
47-
sleep_time::Cint
48-
end
49-
50-
@inline function maketime(info::thread_basic_info)
51-
user = info.user_time.seconds * 1e9 + info.user_time.microseconds * 1e3
52-
system = info.system_time.seconds * 1e9 + info.system_time.microseconds * 1e3
53-
return user+system
54-
end
55-
56-
@inline function walltime
57-
Base.time_ns()
58-
end
59-
60-
@inline function processtime()
38+
@inline function cputime()
6139
ru = Ref{rusage}()
6240
err = ccall(:getrusage, Cint, (Cint, Ref{rusage}), RUSAGE_SELF, ru)
6341
# TODO error check
6442
return maketime(ru[])
6543
end
66-
67-
const THREAD_BASIC_INFO_COUNT = (sizeof(thread_basic_info) ÷ sizeof(Int))
68-
69-
@inline function threadtime()
70-
#mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
71-
#thread_basic_info_data_t info;
72-
#mach_port_t thread = pthread_mach_thread_np(pthread_self());
73-
#if (thread_info(thread, THREAD_BASIC_INFO, (thread_info_t)&info, &count) ==
74-
# KERN_SUCCESS) {
75-
# return MakeTime(info);
76-
#}
77-
error("Thread time not implemented on OSX")
78-
end

src/timers/timers.jl

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,22 @@ Based upon https://github.com/google/benchmark
55
module Timers
66

77
"""
8-
walltime()
8+
realtime()
99
1010
Monotonic runtime counter
1111
1212
Returns time in ns as Float64.
1313
"""
14-
function walltime end
14+
function realtime end
1515

1616
"""
17-
processtime()
17+
cputime()
1818
1919
Process specific CPU time clock.
2020
2121
Returns time in ns as Float64.
2222
"""
23-
function processtime end
24-
25-
"""
26-
threadtime()
27-
28-
Thread specific CPU time clock.
29-
30-
Returns time in ns as Float64.
31-
"""
32-
function threadtime end
23+
function cputime end
3324

3425
function _applever()
3526
return VersionNumber(readchomp(`sw_vers -productVersion`))

src/timers/unix.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ maketime(ts) = ts.tv_sec * 1e9 + ts.tv_nsec
1010
if is_linux()
1111
const CLOCK_MONOTONIC = Cint(1)
1212
const CLOCK_PROCESS_CPUTIME_ID = Cint(2)
13-
const CLOCK_THREAD_CPUTIME_ID = Cint(3)
1413
elseif Sys.KERNEL == :FreeBSD # atleast on FreeBSD 11.1
1514
const CLOCK_MONOTONIC = Cint(4)
1615
const CLOCK_PROCESS_CPUTIME_ID = Cint(14)
17-
const CLOCK_THREAD_CPUTIME_ID = Cint(15)
1816
elseif is_apple() # Version 10.12 required
1917
const CLOCK_MONOTONIC = Cint(6)
2018
const CLOCK_PROCESS_CPUTIME_ID = Cint(12)
21-
const CLOCK_THREAD_CPUTIME_ID = Cint(16)
2219
else
2320
error("""
2421
BenchmarkTools doesn't currently support your system.
@@ -32,14 +29,10 @@ end
3229
return ts[]
3330
end
3431

35-
@inline function walltime()
32+
@inline function realtime()
3633
maketime(clock_gettime(CLOCK_MONOTONIC))
3734
end
3835

39-
@inline function processtime()
36+
@inline function cputime()
4037
maketime(clock_gettime(CLOCK_PROCESS_CPUTIME_ID))
4138
end
42-
43-
@inline function threadtime()
44-
maketime(clock_gettime(CLOCK_THREAD_CPUTIME_ID))
45-
end

src/timers/windows.jl

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const HANDLE = Ptr{Void}
1616
(kernel + user) * 1e2
1717
end
1818

19-
@inline function walltime()
19+
@inline function realtime()
2020
# counter = Ref{UInt64}()
2121
# err = ccall(:QueryPerformanceCounter, Cint, (Ref{UInt64},) )
2222
return Float64(Base.time_ns())
2323
end
2424

25-
@inline function processtime()
25+
@inline function cputime()
2626
proc = ccall(:GetCurrentProcess, HANDLE, ())
2727
creation_time = Ref{FileTime}()
2828
exit_time = Ref{FileTime}()
@@ -34,16 +34,3 @@ end
3434
# TODO: Error handling
3535
return maketime(kernel_time, user_time)
3636
end
37-
38-
@inline function threadtime()
39-
thread = ccall(:GetCurrentThread, HANDLE, ())
40-
creation_time = Ref{FileTime}()
41-
exit_time = Ref{FileTime}()
42-
kernel_time = Ref{FileTime}()
43-
user_time = Ref{FileTime}()
44-
45-
err = ccall(:GetThreadTimes, Cint, (HANDLE, Ref{FileTime}, Ref{FileTime}, Ref{FileTime}, Ref{FileTime}),
46-
thread, creation_time, exit_time, kernel_time, user_time)
47-
# TODO: Error handling
48-
return maketime(kernel_time, user_time)
49-
end

0 commit comments

Comments
 (0)