activesupport 3.0.pre → 3.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (351) hide show
  1. data/CHANGELOG +121 -1
  2. data/README.rdoc +33 -0
  3. data/lib/active_support.rb +42 -4
  4. data/lib/active_support/backtrace_cleaner.rb +31 -9
  5. data/lib/active_support/benchmarkable.rb +1 -0
  6. data/lib/active_support/buffered_logger.rb +5 -2
  7. data/lib/active_support/builder.rb +6 -0
  8. data/lib/active_support/cache.rb +454 -84
  9. data/lib/active_support/cache/compressed_mem_cache_store.rb +6 -13
  10. data/lib/active_support/cache/file_store.rb +140 -41
  11. data/lib/active_support/cache/mem_cache_store.rb +121 -76
  12. data/lib/active_support/cache/memory_store.rb +127 -27
  13. data/lib/active_support/cache/strategy/local_cache.rb +111 -58
  14. data/lib/active_support/cache/synchronized_memory_store.rb +2 -38
  15. data/lib/active_support/callbacks.rb +105 -76
  16. data/lib/active_support/configurable.rb +19 -18
  17. data/lib/active_support/core_ext/array.rb +1 -0
  18. data/lib/active_support/core_ext/array/access.rb +1 -1
  19. data/lib/active_support/core_ext/array/conversions.rb +29 -54
  20. data/lib/active_support/core_ext/array/extract_options.rb +16 -1
  21. data/lib/active_support/core_ext/array/grouping.rb +1 -1
  22. data/lib/active_support/core_ext/array/random_access.rb +26 -5
  23. data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
  24. data/lib/active_support/core_ext/array/wrap.rb +13 -9
  25. data/lib/active_support/core_ext/benchmark.rb +0 -12
  26. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +2 -0
  27. data/lib/active_support/core_ext/class.rb +2 -1
  28. data/lib/active_support/core_ext/class/attribute.rb +67 -0
  29. data/lib/active_support/core_ext/class/attribute_accessors.rb +33 -27
  30. data/lib/active_support/core_ext/class/delegating_attributes.rb +35 -41
  31. data/lib/active_support/core_ext/class/inheritable_attributes.rb +23 -14
  32. data/lib/active_support/core_ext/class/subclasses.rb +50 -0
  33. data/lib/active_support/core_ext/date/calculations.rb +35 -12
  34. data/lib/active_support/core_ext/date/conversions.rb +5 -5
  35. data/lib/active_support/core_ext/date/zones.rb +14 -0
  36. data/lib/active_support/core_ext/date_time/calculations.rb +3 -1
  37. data/lib/active_support/core_ext/date_time/conversions.rb +24 -5
  38. data/lib/active_support/core_ext/date_time/zones.rb +4 -0
  39. data/lib/active_support/core_ext/enumerable.rb +5 -9
  40. data/lib/active_support/core_ext/exception.rb +0 -47
  41. data/lib/active_support/core_ext/file.rb +1 -0
  42. data/lib/active_support/core_ext/file/atomic.rb +3 -2
  43. data/lib/active_support/core_ext/file/path.rb +5 -0
  44. data/lib/active_support/core_ext/float/rounding.rb +3 -2
  45. data/lib/active_support/core_ext/hash/conversions.rb +65 -145
  46. data/lib/active_support/core_ext/hash/deep_merge.rb +6 -7
  47. data/lib/active_support/core_ext/hash/except.rb +8 -1
  48. data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -0
  49. data/lib/active_support/core_ext/hash/keys.rb +10 -11
  50. data/lib/active_support/core_ext/hash/slice.rb +6 -0
  51. data/lib/active_support/core_ext/integer.rb +1 -1
  52. data/lib/active_support/core_ext/integer/multiple.rb +6 -0
  53. data/lib/active_support/core_ext/kernel.rb +1 -1
  54. data/lib/active_support/core_ext/kernel/debugger.rb +3 -2
  55. data/lib/active_support/core_ext/kernel/reporting.rb +2 -1
  56. data/lib/active_support/core_ext/kernel/requires.rb +2 -2
  57. data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
  58. data/lib/active_support/core_ext/load_error.rb +17 -30
  59. data/lib/active_support/core_ext/logger.rb +2 -40
  60. data/lib/active_support/core_ext/module.rb +5 -3
  61. data/lib/active_support/core_ext/module/aliasing.rb +1 -1
  62. data/lib/active_support/core_ext/module/anonymous.rb +24 -0
  63. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  64. data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
  65. data/lib/active_support/core_ext/module/attribute_accessors.rb +20 -22
  66. data/lib/active_support/core_ext/module/delegation.rb +21 -10
  67. data/lib/active_support/core_ext/module/introspection.rb +8 -8
  68. data/lib/active_support/core_ext/module/method_names.rb +14 -0
  69. data/lib/active_support/core_ext/module/reachable.rb +10 -0
  70. data/lib/active_support/core_ext/module/remove_method.rb +11 -0
  71. data/lib/active_support/core_ext/module/synchronization.rb +2 -1
  72. data/lib/active_support/core_ext/name_error.rb +3 -1
  73. data/lib/active_support/core_ext/object.rb +5 -3
  74. data/lib/active_support/core_ext/object/blank.rb +20 -2
  75. data/lib/active_support/core_ext/object/conversions.rb +2 -16
  76. data/lib/active_support/core_ext/object/duplicable.rb +23 -1
  77. data/lib/active_support/core_ext/object/instance_variables.rb +0 -7
  78. data/lib/active_support/core_ext/object/to_json.rb +19 -0
  79. data/lib/active_support/core_ext/object/to_param.rb +49 -0
  80. data/lib/active_support/core_ext/object/to_query.rb +27 -0
  81. data/lib/active_support/core_ext/object/with_options.rb +2 -0
  82. data/lib/active_support/core_ext/proc.rb +4 -4
  83. data/lib/active_support/core_ext/range/overlaps.rb +1 -1
  84. data/lib/active_support/core_ext/regexp.rb +0 -22
  85. data/lib/active_support/core_ext/rexml.rb +4 -1
  86. data/lib/active_support/core_ext/string.rb +3 -2
  87. data/lib/active_support/core_ext/string/access.rb +4 -2
  88. data/lib/active_support/core_ext/string/conversions.rb +28 -1
  89. data/lib/active_support/core_ext/string/encoding.rb +11 -0
  90. data/lib/active_support/core_ext/string/exclude.rb +6 -0
  91. data/lib/active_support/core_ext/string/filters.rb +29 -0
  92. data/lib/active_support/core_ext/string/inflections.rb +12 -12
  93. data/lib/active_support/core_ext/string/interpolation.rb +2 -92
  94. data/lib/active_support/core_ext/string/multibyte.rb +16 -19
  95. data/lib/active_support/core_ext/string/output_safety.rb +101 -35
  96. data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -14
  97. data/lib/active_support/core_ext/string/xchar.rb +1 -1
  98. data/lib/active_support/core_ext/time/calculations.rb +14 -7
  99. data/lib/active_support/core_ext/time/conversions.rb +1 -0
  100. data/lib/active_support/core_ext/time/marshal.rb +56 -0
  101. data/lib/active_support/core_ext/time/zones.rb +2 -5
  102. data/lib/active_support/core_ext/uri.rb +10 -4
  103. data/lib/active_support/dependencies.rb +200 -197
  104. data/lib/active_support/dependencies/autoload.rb +50 -0
  105. data/lib/active_support/deprecation/behaviors.rb +13 -9
  106. data/lib/active_support/deprecation/method_wrappers.rb +10 -9
  107. data/lib/active_support/deprecation/proxy_wrappers.rb +7 -0
  108. data/lib/active_support/deprecation/reporting.rb +5 -3
  109. data/lib/active_support/descendants_tracker.rb +43 -0
  110. data/lib/active_support/duration.rb +8 -4
  111. data/lib/active_support/file_update_checker.rb +36 -0
  112. data/lib/active_support/hash_with_indifferent_access.rb +9 -1
  113. data/lib/active_support/i18n.rb +9 -0
  114. data/lib/active_support/i18n_railtie.rb +81 -0
  115. data/lib/active_support/inflections.rb +1 -1
  116. data/lib/active_support/inflector.rb +4 -407
  117. data/lib/active_support/inflector/inflections.rb +211 -0
  118. data/lib/active_support/inflector/methods.rb +151 -0
  119. data/lib/active_support/inflector/transliterate.rb +97 -0
  120. data/lib/active_support/json/backends/jsongem.rb +12 -9
  121. data/lib/active_support/json/backends/yajl.rb +40 -0
  122. data/lib/active_support/json/backends/yaml.rb +1 -1
  123. data/lib/active_support/json/decoding.rb +17 -2
  124. data/lib/active_support/json/encoding.rb +48 -31
  125. data/lib/active_support/json/variable.rb +2 -4
  126. data/lib/active_support/lazy_load_hooks.rb +27 -0
  127. data/lib/active_support/locale/en.yml +5 -2
  128. data/lib/active_support/log_subscriber.rb +123 -0
  129. data/lib/active_support/log_subscriber/test_helper.rb +99 -0
  130. data/lib/active_support/memoizable.rb +1 -1
  131. data/lib/active_support/message_encryptor.rb +1 -0
  132. data/lib/active_support/message_verifier.rb +2 -1
  133. data/lib/active_support/multibyte.rb +8 -23
  134. data/lib/active_support/multibyte/chars.rb +213 -446
  135. data/lib/active_support/multibyte/unicode.rb +392 -0
  136. data/lib/active_support/multibyte/utils.rb +6 -7
  137. data/lib/active_support/notifications.rb +29 -122
  138. data/lib/active_support/notifications/fanout.rb +61 -0
  139. data/lib/active_support/notifications/instrumenter.rb +54 -0
  140. data/lib/active_support/ordered_hash.rb +59 -14
  141. data/lib/active_support/ordered_options.rb +6 -0
  142. data/lib/active_support/railtie.rb +60 -0
  143. data/lib/active_support/rescuable.rb +7 -4
  144. data/lib/active_support/ruby/shim.rb +4 -6
  145. data/lib/active_support/test_case.rb +2 -7
  146. data/lib/active_support/testing/assertions.rb +15 -0
  147. data/lib/active_support/testing/declarative.rb +1 -1
  148. data/lib/active_support/testing/isolation.rb +64 -17
  149. data/lib/active_support/testing/performance.rb +306 -335
  150. data/lib/active_support/testing/setup_and_teardown.rb +51 -29
  151. data/lib/active_support/time.rb +24 -3
  152. data/lib/active_support/time_with_zone.rb +10 -14
  153. data/lib/active_support/values/time_zone.rb +192 -234
  154. data/lib/active_support/values/unicode_tables.dat +0 -0
  155. data/lib/active_support/version.rb +3 -2
  156. data/lib/active_support/whiny_nil.rb +9 -7
  157. data/lib/active_support/xml_mini.rb +130 -1
  158. data/lib/active_support/xml_mini/jdom.rb +2 -0
  159. data/lib/active_support/xml_mini/libxml.rb +23 -86
  160. data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
  161. data/lib/active_support/xml_mini/nokogiri.rb +27 -24
  162. data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
  163. data/lib/active_support/xml_mini/rexml.rb +8 -2
  164. metadata +62 -195
  165. data/README +0 -43
  166. data/lib/active_support/autoload.rb +0 -28
  167. data/lib/active_support/core_ext/boolean.rb +0 -1
  168. data/lib/active_support/core_ext/boolean/conversions.rb +0 -11
  169. data/lib/active_support/core_ext/class/removal.rb +0 -53
  170. data/lib/active_support/core_ext/date.rb +0 -7
  171. data/lib/active_support/core_ext/date_time.rb +0 -5
  172. data/lib/active_support/core_ext/integer/even_odd.rb +0 -16
  173. data/lib/active_support/core_ext/kernel/daemonizing.rb +0 -7
  174. data/lib/active_support/core_ext/module/inclusion.rb +0 -30
  175. data/lib/active_support/core_ext/module/loading.rb +0 -23
  176. data/lib/active_support/core_ext/nil.rb +0 -1
  177. data/lib/active_support/core_ext/nil/conversions.rb +0 -5
  178. data/lib/active_support/core_ext/object/extending.rb +0 -80
  179. data/lib/active_support/core_ext/object/metaclass.rb +0 -13
  180. data/lib/active_support/core_ext/object/misc.rb +0 -3
  181. data/lib/active_support/core_ext/object/returning.rb +0 -42
  182. data/lib/active_support/core_ext/object/tap.rb +0 -16
  183. data/lib/active_support/core_ext/string/bytesize.rb +0 -5
  184. data/lib/active_support/core_ext/string/iterators.rb +0 -13
  185. data/lib/active_support/core_ext/symbol.rb +0 -1
  186. data/lib/active_support/core_ext/symbol/to_proc.rb +0 -14
  187. data/lib/active_support/core_ext/time.rb +0 -10
  188. data/lib/active_support/core_ext/time/marshal_with_utc_flag.rb +0 -22
  189. data/lib/active_support/deprecated_callbacks.rb +0 -283
  190. data/lib/active_support/multibyte/unicode_database.rb +0 -71
  191. data/lib/active_support/vendor.rb +0 -16
  192. data/lib/active_support/vendor/builder-2.1.2/lib/blankslate.rb +0 -113
  193. data/lib/active_support/vendor/builder-2.1.2/lib/builder.rb +0 -13
  194. data/lib/active_support/vendor/builder-2.1.2/lib/builder/blankslate.rb +0 -20
  195. data/lib/active_support/vendor/builder-2.1.2/lib/builder/css.rb +0 -250
  196. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xchar.rb +0 -115
  197. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlbase.rb +0 -139
  198. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlevents.rb +0 -63
  199. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlmarkup.rb +0 -328
  200. data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +0 -20
  201. data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
  202. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
  203. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
  204. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +0 -204
  205. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -215
  206. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +0 -53
  207. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
  208. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -99
  209. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
  210. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
  211. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
  212. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
  213. data/lib/active_support/vendor/memcache-client-1.7.5/lib/memcache.rb +0 -1133
  214. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo.rb +0 -33
  215. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone.rb +0 -47
  216. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone_info.rb +0 -228
  217. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Algiers.rb +0 -55
  218. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Cairo.rb +0 -219
  219. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Casablanca.rb +0 -42
  220. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Harare.rb +0 -18
  221. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Johannesburg.rb +0 -25
  222. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Monrovia.rb +0 -22
  223. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Nairobi.rb +0 -23
  224. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -166
  225. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -86
  226. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Bogota.rb +0 -23
  227. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Caracas.rb +0 -23
  228. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chicago.rb +0 -283
  229. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chihuahua.rb +0 -136
  230. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Denver.rb +0 -204
  231. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Godthab.rb +0 -161
  232. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Guatemala.rb +0 -27
  233. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Halifax.rb +0 -274
  234. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -149
  235. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Juneau.rb +0 -194
  236. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/La_Paz.rb +0 -22
  237. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Lima.rb +0 -35
  238. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Los_Angeles.rb +0 -232
  239. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mazatlan.rb +0 -139
  240. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mexico_City.rb +0 -144
  241. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Monterrey.rb +0 -131
  242. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/New_York.rb +0 -282
  243. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Phoenix.rb +0 -30
  244. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Regina.rb +0 -74
  245. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Santiago.rb +0 -205
  246. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Sao_Paulo.rb +0 -171
  247. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/St_Johns.rb +0 -288
  248. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Tijuana.rb +0 -196
  249. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Almaty.rb +0 -67
  250. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baghdad.rb +0 -73
  251. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baku.rb +0 -161
  252. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Bangkok.rb +0 -20
  253. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Chongqing.rb +0 -33
  254. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Colombo.rb +0 -30
  255. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Dhaka.rb +0 -27
  256. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Hong_Kong.rb +0 -87
  257. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Irkutsk.rb +0 -165
  258. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jakarta.rb +0 -30
  259. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jerusalem.rb +0 -163
  260. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kabul.rb +0 -20
  261. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kamchatka.rb +0 -163
  262. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Karachi.rb +0 -32
  263. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kathmandu.rb +0 -20
  264. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kolkata.rb +0 -25
  265. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -163
  266. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -31
  267. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuwait.rb +0 -18
  268. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Magadan.rb +0 -163
  269. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Muscat.rb +0 -18
  270. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Novosibirsk.rb +0 -164
  271. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Rangoon.rb +0 -24
  272. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Riyadh.rb +0 -18
  273. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Seoul.rb +0 -34
  274. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Shanghai.rb +0 -35
  275. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Singapore.rb +0 -33
  276. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Taipei.rb +0 -59
  277. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tashkent.rb +0 -47
  278. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tbilisi.rb +0 -78
  279. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tehran.rb +0 -121
  280. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tokyo.rb +0 -30
  281. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -65
  282. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Urumqi.rb +0 -33
  283. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Vladivostok.rb +0 -164
  284. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yakutsk.rb +0 -163
  285. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -165
  286. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yerevan.rb +0 -165
  287. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Azores.rb +0 -270
  288. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -23
  289. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -18
  290. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Adelaide.rb +0 -187
  291. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Brisbane.rb +0 -35
  292. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Darwin.rb +0 -29
  293. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Hobart.rb +0 -193
  294. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Melbourne.rb +0 -185
  295. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Perth.rb +0 -37
  296. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Sydney.rb +0 -185
  297. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Etc/UTC.rb +0 -16
  298. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Amsterdam.rb +0 -228
  299. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Athens.rb +0 -185
  300. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Belgrade.rb +0 -163
  301. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Berlin.rb +0 -188
  302. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bratislava.rb +0 -13
  303. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Brussels.rb +0 -232
  304. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bucharest.rb +0 -181
  305. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Budapest.rb +0 -197
  306. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Copenhagen.rb +0 -179
  307. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Dublin.rb +0 -276
  308. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Helsinki.rb +0 -163
  309. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Istanbul.rb +0 -218
  310. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Kiev.rb +0 -168
  311. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Lisbon.rb +0 -268
  312. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Ljubljana.rb +0 -13
  313. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/London.rb +0 -288
  314. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Madrid.rb +0 -211
  315. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Minsk.rb +0 -170
  316. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Moscow.rb +0 -181
  317. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Paris.rb +0 -232
  318. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Prague.rb +0 -187
  319. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Riga.rb +0 -176
  320. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Rome.rb +0 -215
  321. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sarajevo.rb +0 -13
  322. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Skopje.rb +0 -13
  323. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sofia.rb +0 -173
  324. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Stockholm.rb +0 -165
  325. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Tallinn.rb +0 -172
  326. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vienna.rb +0 -183
  327. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vilnius.rb +0 -170
  328. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Warsaw.rb +0 -212
  329. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Zagreb.rb +0 -13
  330. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Auckland.rb +0 -202
  331. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Fiji.rb +0 -23
  332. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Guam.rb +0 -22
  333. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Honolulu.rb +0 -28
  334. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Majuro.rb +0 -20
  335. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Midway.rb +0 -25
  336. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Noumea.rb +0 -25
  337. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -26
  338. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -20
  339. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Tongatapu.rb +0 -27
  340. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/info_timezone.rb +0 -52
  341. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone.rb +0 -51
  342. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone_info.rb +0 -44
  343. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/offset_rationals.rb +0 -98
  344. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/ruby_core_support.rb +0 -56
  345. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/time_or_datetime.rb +0 -292
  346. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone.rb +0 -508
  347. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_definition.rb +0 -56
  348. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_info.rb +0 -40
  349. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_offset_info.rb +0 -94
  350. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_period.rb +0 -198
  351. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_transition_info.rb +0 -129
@@ -1,450 +1,421 @@
1
- require 'ruby-prof'
2
-
3
- require 'fileutils'
4
- require 'rails/version'
5
-
6
- module ActiveSupport
7
- module Testing
8
- module Performance
9
- DEFAULTS =
10
- if benchmark = ARGV.include?('--benchmark') # HAX for rake test
11
- { :benchmark => true,
12
- :runs => 4,
13
- :metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time],
14
- :output => 'tmp/performance' }
15
- else
16
- { :benchmark => false,
17
- :runs => 1,
18
- :min_percent => 0.01,
19
- :metrics => [:process_time, :memory, :objects],
20
- :formats => [:flat, :graph_html, :call_tree],
21
- :output => 'tmp/performance' }
22
- end.freeze
23
-
24
- def self.included(base)
25
- base.superclass_delegating_accessor :profile_options
26
- base.profile_options = DEFAULTS
27
- end
1
+ begin
2
+ require 'ruby-prof'
3
+
4
+ require 'fileutils'
5
+ require 'rails/version'
6
+ require 'active_support/core_ext/class/delegating_attributes'
7
+ require 'active_support/core_ext/string/inflections'
8
+
9
+ module ActiveSupport
10
+ module Testing
11
+ module Performance
12
+ DEFAULTS =
13
+ if benchmark = ARGV.include?('--benchmark') # HAX for rake test
14
+ { :benchmark => true,
15
+ :runs => 4,
16
+ :metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time],
17
+ :output => 'tmp/performance' }
18
+ else
19
+ { :benchmark => false,
20
+ :runs => 1,
21
+ :min_percent => 0.01,
22
+ :metrics => [:process_time, :memory, :objects],
23
+ :formats => [:flat, :graph_html, :call_tree],
24
+ :output => 'tmp/performance' }
25
+ end.freeze
26
+
27
+ def self.included(base)
28
+ base.superclass_delegating_accessor :profile_options
29
+ base.profile_options = DEFAULTS
30
+ end
28
31
 
29
- def full_test_name
30
- "#{self.class.name}##{method_name}"
31
- end
32
+ def full_test_name
33
+ "#{self.class.name}##{method_name}"
34
+ end
32
35
 
33
- def run(result)
34
- return if method_name =~ /^default_test$/
36
+ def run(result)
37
+ return if method_name =~ /^default_test$/
35
38
 
36
- yield(self.class::STARTED, name)
37
- @_result = result
39
+ yield(self.class::STARTED, name)
40
+ @_result = result
38
41
 
39
- run_warmup
40
- if profile_options && metrics = profile_options[:metrics]
41
- metrics.each do |metric_name|
42
- if klass = Metrics[metric_name.to_sym]
43
- run_profile(klass.new)
44
- result.add_run
42
+ run_warmup
43
+ if profile_options && metrics = profile_options[:metrics]
44
+ metrics.each do |metric_name|
45
+ if klass = Metrics[metric_name.to_sym]
46
+ run_profile(klass.new)
47
+ result.add_run
48
+ end
45
49
  end
46
50
  end
47
- end
48
51
 
49
- yield(self.class::FINISHED, name)
50
- end
52
+ yield(self.class::FINISHED, name)
53
+ end
51
54
 
52
- def run_test(metric, mode)
53
- run_callbacks :setup
54
- setup
55
- metric.send(mode) { __send__ @method_name }
56
- rescue ::Test::Unit::AssertionFailedError => e
57
- add_failure(e.message, e.backtrace)
58
- rescue StandardError, ScriptError
59
- add_error($!)
60
- ensure
61
- begin
62
- teardown
63
- run_callbacks :teardown, :enumerator => :reverse_each
55
+ def run_test(metric, mode)
56
+ run_callbacks :setup
57
+ setup
58
+ metric.send(mode) { __send__ @method_name }
64
59
  rescue ::Test::Unit::AssertionFailedError => e
65
60
  add_failure(e.message, e.backtrace)
66
61
  rescue StandardError, ScriptError
67
62
  add_error($!)
63
+ ensure
64
+ begin
65
+ teardown
66
+ run_callbacks :teardown, :enumerator => :reverse_each
67
+ rescue ::Test::Unit::AssertionFailedError => e
68
+ add_failure(e.message, e.backtrace)
69
+ rescue StandardError, ScriptError
70
+ add_error($!)
71
+ end
68
72
  end
69
- end
70
-
71
- protected
72
- def run_warmup
73
- GC.start
74
73
 
75
- time = Metrics::Time.new
76
- run_test(time, :benchmark)
77
- puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]
74
+ protected
75
+ def run_warmup
76
+ GC.start
78
77
 
79
- GC.start
80
- end
78
+ time = Metrics::Time.new
79
+ run_test(time, :benchmark)
80
+ puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]
81
81
 
82
- def run_profile(metric)
83
- klass = profile_options[:benchmark] ? Benchmarker : Profiler
84
- performer = klass.new(self, metric)
82
+ GC.start
83
+ end
85
84
 
86
- performer.run
87
- puts performer.report
88
- performer.record
89
- end
85
+ def run_profile(metric)
86
+ klass = profile_options[:benchmark] ? Benchmarker : Profiler
87
+ performer = klass.new(self, metric)
90
88
 
91
- class Performer
92
- delegate :run_test, :profile_options, :full_test_name, :to => :@harness
89
+ performer.run
90
+ puts performer.report
91
+ performer.record
92
+ end
93
93
 
94
- def initialize(harness, metric)
95
- @harness, @metric = harness, metric
96
- end
94
+ class Performer
95
+ delegate :run_test, :profile_options, :full_test_name, :to => :@harness
97
96
 
98
- def report
99
- rate = @total / profile_options[:runs]
100
- '%20s: %s' % [@metric.name, @metric.format(rate)]
101
- end
97
+ def initialize(harness, metric)
98
+ @harness, @metric = harness, metric
99
+ end
102
100
 
103
- protected
104
- def output_filename
105
- "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}"
101
+ def report
102
+ rate = @total / profile_options[:runs]
103
+ '%20s: %s' % [@metric.name, @metric.format(rate)]
106
104
  end
107
- end
108
105
 
109
- class Benchmarker < Performer
110
- def run
111
- profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
112
- @total = @metric.total
106
+ protected
107
+ def output_filename
108
+ "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}"
109
+ end
113
110
  end
114
111
 
115
- def record
116
- avg = @metric.total / profile_options[:runs].to_i
117
- now = Time.now.utc.xmlschema
118
- with_output_file do |file|
119
- file.puts "#{avg},#{now},#{environment}"
112
+ class Benchmarker < Performer
113
+ def run
114
+ profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
115
+ @total = @metric.total
120
116
  end
121
- end
122
117
 
123
- def environment
124
- unless defined? @env
125
- app = "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/
126
-
127
- rails = Rails::VERSION::STRING
128
- if File.directory?('vendor/rails/.git')
129
- Dir.chdir('vendor/rails') do
130
- rails += ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/
131
- end
118
+ def record
119
+ avg = @metric.total / profile_options[:runs].to_i
120
+ now = Time.now.utc.xmlschema
121
+ with_output_file do |file|
122
+ file.puts "#{avg},#{now},#{environment}"
132
123
  end
133
-
134
- ruby = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
135
- ruby += "-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}"
136
-
137
- @env = [app, rails, ruby, RUBY_PLATFORM] * ','
138
124
  end
139
125
 
140
- @env
141
- end
126
+ def environment
127
+ unless defined? @env
128
+ app = "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/
142
129
 
143
- protected
144
- HEADER = 'measurement,created_at,app,rails,ruby,platform'
130
+ rails = Rails::VERSION::STRING
131
+ if File.directory?('vendor/rails/.git')
132
+ Dir.chdir('vendor/rails') do
133
+ rails += ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/
134
+ end
135
+ end
145
136
 
146
- def with_output_file
147
- fname = output_filename
137
+ ruby = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
138
+ ruby += "-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}"
148
139
 
149
- if new = !File.exist?(fname)
150
- FileUtils.mkdir_p(File.dirname(fname))
140
+ @env = [app, rails, ruby, RUBY_PLATFORM] * ','
151
141
  end
152
142
 
153
- File.open(fname, 'ab') do |file|
154
- file.puts(HEADER) if new
155
- yield file
156
- end
143
+ @env
157
144
  end
158
145
 
159
- def output_filename
160
- "#{super}.csv"
161
- end
162
- end
146
+ protected
147
+ HEADER = 'measurement,created_at,app,rails,ruby,platform'
163
148
 
164
- class Profiler < Performer
165
- def initialize(*args)
166
- super
167
- @supported = @metric.measure_mode rescue false
168
- end
149
+ def with_output_file
150
+ fname = output_filename
169
151
 
170
- def run
171
- return unless @supported
152
+ if new = !File.exist?(fname)
153
+ FileUtils.mkdir_p(File.dirname(fname))
154
+ end
172
155
 
173
- RubyProf.measure_mode = @metric.measure_mode
174
- RubyProf.start
175
- RubyProf.pause
176
- profile_options[:runs].to_i.times { run_test(@metric, :profile) }
177
- @data = RubyProf.stop
178
- @total = @data.threads.values.sum(0) { |method_infos| method_infos.sort.last.total_time }
156
+ File.open(fname, 'ab') do |file|
157
+ file.puts(HEADER) if new
158
+ yield file
159
+ end
160
+ end
161
+
162
+ def output_filename
163
+ "#{super}.csv"
164
+ end
179
165
  end
180
166
 
181
- def report
182
- if @supported
167
+ class Profiler < Performer
168
+ def initialize(*args)
183
169
  super
184
- else
185
- '%20s: unsupported' % @metric.name
170
+ @supported = @metric.measure_mode rescue false
186
171
  end
187
- end
188
172
 
189
- def record
190
- return unless @supported
173
+ def run
174
+ return unless @supported
191
175
 
192
- klasses = profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact
176
+ RubyProf.measure_mode = @metric.measure_mode
177
+ RubyProf.start
178
+ RubyProf.pause
179
+ profile_options[:runs].to_i.times { run_test(@metric, :profile) }
180
+ @data = RubyProf.stop
181
+ @total = @data.threads.values.sum(0) { |method_infos| method_infos.sort.last.total_time }
182
+ end
193
183
 
194
- klasses.each do |klass|
195
- fname = output_filename(klass)
196
- FileUtils.mkdir_p(File.dirname(fname))
197
- File.open(fname, 'wb') do |file|
198
- klass.new(@data).print(file, profile_options.slice(:min_percent))
184
+ def report
185
+ if @supported
186
+ super
187
+ else
188
+ '%20s: unsupported' % @metric.name
199
189
  end
200
190
  end
201
- end
202
191
 
203
- protected
204
- def output_filename(printer_class)
205
- suffix =
206
- case printer_class.name.demodulize
207
- when 'FlatPrinter'; 'flat.txt'
208
- when 'GraphPrinter'; 'graph.txt'
209
- when 'GraphHtmlPrinter'; 'graph.html'
210
- when 'CallTreePrinter'; 'tree.txt'
211
- else printer_class.name.sub(/Printer$/, '').underscore
212
- end
192
+ def record
193
+ return unless @supported
213
194
 
214
- "#{super()}_#{suffix}"
195
+ klasses = profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact
196
+
197
+ klasses.each do |klass|
198
+ fname = output_filename(klass)
199
+ FileUtils.mkdir_p(File.dirname(fname))
200
+ File.open(fname, 'wb') do |file|
201
+ klass.new(@data).print(file, profile_options.slice(:min_percent))
202
+ end
203
+ end
215
204
  end
216
- end
217
205
 
218
- module Metrics
219
- def self.[](name)
220
- const_get(name.to_s.camelize)
221
- rescue NameError
222
- nil
206
+ protected
207
+ def output_filename(printer_class)
208
+ suffix =
209
+ case printer_class.name.demodulize
210
+ when 'FlatPrinter'; 'flat.txt'
211
+ when 'GraphPrinter'; 'graph.txt'
212
+ when 'GraphHtmlPrinter'; 'graph.html'
213
+ when 'CallTreePrinter'; 'tree.txt'
214
+ else printer_class.name.sub(/Printer$/, '').underscore
215
+ end
216
+
217
+ "#{super()}_#{suffix}"
218
+ end
223
219
  end
224
220
 
225
- class Base
226
- attr_reader :total
227
-
228
- def initialize
229
- @total = 0
221
+ module Metrics
222
+ def self.[](name)
223
+ const_get(name.to_s.camelize)
224
+ rescue NameError
225
+ nil
230
226
  end
231
227
 
232
- def name
233
- @name ||= self.class.name.demodulize.underscore
234
- end
228
+ class Base
229
+ attr_reader :total
235
230
 
236
- def measure_mode
237
- self.class::Mode
238
- end
231
+ def initialize
232
+ @total = 0
233
+ end
239
234
 
240
- def measure
241
- 0
242
- end
235
+ def name
236
+ @name ||= self.class.name.demodulize.underscore
237
+ end
243
238
 
244
- def benchmark
245
- with_gc_stats do
246
- before = measure
247
- yield
248
- @total += (measure - before)
239
+ def measure_mode
240
+ self.class::Mode
249
241
  end
250
- end
251
242
 
252
- def profile
253
- RubyProf.resume
254
- yield
255
- ensure
256
- RubyProf.pause
257
- end
243
+ def measure
244
+ 0
245
+ end
258
246
 
259
- protected
260
- if GC.respond_to?(:enable_stats)
261
- def with_gc_stats
262
- GC.enable_stats
263
- yield
264
- ensure
265
- GC.disable_stats
266
- end
267
- elsif defined?(GC::Profiler)
268
- def with_gc_stats
269
- GC.start
270
- GC.disable
271
- GC::Profiler.enable
272
- yield
273
- ensure
274
- GC::Profiler.disable
275
- GC.enable
276
- end
277
- else
278
- def with_gc_stats
247
+ def benchmark
248
+ with_gc_stats do
249
+ before = measure
279
250
  yield
251
+ @total += (measure - before)
280
252
  end
281
253
  end
282
- end
283
254
 
284
- class Time < Base
285
- def measure
286
- ::Time.now.to_f
287
- end
288
-
289
- def format(measurement)
290
- if measurement < 2
291
- '%d ms' % (measurement * 1000)
292
- else
293
- '%.2f sec' % measurement
255
+ def profile
256
+ RubyProf.resume
257
+ yield
258
+ ensure
259
+ RubyProf.pause
294
260
  end
295
- end
296
- end
297
261
 
298
- class ProcessTime < Time
299
- Mode = RubyProf::PROCESS_TIME
300
-
301
- def measure
302
- RubyProf.measure_process_time
262
+ protected
263
+ # Ruby 1.9 with GC::Profiler
264
+ if defined?(GC::Profiler)
265
+ def with_gc_stats
266
+ GC::Profiler.enable
267
+ GC.start
268
+ yield
269
+ ensure
270
+ GC::Profiler.disable
271
+ end
272
+
273
+ # Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker)
274
+ elsif GC.respond_to?(:enable_stats)
275
+ def with_gc_stats
276
+ GC.enable_stats
277
+ yield
278
+ ensure
279
+ GC.disable_stats
280
+ end
281
+
282
+ else
283
+ def with_gc_stats
284
+ yield
285
+ end
286
+ end
303
287
  end
304
- end
305
288
 
306
- class WallTime < Time
307
- Mode = RubyProf::WALL_TIME
289
+ class Time < Base
290
+ def measure
291
+ ::Time.now.to_f
292
+ end
308
293
 
309
- def measure
310
- RubyProf.measure_wall_time
294
+ def format(measurement)
295
+ if measurement < 1
296
+ '%d ms' % (measurement * 1000)
297
+ else
298
+ '%.2f sec' % measurement
299
+ end
300
+ end
311
301
  end
312
- end
313
302
 
314
- class CpuTime < Time
315
- Mode = RubyProf::CPU_TIME if RubyProf.const_defined?(:CPU_TIME)
303
+ class ProcessTime < Time
304
+ Mode = RubyProf::PROCESS_TIME
316
305
 
317
- def initialize(*args)
318
- # FIXME: yeah my CPU is 2.33 GHz
319
- RubyProf.cpu_frequency = 2.33e9
320
- super
321
- end
322
-
323
- def measure
324
- RubyProf.measure_cpu_time
306
+ def measure
307
+ RubyProf.measure_process_time
308
+ end
325
309
  end
326
- end
327
310
 
328
- class Memory < Base
329
- Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY)
311
+ class WallTime < Time
312
+ Mode = RubyProf::WALL_TIME
330
313
 
331
- # ruby-prof wrapper
332
- if RubyProf.respond_to?(:measure_memory)
333
314
  def measure
334
- RubyProf.measure_memory / 1024.0
315
+ RubyProf.measure_wall_time
335
316
  end
317
+ end
336
318
 
337
- # Ruby 1.8 + railsbench patch
338
- elsif GC.respond_to?(:allocated_size)
339
- def measure
340
- GC.allocated_size / 1024.0
341
- end
319
+ class CpuTime < Time
320
+ Mode = RubyProf::CPU_TIME if RubyProf.const_defined?(:CPU_TIME)
342
321
 
343
- # Ruby 1.8 + lloyd patch
344
- elsif GC.respond_to?(:heap_info)
345
- def measure
346
- GC.heap_info['heap_current_memory'] / 1024.0
322
+ def initialize(*args)
323
+ # FIXME: yeah my CPU is 2.33 GHz
324
+ RubyProf.cpu_frequency = 2.33e9 unless RubyProf.cpu_frequency > 0
325
+ super
347
326
  end
348
327
 
349
- # Ruby 1.9 with total_malloc_allocated_size patch
350
- elsif GC.respond_to?(:malloc_total_allocated_size)
351
328
  def measure
352
- GC.total_malloc_allocated_size / 1024.0
329
+ RubyProf.measure_cpu_time
353
330
  end
331
+ end
354
332
 
355
- # Ruby 1.9 unpatched
356
- elsif GC.respond_to?(:malloc_allocated_size)
357
- def measure
358
- GC.malloc_allocated_size / 1024.0
333
+ class Memory < Base
334
+ Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY)
335
+
336
+ # Ruby 1.9 + GCdata patch
337
+ if GC.respond_to?(:malloc_allocated_size)
338
+ def measure
339
+ GC.malloc_allocated_size / 1024.0
340
+ end
341
+
342
+ # Ruby 1.8 + ruby-prof wrapper
343
+ elsif RubyProf.respond_to?(:measure_memory)
344
+ def measure
345
+ RubyProf.measure_memory / 1024.0
346
+ end
359
347
  end
360
348
 
361
- # Ruby 1.9 + GC profiler patch
362
- elsif defined?(GC::Profiler)
363
- def measure
364
- GC.enable
365
- GC.start
366
- kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0
367
- GC.disable
368
- kb
349
+ def format(measurement)
350
+ '%.2f KB' % measurement
369
351
  end
370
352
  end
371
353
 
372
- def format(measurement)
373
- '%.2f KB' % measurement
374
- end
375
- end
354
+ class Objects < Base
355
+ Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS)
376
356
 
377
- class Objects < Base
378
- Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS)
379
-
380
- if RubyProf.respond_to?(:measure_allocations)
381
- def measure
382
- RubyProf.measure_allocations
383
- end
357
+ # Ruby 1.9 + GCdata patch
358
+ if GC.respond_to?(:malloc_allocations)
359
+ def measure
360
+ GC.malloc_allocations
361
+ end
384
362
 
385
- # Ruby 1.8 + railsbench patch
386
- elsif ObjectSpace.respond_to?(:allocated_objects)
387
- def measure
388
- ObjectSpace.allocated_objects
363
+ # Ruby 1.8 + ruby-prof wrapper
364
+ elsif RubyProf.respond_to?(:measure_allocations)
365
+ def measure
366
+ RubyProf.measure_allocations
367
+ end
389
368
  end
390
369
 
391
- # Ruby 1.9 + GC profiler patch
392
- elsif defined?(GC::Profiler)
393
- def measure
394
- GC.enable
395
- GC.start
396
- last = GC::Profiler.data.last
397
- count = last[:HEAP_LIVE_OBJECTS] + last[:HEAP_FREE_OBJECTS]
398
- GC.disable
399
- count
370
+ def format(measurement)
371
+ measurement.to_i.to_s
400
372
  end
401
373
  end
402
374
 
403
- def format(measurement)
404
- measurement.to_i.to_s
405
- end
406
- end
375
+ class GcRuns < Base
376
+ Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS)
407
377
 
408
- class GcRuns < Base
409
- Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS)
378
+ # Ruby 1.9
379
+ if GC.respond_to?(:count)
380
+ def measure
381
+ GC.count
382
+ end
410
383
 
411
- if RubyProf.respond_to?(:measure_gc_runs)
412
- def measure
413
- RubyProf.measure_gc_runs
414
- end
415
- elsif GC.respond_to?(:collections)
416
- def measure
417
- GC.collections
384
+ # Ruby 1.8 + ruby-prof wrapper
385
+ elsif RubyProf.respond_to?(:measure_gc_runs)
386
+ def measure
387
+ RubyProf.measure_gc_runs
388
+ end
418
389
  end
419
- elsif GC.respond_to?(:heap_info)
420
- def measure
421
- GC.heap_info['num_gc_passes']
390
+
391
+ def format(measurement)
392
+ measurement.to_i.to_s
422
393
  end
423
394
  end
424
395
 
425
- def format(measurement)
426
- measurement.to_i.to_s
427
- end
428
- end
396
+ class GcTime < Base
397
+ Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME)
429
398
 
430
- class GcTime < Base
431
- Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME)
399
+ # Ruby 1.9 with GC::Profiler
400
+ if GC.respond_to?(:total_time)
401
+ def measure
402
+ GC::Profiler.total_time
403
+ end
432
404
 
433
- if RubyProf.respond_to?(:measure_gc_time)
434
- def measure
435
- RubyProf.measure_gc_time
436
- end
437
- elsif GC.respond_to?(:time)
438
- def measure
439
- GC.time
405
+ # Ruby 1.8 + ruby-prof wrapper
406
+ elsif RubyProf.respond_to?(:measure_gc_time)
407
+ def measure
408
+ RubyProf.measure_gc_time / 1000
409
+ end
440
410
  end
441
- end
442
411
 
443
- def format(measurement)
444
- '%d ms' % (measurement / 1000)
412
+ def format(measurement)
413
+ '%.2f ms' % measurement
414
+ end
445
415
  end
446
416
  end
447
417
  end
448
418
  end
449
419
  end
420
+ rescue LoadError
450
421
  end