mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- Add LogStash::StopWatch class for recording execution time of code
This commit is contained in:
parent
18476af99b
commit
646a0948ed
1 changed files with 23 additions and 0 deletions
23
lib/util.rb
23
lib/util.rb
|
@ -16,4 +16,27 @@ module LogStash
|
|||
return hash
|
||||
end
|
||||
end
|
||||
|
||||
class StopWatch
|
||||
def initialize
|
||||
start
|
||||
end # def initialize
|
||||
|
||||
def start
|
||||
@start = Time.now
|
||||
end # def start
|
||||
|
||||
def duration
|
||||
return Time.now - @start
|
||||
end # def duration
|
||||
|
||||
def to_s(precision=-1)
|
||||
# precision is for numbers, and '.' isn't a number, so pad for '.' if we
|
||||
# want >0 precision
|
||||
precision += 1 if precision > 0
|
||||
return duration.to_s[0 .. precision]
|
||||
end # def to_s
|
||||
end # class StopWatch
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue