Skip to content

Commit

Permalink
Don't factor out Tms.
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Apr 12, 2020
1 parent ef87f47 commit c791a83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/crystal/system/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct Crystal::System::Process
# Whether the process identified by *pid* is still registered in the system.
# def self.exists?(pid : Int) : Bool

# Measures CPU times and returns valid arguments for `Tms.new`.
# def self.times : NamedTuple
# Measures CPU times.
# def self.times : ::Process::Tms

# Duplicates the current process.
# def self.fork : ProcessInformation
Expand Down
12 changes: 6 additions & 6 deletions src/crystal/system/unix/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ struct Crystal::System::Process
LibC.getrusage(LibC::RUSAGE_SELF, out usage)
LibC.getrusage(LibC::RUSAGE_CHILDREN, out child)

{
utime: usage.ru_utime.tv_sec.to_f64 + usage.ru_utime.tv_usec.to_f64 / 1e6,
stime: usage.ru_stime.tv_sec.to_f64 + usage.ru_stime.tv_usec.to_f64 / 1e6,
cutime: child.ru_utime.tv_sec.to_f64 + child.ru_utime.tv_usec.to_f64 / 1e6,
cstime: child.ru_stime.tv_sec.to_f64 + child.ru_stime.tv_usec.to_f64 / 1e6,
}
::Process::Tms.new(
usage.ru_utime.tv_sec.to_f64 + usage.ru_utime.tv_usec.to_f64 / 1e6,
usage.ru_stime.tv_sec.to_f64 + usage.ru_stime.tv_usec.to_f64 / 1e6,
child.ru_utime.tv_sec.to_f64 + child.ru_utime.tv_usec.to_f64 / 1e6,
child.ru_stime.tv_sec.to_f64 + child.ru_stime.tv_usec.to_f64 / 1e6,
)
end

def self.fork(*, will_exec = false)
Expand Down
20 changes: 10 additions & 10 deletions src/process.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# A struct representing the CPU current times of the process,
# in fractions of seconds.
#
# * *utime*: CPU time a process spent in userland.
# * *stime*: CPU time a process spent in the kernel.
# * *cutime*: CPU time a processes terminated children (and their terminated children) spent in the userland.
# * *cstime*: CPU time a processes terminated children (and their terminated children) spent in the kernel.
record Process::Tms, utime : Float64, stime : Float64, cutime : Float64, cstime : Float64

require "crystal/system/process"

class Process
Expand Down Expand Up @@ -50,19 +59,10 @@ class Process
Crystal::System::Process.exists?(pid)
end

# A struct representing the CPU current times of the process,
# in fractions of seconds.
#
# * *utime*: CPU time a process spent in userland.
# * *stime*: CPU time a process spent in the kernel.
# * *cutime*: CPU time a processes terminated children (and their terminated children) spent in the userland.
# * *cstime*: CPU time a processes terminated children (and their terminated children) spent in the kernel.
record Tms, utime : Float64, stime : Float64, cutime : Float64, cstime : Float64

# Returns a `Tms` for the current process. For the children times, only those
# of terminated children are returned.
def self.times : Tms
Tms.new(**Crystal::System::Process.times)
Crystal::System::Process.times
end

# Runs the given block inside a new process and
Expand Down

0 comments on commit c791a83

Please sign in to comment.