Comments (1)
Custom formatting can now be specified for benchmark logging (see this commit)
# Subclass ActionLogic::ActionBenchmark::DefaultFormatter
# This sets up a few things in the constructor and makes sure the correct log IO is provided via
# the `benchmark_log` attr_reader.
class CustomFormatter < ActionLogic::ActionBenchmark::DefaultFormatter
# Custom formatters require you to define three methods (one for each of the ActionLogic execution
# context types (`ActionTask`, `ActionUseCase` and `ActionCoordinator`)
# The respective methods your custom formatter will need to define are:
# `def coordinator`, `def use_case` and `def task`
# Each of the format methods receives two inputs:
# `benchmark_result` which is a Ruby stdlib Benchmark instance
# `context_name` which is a Ruby String representing the class name of the `ActionTask`,
# `ActionUseCase`, `ActionCoordinator` or class
def task(benchmark_result, context_name)
benchmark_log.puts("[task] #{context_name}: #{benchmark_result.real}")
end
def use_case(benchmark_result, context_name)
benchmark_log.puts("[use case] #{context_name}: #{benchmark_result.real}")
end
def coordinator(benchmark_result, context_name)
benchmark_log.puts("[coordinator] #{context_name}: #{benchmark_result.real}")
end
end
# To configure ActionLogic to use your custom formatter, you'll need to specify a
# few configuration options:
ActionLogic::ActionConfiguration.configure do |config|
config.benchmark = true
config.benchmark_log = File.open("tmp.log", "w") # If you do not specify a log file, stdout will be used
config.benchmark_formatter = CustomFormatter
end
# Using this configuration with the test suite yields a benchmark output formatted like so:
SimpleTestTask: 3.322999691590667e-05
SimpleTestUseCase: 0.00011545396409928799
UseCaseTestTask1: 2.9074028134346008e-05
UseCaseTestTask2: 2.7913018129765987e-05
SimpleTestUseCase2: 0.00011622201418504119
SimpleTestTask: 6.190297426655889e-05
SimpleTestUseCase: 0.00018308503786101937
...
# If no custom formatter is defined, ActionLogic provides a default formatter
# whose output is a machine readable format for easy parsing:
context: SimpleTestTask user_time: 0.000000 system_time: 0.000000 total_time: 0.000000 real_time: 0.000048
context: SimpleTestTask user_time: 0.000000 system_time: 0.000000 total_time: 0.000000 real_time: 0.000030
context: FailureTestTask user_time: 0.000000 system_time: 0.000000 total_time: 0.000000 real_time: 0.000038
context: ErrorHandlerTestTask user_time: 0.000000 system_time: 0.000000 total_time: 0.000000 real_time: 0.000042
context: ValidateAroundCustomTypeTestTask user_time: 0.000000 system_time: 0.000000 total_time: 0.000000 real_time: 0.000044
context: ValidateAroundTestTask user_time: 0.000000 system_time: 0.000000 total_time: 0.000000 real_time: 0.000164
...
from actionlogic.
Related Issues (10)
- Make defining a `call` method optional for `ActionUseCase` and `ActionCoordinator`
- `context` is missing information for ActionLogic errors
- Type validations should use the class constant HOT 1
- When an ActionLogic validation fails, include the failing context by default. HOT 1
- Add benchmarking HOT 1
- Update README to document new ActionLogic::Configuration HOT 1
- Allow for custom validations
- Create an example Rails application
- Provide convenience method for transaction HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from actionlogic.