pantheios-ruby 0.11.2 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba27a1f4565489233730df50c8742a400e7c8cee
4
- data.tar.gz: 6589a0a3912e4c690e9eaf11f3128a2e775639d6
3
+ metadata.gz: 11967109aaed8da770e480f5e845e9cac404d665
4
+ data.tar.gz: af33cdea7f4977ec3bac10a0e7b5db1546de7d2b
5
5
  SHA512:
6
- metadata.gz: ecb01f00e31caff3b26b1c550499c1a6a94d0a7733dac43b578dc0d30dcdebaef9e1df0afc26fe4dbfa5fa1716a50821bedf5271ddae91d130576bb0e9dd8354
7
- data.tar.gz: 9a381fc7a7ad2f2c39edf9514ea47e9484ccf9701aa3098d2b9db70d160fd4ddb3474535f9ca3ad9828622107dbc0a721798db25572c70ac1015b665ea949b21
6
+ metadata.gz: deccf69e633dc5d8d596312e285e6708adca6c36000e1a273d707b6474583afa51c9acae9cafa68137bc7a3b34ad5afcd8e854de75e5563e05e88ecd96b67013
7
+ data.tar.gz: c6e66cd2de127d5dcaa270d3af1da1fc999632bcee26a0cd2741f0b94e24e86485a79e69e5dbf00e40b18fd094e5ec1100334ae194de1f5d867331ff41dc6ae9
data/lib/pantheios/api.rb CHANGED
@@ -5,13 +5,13 @@
5
5
  # Purpose: The Pantheios.Ruby API (::Pantheios::API)
6
6
  #
7
7
  # Created: 2nd April 2011
8
- # Updated: 24th December 2017
8
+ # Updated: 22nd January 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2011-2017, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2011-2018, Matthew Wilson and Synesis Software
15
15
  # All rights reserved.
16
16
  #
17
17
  # Redistribution and use in source and binary forms, with or without
@@ -77,54 +77,54 @@ module Pantheios
77
77
  module API
78
78
 
79
79
  # Logs an arbitrary set of parameters at the given severity level
80
- def log severity, *args
80
+ def log severity, *args, &block
81
81
 
82
82
  return nil unless severity_logged? severity
83
83
 
84
- log_or_trace 1, severity, args
84
+ log_or_trace_with_block_ 1, severity, args, &block
85
85
  end
86
86
 
87
87
  # Logs an array of parameters at the given severity level
88
- def log_v severity, argv
88
+ def log_v severity, argv, &block
89
89
 
90
90
  return nil unless severity_logged? severity
91
91
 
92
- log_or_trace 1, severity, argv
92
+ log_or_trace_with_block_ 1, severity, argv, &block
93
93
  end
94
94
 
95
95
  # Logs an arbitrary set of parameters at the Trace (:trace) level
96
- def trace *args
96
+ def trace *args, &block
97
97
 
98
98
  return nil unless tracing?
99
99
 
100
- ::Pantheios::Core.trace_v_prep self, 1, args
100
+ trace_with_block_ 1, args, &block
101
101
  end
102
102
 
103
103
  # Logs an array of parameters at the Trace (:trace) level
104
- def trace_v argv
104
+ def trace_v argv, &block
105
105
 
106
106
  return nil unless tracing?
107
107
 
108
- ::Pantheios::Core.trace_v_prep self, 1, argv
108
+ trace_with_block_ 1, argv, &block
109
109
  end
110
110
 
111
111
  if Util::VersionUtil.version_compare(RUBY_VERSION, [ 2, 1 ]) >= 0
112
112
 
113
- def trace_blv b, lvars
113
+ def trace_blv b, lvars, &block
114
114
 
115
115
  return nil unless tracing?
116
116
 
117
- ::Pantheios::Core.trace_v_impl self, 1, ApplicationLayer::ParamNameList[*lvars], :trace, lvars.map { |lv| b.local_variable_get(lv) }
117
+ ::Pantheios::Core.trace_v_impl(self, 1, ApplicationLayer::ParamNameList[*lvars], :trace, lvars.map { |lv| b.local_variable_get(lv) }, &block)
118
118
  end
119
119
  end # RUBY_VERSION
120
120
 
121
121
  if Util::VersionUtil.version_compare(RUBY_VERSION, [ 2, 2 ]) >= 0
122
122
 
123
- def trace_b b
123
+ def trace_b b, &block
124
124
 
125
125
  return nil unless tracing?
126
126
 
127
- ::Pantheios::Core.trace_v_impl self, 1, ApplicationLayer::ParamNameList[*b.local_variables], :trace, b.local_variables.map { |lv| b.local_variable_get(lv) }
127
+ ::Pantheios::Core.trace_v_impl(self, 1, ApplicationLayer::ParamNameList[*b.local_variables], :trace, b.local_variables.map { |lv| b.local_variable_get(lv) }, &block)
128
128
  end
129
129
  end # RUBY_VERSION
130
130
 
@@ -259,14 +259,19 @@ module API
259
259
  private
260
260
 
261
261
  # Private implementation method that should not need to be overridden
262
- def log_or_trace call_depth, severity, argv
262
+ def log_or_trace_with_block_ call_depth, severity, argv, &block
263
263
 
264
264
  if :trace == severity
265
265
 
266
- return ::Pantheios::Core.trace_v_impl self, 1 + call_depth, nil, severity, argv
266
+ return ::Pantheios::Core.trace_v_impl self, 1 + call_depth, nil, severity, argv, &block
267
267
  end
268
268
 
269
- ::Pantheios::Core.log_raw self, severity, argv.join
269
+ ::Pantheios::Core.log_v_impl self, severity, argv, &block
270
+ end
271
+
272
+ def trace_with_block_ call_depth, argv, &block
273
+
274
+ return ::Pantheios::Core.trace_v_impl self, 1 + call_depth, nil, :trace, argv, &block
270
275
  end
271
276
 
272
277
  end # module API
@@ -5,7 +5,7 @@
5
5
  # Purpose: The Pantheios.Ruby core (::Pantheios::Core)
6
6
  #
7
7
  # Created: 2nd April 2011
8
- # Updated: 8th January 2018
8
+ # Updated: 22nd January 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
@@ -88,7 +88,7 @@ module Core
88
88
  # :nodoc:
89
89
  class State
90
90
 
91
- def initialize default_fe
91
+ def initialize default_fe, **options
92
92
 
93
93
  @mx_service = Mutex.new
94
94
  @front_end = nil
@@ -148,13 +148,22 @@ module Core
148
148
  return r
149
149
  end
150
150
 
151
- def severity_logged? severity
151
+ if ::Pantheios::Globals.SYNCHRONISED_SEVERITY_LOGGED?
152
152
 
153
- @mx_service.synchronize do
153
+ def severity_logged? severity
154
+
155
+ @mx_service.synchronize do
154
156
 
155
- return nil unless @front_end
157
+ return nil unless @front_end
156
158
 
157
- @front_end.severity_logged? severity
159
+ @front_end.severity_logged? severity
160
+ end
161
+ end
162
+ else
163
+
164
+ def severity_logged? severity
165
+
166
+ return @front_end.severity_logged? severity
158
167
  end
159
168
  end
160
169
 
@@ -354,20 +363,72 @@ module Core
354
363
  end
355
364
 
356
365
 
366
+
357
367
  # Internal implementation method, not to be called by application code
358
- def self.trace_v_prep prefix_provider, call_depth, argv
368
+ def self.get_block_value_ &block
369
+
370
+ case block.arity
371
+ when 0
359
372
 
360
- if ApplicationLayer::ParamNameList === argv[0]
373
+ yield
374
+ when 1
361
375
 
362
- self.trace_v_impl prefix_provider, 1 + call_depth, argv[0], :trace, argv[1..-1]
376
+ yield severity
377
+ when 2
378
+
379
+ yield severity, argv
380
+ when 3
381
+
382
+ yield severity, argv, self
363
383
  else
364
384
 
365
- self.trace_v_impl prefix_provider, 1 + call_depth, nil, :trace, argv
385
+ warn 'too many parameters in logging block'
386
+
387
+ yield severity, argv, self
366
388
  end
367
389
  end
368
390
 
369
391
  # Internal implementation method, not to be called by application code
370
- def self.trace_v_impl prefix_provider, call_depth, param_list, severity, argv
392
+ def self.log_v_impl prefix_provider, severity, argv, &block
393
+
394
+ argv << get_block_value_(&block) if block_given?
395
+
396
+ self.log_raw prefix_provider, severity, argv.join
397
+ end
398
+
399
+ # Internal implementation method, not to be called by application code
400
+ def self.trace_v_impl prefix_provider, call_depth, param_list, severity, argv, &block
401
+
402
+ unless param_list
403
+
404
+ if ApplicationLayer::ParamNameList === argv[0]
405
+
406
+ param_list = argv.shift
407
+ end
408
+ end
409
+
410
+ if block_given?
411
+
412
+ br = get_block_value_ &block
413
+
414
+ if ApplicationLayer::ParamNameList === br
415
+
416
+ param_list = br
417
+ else
418
+ if ::Array === br
419
+
420
+ if ApplicationLayer::ParamNameList === br[0]
421
+
422
+ param_list = br.shift
423
+ end
424
+
425
+ argv += br
426
+ else
427
+
428
+ argv << br
429
+ end
430
+ end
431
+ end
371
432
 
372
433
  case param_list
373
434
  when nil
@@ -5,7 +5,7 @@
5
5
  # Purpose: The Pantheios.Ruby "globals" (::Pantheios::Globals)
6
6
  #
7
7
  # Created: 24th December 2017
8
- # Updated: 8th January 2018
8
+ # Updated: 22nd January 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
@@ -54,6 +54,18 @@ module Pantheios
54
54
  #
55
55
  # NOTE: The "globals" in this namespace are operative before
56
56
  # +::Pantheios::Core+ and +::Pantheios::API+
57
+ #
58
+ # === Variables
59
+ #
60
+ # * *HAS_CASCADED_INCLUDES* [boolean] Determines whether including
61
+ # +::Pantheios+ also includes all relevant parts of subordinate
62
+ # namespaces. See the documentation for the +::Pantheios+ namespace for
63
+ # further details
64
+ #
65
+ # * *SYNCHRONISED_SEVERITY_LOGGED* [boolean] Determines whether the core
66
+ # protects the call to the underlying log-service's +severity_logged?+
67
+ # with a mutex (which has a non-trivial cost).
68
+ #
57
69
  module Globals
58
70
 
59
71
  module Internals_
@@ -64,17 +76,24 @@ module Globals
64
76
 
65
77
  module Helpers_
66
78
 
67
- def self.cattr receiver, name, types, initial_value
79
+ def self.cattr receiver, name, types, initial_value, **options
80
+
81
+ if options[:boolean] && types.nil?
82
+
83
+ types = Internals_::TRUTHY_CLASSES
84
+ end
68
85
 
69
86
  types = nil if !types.nil? && types.empty?
70
87
 
71
88
  receiver.class_eval do
72
89
 
73
- field_name = '@' + name
90
+ field_name = '@' + name
91
+ get_name = name
92
+ get_name += '?' if options[:boolean]
74
93
 
75
94
  instance_variable_set field_name, initial_value
76
95
 
77
- define_singleton_method(name) do
96
+ define_singleton_method(get_name) do
78
97
 
79
98
  instance_variable_get field_name
80
99
  end
@@ -98,6 +117,8 @@ module Globals
98
117
 
99
118
  Helpers_.cattr self, 'INITIAL_SERVICE_CLASSES', nil, nil
100
119
 
120
+ Helpers_.cattr self, 'SYNCHRONISED_SEVERITY_LOGGED', nil, true, boolean: true
121
+
101
122
  def self.included receiver
102
123
 
103
124
  abort "Attempt to include #{self} into #{receiver}. This is not allowed"
@@ -5,7 +5,7 @@
5
5
  # Purpose: Version for Pantheios.Ruby library
6
6
  #
7
7
  # Created: 2nd April 2011
8
- # Updated: 8th January 2018
8
+ # Updated: 22nd 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
@@ -50,7 +50,7 @@
50
50
  module Pantheios
51
51
 
52
52
  # Current version of the Pantheios.Ruby library
53
- VERSION = '0.11.2'
53
+ VERSION = '0.12.1'
54
54
 
55
55
  private
56
56
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ # File: test/performance/test_perf_simple_statements.rb
5
+ #
6
+ # Purpose: COMPLETE_ME
7
+ #
8
+ # Created: 22nd January 2018
9
+ # Updated: 22nd January 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright: <<TBD>>
14
+ #
15
+ #############################################################################
16
+
17
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
18
+
19
+ require 'pantheios/globals'
20
+ require 'pantheios/services/null_log_service'
21
+
22
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
23
+
24
+ require 'pantheios'
25
+
26
+ require 'benchmark'
27
+
28
+ include Pantheios
29
+
30
+ N = 5000000
31
+
32
+ def severity_logged? severity
33
+
34
+ return false
35
+ end
36
+
37
+
38
+ Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:') do |r|
39
+
40
+ at_0 = r.report("arguments (1-arg)") do
41
+
42
+ for i in (0...N) do
43
+
44
+ log :notice, 'the cat in the hat.'
45
+ end
46
+ end
47
+
48
+ bt_0 = r.report("blocks (1-arg)") do
49
+
50
+ for i in (0...N) do
51
+
52
+ log(:notice) { 'the cat in the hat!' }
53
+ end
54
+ end
55
+
56
+ at_1 = r.report("arguments (simple)") do
57
+
58
+ for i in (0...N) do
59
+
60
+ log :notice, 'the ', 'cat ', 'in ', 'the ', 'hat.'
61
+ end
62
+ end
63
+
64
+ bt_1 = r.report("blocks (simple)") do
65
+
66
+ for i in (0...N) do
67
+
68
+ log(:notice) { 'the ' + 'cat ' + 'in ' + 'the ' + 'hat!' }
69
+ end
70
+ end
71
+
72
+ at_2 = r.report("arguments (complex)") do
73
+
74
+ cat = 'cat'
75
+ hat = :hat
76
+ t = Time.now
77
+
78
+ for i in (0...N) do
79
+
80
+ log :notice, "the #{cat} in the #{hat} (#{t})"
81
+ end
82
+ end
83
+
84
+ bt_2 = r.report("blocks (complex)") do
85
+
86
+ cat = 'cat'
87
+ hat = :hat
88
+ t = Time.now
89
+
90
+ for i in (0...N) do
91
+
92
+ log(:notice) { "the #{cat} in the #{hat} (#{t})" }
93
+ end
94
+ end
95
+
96
+ [ at_0 + at_1 + at_2 + bt_0 + bt_1 + bt_2, (at_0 + at_1 + at_2 + bt_0 + bt_1 + bt_2) / 2 ]
97
+ end
98
+
99
+
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ # File: test/performance/test_perf_trace_variants.rb
5
+ #
6
+ # Purpose: COMPLETE_ME
7
+ #
8
+ # Created: 22nd January 2018
9
+ # Updated: 22nd January 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright: <<TBD>>
14
+ #
15
+ #############################################################################
16
+
17
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
18
+
19
+ require 'pantheios/globals'
20
+ require 'pantheios/services/null_log_service'
21
+
22
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
23
+
24
+ require 'pantheios'
25
+
26
+ require 'benchmark'
27
+
28
+ include Pantheios
29
+
30
+ N = 1000000
31
+ T = Time.now
32
+
33
+ def severity_logged? severity
34
+
35
+ return ::Pantheios::Core.severity_logged? severity
36
+ end
37
+
38
+
39
+ def blank_trace p0, p1, p2, p3, t
40
+
41
+ trace
42
+ end
43
+
44
+ def anonymous_trace p0, p1, p2, p3, t
45
+
46
+ trace p0, p1, p2, p3, t
47
+ end
48
+
49
+ def parameter_trace p0, p1, p2, p3, t
50
+
51
+ trace ParamNames[ :p0, :p1, :p2, :p3, :t ], p0, p1, p2, p3, t
52
+ end
53
+
54
+ def parameter_cond p0, p1, p2, p3, t
55
+
56
+ trace ParamNames[ :p0, :p1, :p2, :p3, :t ], p0, p1, p2, p3, t if severity_logged? :trace
57
+ end
58
+
59
+ def names_in_block p0, p1, p2, p3, t
60
+
61
+ trace(p0, p1, p2, p3, t) { ParamNames[ :p0, :p1, :p2, :p3, :t ] }
62
+ end
63
+
64
+ def all_in_block p0, p1, p2, p3, t
65
+
66
+ trace { [ ParamNames[ :p0, :p1, :p2, :p3, :t ], p0, p1, p2, p3, t ] }
67
+ end
68
+
69
+
70
+ Benchmark.benchmark(Benchmark::CAPTION, 24, Benchmark::FORMAT, 'total:', 'avg:') do |r|
71
+
72
+ t_log = r.report('plain log') do
73
+
74
+ for i in (0...N) do
75
+
76
+ log :abc, 'd', 'ef', 't=', T
77
+ end
78
+ end
79
+
80
+ t_blank_trace = r.report('blank_trace') do
81
+
82
+ for i in (0...N) do
83
+
84
+ blank_trace :abc, 'd', 'ef', 't=', T
85
+ end
86
+ end
87
+
88
+ t_anonymous_trace = r.report('anonymous_trace') do
89
+
90
+ for i in (0...N) do
91
+
92
+ anonymous_trace :abc, 'd', 'ef', 't=', T
93
+ end
94
+ end
95
+
96
+ t_parameter_trace = r.report('parameter_trace') do
97
+
98
+ for i in (0...N) do
99
+
100
+ parameter_trace :abc, 'd', 'ef', 't=', T
101
+ end
102
+ end
103
+
104
+ t_parameter_cond = r.report('parameter_cond') do
105
+
106
+ for i in (0...N) do
107
+
108
+ parameter_cond :abc, 'd', 'ef', 't=', T
109
+ end
110
+ end
111
+
112
+ t_names_in_block = r.report('names_in_block') do
113
+
114
+ for i in (0...N) do
115
+
116
+ names_in_block :abc, 'd', 'ef', 't=', T
117
+ end
118
+ end
119
+
120
+ t_all_in_block = r.report('all_in_block') do
121
+
122
+ for i in (0...N) do
123
+
124
+ all_in_block :abc, 'd', 'ef', 't=', T
125
+ end
126
+ end
127
+
128
+ # [ at_0 + at_1 + at_2 + bt_0 + bt_1 + bt_2, (at_0 + at_1 + at_2 + bt_0 + bt_1 + bt_2) / 2 ]
129
+ end
130
+
131
+
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ # File: test/scratch/log_using_blocks.rb
5
+ #
6
+ # Purpose: COMPLETE_ME
7
+ #
8
+ # Created: 22nd January 2018
9
+ # Updated: 22nd January 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright: <<TBD>>
14
+ #
15
+ #############################################################################
16
+
17
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
18
+
19
+ require 'pantheios'
20
+
21
+ include Pantheios
22
+
23
+ log :notice, 'program starting ...'
24
+
25
+ log(:notice) { 'program started' }
26
+
27
+ def f param0, param1
28
+
29
+ trace
30
+
31
+ log :trace
32
+
33
+ trace param0, param1
34
+
35
+ log :trace, param0, param1
36
+
37
+ trace ParamNames[ :param0, :param1 ], param0, param1
38
+
39
+ log :trace, ParamNames[ :param0, :param1 ], param0, param1
40
+
41
+ trace { [ ParamNames[ :param0, :param1 ], param0, param1 ] }
42
+ end
43
+
44
+ def g param0, param1
45
+
46
+ trace(param0, param1) { [ ParamNames[ :param0, :param1 ]] }
47
+
48
+ f param0, param1
49
+ end
50
+
51
+ def h param0, param1, param2
52
+
53
+ trace(param0, param1, param2) { ParamNames[ :param0, :param1, :param2 ] }
54
+
55
+ g param0, param1
56
+ end
57
+
58
+
59
+ f :abc, 'def'
60
+
61
+ puts
62
+
63
+ g :ghi, 'k'
64
+
65
+ puts
66
+
67
+ h 'lmnop', :q, :rst
68
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pantheios-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-09 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xqsr3
@@ -51,6 +51,9 @@ files:
51
51
  - lib/pantheios/util/thread_util.rb
52
52
  - lib/pantheios/util/version_util.rb
53
53
  - lib/pantheios/version.rb
54
+ - test/performance/test_perf_simple_statements.rb
55
+ - test/performance/test_perf_trace_variants.rb
56
+ - test/scratch/log_using_blocks.rb
54
57
  - test/unit/application_layer/tc_param_name_list.rb
55
58
  - test/unit/application_layer/tc_stock_severity_levels.rb
56
59
  - test/unit/application_layer/ts_all.rb