dev_suite 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eca02b15867ef75a77fed4586931ab72a98c33202dd3792daf44cc208c0f9e72
4
- data.tar.gz: b6bc4187d4e93978fab552d47178792efb7862c9055f868469b138ee37e755e0
3
+ metadata.gz: fde5663cbb9add03d1db18d4b31fffba0049d8d4f49e5e6bcac7d5d72c6933a2
4
+ data.tar.gz: d37a1514954b871e610f07942556581f0c68ff83ce35f8f408e35adbabaeee3b
5
5
  SHA512:
6
- metadata.gz: 70e87b35875abc89df1823e80fd6fda525eb019e992b8e454cdf22043b98b0b731cdc6b111af15ca23bb8818857de387ae996adbeb1d0920413dbe807804119e
7
- data.tar.gz: 9c4396647818118bde2c5c82a3b9f0d5ce2775d3c53812070071b4b3d37ebc931786214a3a8a8b6c3c151eb64904bebcf61298ba915dbd99baf64c1e54d13737
6
+ metadata.gz: 89a013a696f477509da2adc76551badd312dbe73f6ca94440c57384e6a749e0327a4d9a8d9c2262eab7da4dd0ac431656f163e5f7df1068276397c92d641d9a9
7
+ data.tar.gz: 6067472079ddfdb69796f2fa34727e44dd8bc8e39c825748aaad8d138640960796bbc15262e0e0d845bfe5b53838d55a8d84208aa89bf6d685f8264e5a5dc2c8
data/Gemfile.lock CHANGED
@@ -1,15 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_suite (0.2.2)
4
+ dev_suite (0.2.3)
5
5
  benchmark (~> 0.1)
6
- get_process_mem (~> 0.2)
6
+ get_process_mem (~> 1.0)
7
+ thor (~> 1.1)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
12
  ast (2.4.2)
12
13
  benchmark (0.3.0)
14
+ bigdecimal (3.1.8)
13
15
  coderay (1.1.3)
14
16
  diff-lcs (1.5.1)
15
17
  ffi (1.17.0)
@@ -23,7 +25,8 @@ GEM
23
25
  ffi (1.17.0-x86_64-darwin)
24
26
  ffi (1.17.0-x86_64-linux-gnu)
25
27
  ffi (1.17.0-x86_64-linux-musl)
26
- get_process_mem (0.2.7)
28
+ get_process_mem (1.0.0)
29
+ bigdecimal (>= 2.0)
27
30
  ffi (~> 1.0)
28
31
  json (2.7.2)
29
32
  language_server-protocol (3.17.0.3)
@@ -71,6 +74,7 @@ GEM
71
74
  rubocop (~> 1.51)
72
75
  ruby-progressbar (1.13.0)
73
76
  strscan (3.1.0)
77
+ thor (1.3.1)
74
78
  unicode-display_width (2.5.0)
75
79
 
76
80
  PLATFORMS
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # DevSuite
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/dev_suite.svg)](https://badge.fury.io/rb/dev_suite)
3
+ [![Gem Version](https://img.shields.io/gem/v/dev_suite?color=blue)](https://rubygems.org/gems/dev_suite)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/dev_suite?color=blue)](https://rubygems.org/gems/dev_suite)
4
5
  [![Code Climate](https://codeclimate.com/github/patrick204nqh/dev_suite/badges/gpa.svg)](https://codeclimate.com/github/patrick204nqh/dev_suite)
6
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=patrick204nqh_dev_suite&metric=alert_status)](https://sonarcloud.io/summary/overall?id=patrick204nqh_dev_suite)
7
+ [![Dependencies Status](https://badges.depfu.com/badges/84fefb47a5b99ea19afd20a2aae22e3e/overview.svg)](https://depfu.com/github/patrick204nqh/dev_suite?project_id=44065)
8
+ [![Known Vulnerabilities](https://snyk.io/test/github/patrick204nqh/dev_suite/badge.svg)](https://snyk.io/test/github/patrick204nqh/dev_suite)
5
9
 
6
10
  Welcome to DevSuite! This gem provides a suite of utilities for developers to enhance their productivity.
7
11
 
@@ -40,82 +44,90 @@ require 'dev_suite'
40
44
  DevSuite::SomeUtility.do_something
41
45
  ```
42
46
 
43
- ## Features
47
+ ### CLI Commands
44
48
 
49
+ DevSuite also provides a command-line interface for various utilities. Below are some general commands:
50
+
51
+ | Command | Description |
52
+ |--------------------|-------------------------------------|
53
+ | `devsuite version` | Displays the version of DevSuite |
54
+ | `devsuite help` | Shows help information for commands |
55
+
56
+ ## Features Overview
57
+
58
+ ### Performance Analysis
45
59
  <details>
46
- <summary><strong>Performance Analysis</strong></summary>
60
+ <summary>Show more</summary>
47
61
 
48
- Analyze the performance of your code blocks with detailed benchmark and memory usage reports.
49
-
50
- **Usage:**
62
+ **Purpose**: Quickly analyze the performance of Ruby code blocks, capturing metrics like execution time and memory usage.
63
+
64
+ **How to Use**:
51
65
  ```ruby
52
66
  require 'dev_suite'
53
-
54
- DevSuite::Performance.analyze(description: "My Code Block") do
67
+
68
+ DevSuite::Performance.analyze(description: "Example Analysis") do
55
69
  sum = 0
56
- 1_000_000.times do |i|
57
- sum += i
58
- end
70
+ 1_000_000.times { |i| sum += i }
59
71
  sum
60
72
  end
61
73
  ```
62
74
 
63
- **Example output**
75
+ **Sample Output**:
64
76
  ```
65
- | Performance Analysis |
66
- +----------------------------+---------------+
67
- | Metric | Value |
68
- +----------------------------+---------------+
69
- | Description | My Code Block |
70
- | Total Time (s) | 0.056238 |
71
- | User CPU Time (s) | 0.055662 |
72
- | System CPU Time (s) | 0.000097 |
73
- | User + System CPU Time (s) | 0.055759 |
74
- | Memory Before (MB) | 25.39 |
75
- | Memory After (MB) | 25.42 |
76
- | Memory Used (MB) | 0.03 |
77
- | Max Memory Used (MB) | 25.41 |
78
- | Min Memory Used (MB) | 25.41 |
79
- | Avg Memory Used (MB) | 25.41 |
77
+ | Metric | Value |
78
+ |---------------------|------------------|
79
+ | Description | Example Analysis |
80
+ | Total Time (s) | 0.056238 |
81
+ | User CPU Time (s) | 0.055662 |
82
+ | System CPU Time (s) | 0.000097 |
83
+ | Memory Before (MB) | 25.39 |
84
+ | Memory After (MB) | 25.42 |
85
+ | Memory Used (MB) | 0.03 |
80
86
  ```
81
87
  </details>
82
88
 
89
+ ### Directory Tree Visualization
83
90
  <details>
84
- <summary><strong>Directory Tree Visualization</strong></summary>
91
+ <summary>Show more</summary>
85
92
 
86
- Visualize the structure of directories and their subdirectories with a detailed hierarchical representation. This tool is essential for understanding the organization of your files and directories at a glance.
93
+ **Purpose**: Visualize the file structure of directories and subdirectories to better understand project organization.
87
94
 
88
- **Usage:**
95
+ **How to Use**:
89
96
  ```ruby
90
97
  require 'dev_suite'
91
98
 
92
- # Set the base path for the directory you want to visualize
99
+ # Define the directory path
93
100
  base_path = "/path/to/your/directory"
94
101
 
95
- # Perform the visualization
102
+ # Execute the visualization
96
103
  DevSuite::DirectoryTree.visualize(base_path)
97
104
  ```
98
105
 
99
- **Configuring the Visualization:**
106
+ **CLI Command**:
107
+ DevSuite also provides a command-line interface for directory tree visualization. Use the following command to print the directory tree of the specified path:
108
+
109
+ ```sh
110
+ $ devsuite tree [PATH]
111
+ ```
100
112
 
113
+ **Configuration Guide**:
114
+ Customize the visualization by setting configuration options:
101
115
  ```ruby
102
116
  DevSuite::DirectoryTree::Config.configure do |config|
103
- config.settings.set(:skip_hidden, true)
104
- # ...
117
+ config.settings.set(:skip_hidden, true)
118
+ # ...
105
119
  end
106
120
  ```
107
121
 
108
- **Available Configuration Options:**
122
+ **Configuration Options**:
123
+ | Setting | Description | Example Values |
124
+ |----------------|---------------------------------------------------|--------------------------|
125
+ | `:skip_hidden` | Skips hidden files and directories. | `true`, `false` |
126
+ | `:max_depth` | Limits the depth of the directory tree displayed. | `1`, `2`, `3`, ... |
127
+ | `:skip_types` | Excludes files of specific types. | `['.log', '.tmp']`, `[]` |
109
128
 
110
- | Setting | Description | Example Values |
111
- | -------------- | ------------------------------------------------ | ------------------------ |
112
- | `:skip_hidden` | Skip hidden files and directories. | `true`, `false` |
113
- | `:max_depth` | Limit the depth of the directory tree displayed. | `1`, `2`, `3`, ... |
114
- | `:skip_types` | Exclude files of specific types. | `['.log', '.tmp']`, `[]` |
115
-
116
- **Example output**
117
-
118
- ```bash
129
+ **Sample Output**:
130
+ ```
119
131
  /path/to/your/directory/
120
132
  ├── project/
121
133
  │ ├── src/
data/dev_suite.gemspec CHANGED
@@ -30,5 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.add_dependency("benchmark", "~> 0.1")
33
- spec.add_dependency("get_process_mem", "~> 0.2")
33
+ spec.add_dependency("get_process_mem", "~> 1.0")
34
+ spec.add_dependency("thor", "~> 1.1")
34
35
  end
data/exe/devsuite ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/dev_suite"
5
+
6
+ DevSuite::CLI::Main.start(ARGV)
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ module Commands
6
+ class Base < Thor
7
+ no_commands do
8
+ # Log message to console
9
+ def log(message, level: :info)
10
+ case level
11
+ when :info
12
+ puts "[INFO] #{message}"
13
+ when :warn
14
+ puts "[WARNING] #{message}"
15
+ when :error
16
+ puts "[ERROR] #{message}"
17
+ when :debug
18
+ puts "[DEBUG] #{message}" if ENV["DEBUG_MODE"]
19
+ end
20
+ end
21
+
22
+ # Handle common errors
23
+ def handle_error(error)
24
+ log("Error: #{error.message}", level: :error)
25
+ exit(1)
26
+ end
27
+
28
+ # Default method to load configuration
29
+ def load_config(file)
30
+ YAML.load_file(file)
31
+ rescue Errno::ENOENT
32
+ log("Configuration file not found: #{file}", level: :error)
33
+ exit(1)
34
+ end
35
+ end
36
+
37
+ desc "execute", "Execute the command"
38
+ def execute
39
+ raise NotImplementedError
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ module Commands
6
+ class Tree < Base
7
+ desc "visualize PATH", "Visualize the directory structure at given PATH"
8
+ def execute(path)
9
+ log("Starting visualization for: #{path}")
10
+ begin
11
+ # Assume visualize_path is a method that can raise exceptions
12
+ DirectoryTree.visualize(path)
13
+ log("Visualization complete.")
14
+ rescue StandardError => e
15
+ handle_error(e)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ module Commands
6
+ class Version < Base
7
+ def execute
8
+ log("DevSuite version: #{DevSuite::VERSION}")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ module Commands
6
+ require_relative "commands/base"
7
+ require_relative "commands/version"
8
+ require_relative "commands/tree"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ class Main < Thor
6
+ desc "tree DIRECTORY", "Prints the directory tree"
7
+ def tree(directory)
8
+ execute_command(Commands::Tree, directory)
9
+ end
10
+
11
+ desc "version", "Displays the version of the dev_suite gem"
12
+ def version
13
+ execute_command(Commands::Version)
14
+ end
15
+
16
+ private
17
+
18
+ def execute_command(command_class, *args)
19
+ command_class.new.execute(*args)
20
+ rescue StandardError => e
21
+ handle_error(e)
22
+ end
23
+
24
+ def handle_error(error)
25
+ puts "An error occurred: #{error.message}"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module CLI
5
+ require "thor"
6
+
7
+ require_relative "cli/commands"
8
+
9
+ # Main CLI class
10
+ require_relative "cli/main"
11
+ end
12
+ end
@@ -5,10 +5,7 @@ module DevSuite
5
5
  class Analyzer
6
6
  def initialize(description: "Block")
7
7
  @description = description
8
-
9
- @benchmark_profiler = Profiler::Benchmark.new
10
- @memory_profiler = Profiler::Memory.new
11
- @memory_usage = Data::MemoryUsage.new
8
+ @profiler_manager = ProfilerManager.new
12
9
  end
13
10
 
14
11
  # Analyzes the performance of the given block
@@ -17,34 +14,20 @@ module DevSuite
17
14
  def analyze(&block)
18
15
  raise ArgumentError, "No block given" unless block_given?
19
16
 
20
- memory_before = @memory_usage.current
21
- benchmark_result = profile_benchmark(&block)
22
- memory_after = @memory_usage.current
23
-
24
- memory_stats = @memory_profiler.stats(memory_before, memory_after)
25
-
26
- generate_report(benchmark_result, memory_stats)
17
+ outcome = @profiler_manager.run(&block)
18
+ generate_report(@profiler_manager.results)
19
+ outcome
27
20
  end
28
21
 
29
22
  private
30
23
 
31
- # Profiles the benchmark of the given block
32
- # @param block [Proc] The block to be benchmarked
33
- # @return [Benchmark::Tms] The benchmark result
34
- def profile_benchmark(&block)
35
- @benchmark_profiler.run do
36
- @memory_profiler.profile(&block)
37
- end
38
- end
39
-
40
24
  # Generates a performance report
41
25
  # @param benchmark_result [Benchmark::Tms] The benchmark result
42
26
  # @param memory_stats [Hash] The memory statistics
43
- def generate_report(benchmark_result, memory_stats)
27
+ def generate_report(results)
44
28
  Config.configuration.reportor.generate(
45
29
  description: @description,
46
- benchmark_result: benchmark_result,
47
- memory_stats: memory_stats,
30
+ results: results,
48
31
  )
49
32
  end
50
33
  end
@@ -5,9 +5,10 @@ module DevSuite
5
5
  class Config
6
6
  include Utils::ConfigTools::Configuration
7
7
 
8
- attr_reader :reportor
8
+ attr_reader :profilers, :reportor
9
9
 
10
- def initialize(reportor: :simple)
10
+ def initialize(profilers: [:execution_time, :memory], reportor: :simple)
11
+ @profilers = Profiler.create_multiple(profilers)
11
12
  @reportor = Reportor.create(reportor)
12
13
  freeze # Make the instance of this class immutable
13
14
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Profiler
6
+ class ExecutionTime < Base
7
+ attr_reader :stats
8
+
9
+ def run(&block)
10
+ result = nil
11
+ timing = ::Benchmark.measure { result = yield }
12
+ @stats = calculate_stats(timing)
13
+ result
14
+ end
15
+
16
+ private
17
+
18
+ def calculate_stats(timing)
19
+ {
20
+ real: timing.real,
21
+ utime: timing.utime,
22
+ stime: timing.stime,
23
+ total: timing.total,
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -4,7 +4,7 @@ module DevSuite
4
4
  module Performance
5
5
  module Profiler
6
6
  class Memory < Base
7
- attr_reader :max_memory, :min_memory, :average_memory
7
+ attr_reader :stats
8
8
 
9
9
  def initialize
10
10
  super
@@ -12,30 +12,36 @@ module DevSuite
12
12
  @memory_points = []
13
13
  end
14
14
 
15
- def profile(&block)
16
- yield
17
- record_memory
15
+ def run(&block)
16
+ before_memory = record_memory
17
+ result = yield
18
+ after_memory = record_memory
19
+
20
+ @stats = calculate_stats(before_memory, after_memory)
21
+ result
22
+ end
23
+
24
+ private
25
+
26
+ def record_memory
27
+ current_mem = @memory_usage.current
28
+ @memory_points << current_mem
29
+ current_mem
18
30
  end
19
31
 
20
- def stats(before, after)
32
+ def calculate_stats(before, after)
21
33
  memory_used = after - before
22
- @average_memory = @memory_points.sum / @memory_points.size
34
+ average_memory = @memory_points.sum / @memory_points.size
35
+
23
36
  {
24
37
  before: before,
25
38
  after: after,
26
39
  used: memory_used,
27
40
  max: @memory_points.max,
28
41
  min: @memory_points.min,
29
- avg: @average_memory,
42
+ avg: average_memory,
30
43
  }
31
44
  end
32
-
33
- private
34
-
35
- def record_memory
36
- current_mem = @memory_usage.current
37
- @memory_points << current_mem
38
- end
39
45
  end
40
46
  end
41
47
  end
@@ -4,8 +4,25 @@ module DevSuite
4
4
  module Performance
5
5
  module Profiler
6
6
  require_relative "profiler/base"
7
- require_relative "profiler/benchmark"
7
+ require_relative "profiler/execution_time"
8
8
  require_relative "profiler/memory"
9
+
10
+ class << self
11
+ def create(profiler)
12
+ case profiler
13
+ when :execution_time
14
+ ExecutionTime.new
15
+ when :memory
16
+ Memory.new
17
+ else
18
+ raise ArgumentError, "Invalid profiler: #{profiler}"
19
+ end
20
+ end
21
+
22
+ def create_multiple(profilers)
23
+ profilers.map { |profiler| create(profiler) }
24
+ end
25
+ end
9
26
  end
10
27
  end
11
28
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ class ProfilerManager
6
+ attr_reader :results
7
+
8
+ def initialize
9
+ @results = {}
10
+ end
11
+
12
+ # Runs the configured profilers and returns the final result
13
+ def run(&block)
14
+ outcome = block.call
15
+ run_profilers(outcome)
16
+ end
17
+
18
+ private
19
+
20
+ # Runs each profiler and updates the results
21
+ # @param result [Object] The initial result from the block
22
+ # @return [Object] The final result after running all profilers
23
+ def run_profilers(outcome)
24
+ Config.configuration.profilers.each do |profiler|
25
+ outcome = run_profiler(profiler, outcome)
26
+ end
27
+ outcome
28
+ end
29
+
30
+ # Runs a single profiler and updates the results
31
+ # @param profiler [Profiler] The profiler to run
32
+ # @param result [Object] The current result
33
+ # @return [Object] The result after running the profiler
34
+ def run_profiler(profiler, outcome)
35
+ outcome = profiler.run { outcome }
36
+ update_results(profiler)
37
+ outcome
38
+ end
39
+
40
+ # Updates the results hash with the stats from the profiler
41
+ # @param profiler [Profiler] The profiler whose stats to update
42
+ def update_results(profiler)
43
+ key = to_snake_case(profiler.class.name.split("::").last)
44
+ @results[key] = profiler.stats
45
+ end
46
+
47
+ # Convert a class name to a snake_case symbol
48
+ # @param class_name [String] The class name to convert
49
+ # @return [Symbol] The snake_case symbol
50
+ def to_snake_case(class_name)
51
+ class_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase.to_sym
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Reportor
6
+ module Helpers
7
+ module StatMappings
8
+ PROFILER_STAT_TITLES = {
9
+ execution_time: {
10
+ real: "Total Time (s)",
11
+ utime: "User CPU Time (s)",
12
+ stime: "System CPU Time (s)",
13
+ total: "User + System CPU Time (s)",
14
+ },
15
+ memory: {
16
+ before: "Memory Before (MB)",
17
+ after: "Memory After (MB)",
18
+ used: "Memory Used (MB)",
19
+ max: "Max Memory Used (MB)",
20
+ min: "Min Memory Used (MB)",
21
+ avg: "Avg Memory Used (MB)",
22
+ },
23
+ }.freeze
24
+
25
+ class << self
26
+ def title_for(profiler_name, stat_name)
27
+ PROFILER_STAT_TITLES.dig(profiler_name, stat_name) || format_default_title(stat_name)
28
+ end
29
+
30
+ private
31
+
32
+ def format_default_title(metric)
33
+ metric.to_s.split("_").map(&:capitalize).join(" ")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Reportor
6
+ module Helpers
7
+ module TableBuilder
8
+ class << self
9
+ def build_table(description, results)
10
+ table = initialize_table
11
+ add_description(table, description)
12
+ add_profiler_data(table, results)
13
+ table
14
+ end
15
+
16
+ private
17
+
18
+ def initialize_table
19
+ Utils::Table::Table.new.tap do |table|
20
+ table.title = "Performance Analysis"
21
+ table.add_columns("Metric", "Value")
22
+ end
23
+ end
24
+
25
+ def add_description(table, description)
26
+ table.add_row(["Description", description])
27
+ end
28
+
29
+ def add_profiler_data(table, results)
30
+ results.each do |profiler_name, stats|
31
+ # table.add_row(["#{profiler_name.to_s.capitalize} Profiler", ""])
32
+ stats.each do |metric, value|
33
+ title = StatMappings.title_for(profiler_name, metric)
34
+ table.add_row([title, format_value(value)])
35
+ end
36
+ end
37
+ end
38
+
39
+ def format_value(value)
40
+ format("%.6f", value)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module Performance
5
+ module Reportor
6
+ module Helpers
7
+ require_relative "helpers/stat_mappings"
8
+ require_relative "helpers/table_builder"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -7,79 +7,25 @@ module DevSuite
7
7
  #
8
8
  # Generates the performance report
9
9
  #
10
- def generate(description:, benchmark_result:, memory_stats:)
11
- table = create_table
12
- populate_table(
13
- table,
14
- description: description,
15
- benchmark_result: benchmark_result,
16
- memory_stats: memory_stats,
17
- )
10
+ # @param description [String] The description of the analysis
11
+ # @param results [Hash] The profiling results from the profilers
12
+ #
13
+ def generate(description:, results:)
14
+ table = Helpers::TableBuilder.build_table(description, results)
18
15
  render_table(table)
19
16
  end
20
17
 
21
18
  private
22
19
 
23
20
  #
24
- # Creates a new table with the specified configuration
25
- #
26
- def create_table
27
- table = Utils::Table::Table.new
28
- table.tap do |t|
29
- t.title = "Performance Analysis"
30
- t.add_columns("Metric", "Value")
31
- end
32
- end
33
-
34
- #
35
- # Populates the table with benchmark and memory statistics
36
- #
37
- def populate_table(table, description: "", benchmark_result: nil, memory_stats: {})
38
- validate_benchmark_result(benchmark_result)
39
- validate_memory_stats(memory_stats)
40
-
41
- table.add_row(["Description", description])
42
- table.add_row(["Total Time (s)", format("%.6f", benchmark_result.real)])
43
- table.add_row(["User CPU Time (s)", format("%.6f", benchmark_result.utime)])
44
- table.add_row(["System CPU Time (s)", format("%.6f", benchmark_result.stime)])
45
- table.add_row(["User + System CPU Time (s)", format("%.6f", benchmark_result.total)])
46
- table.add_row(["Memory Before (MB)", format("%.2f", memory_stats[:before])])
47
- table.add_row(["Memory After (MB)", format("%.2f", memory_stats[:after])])
48
- table.add_row(["Memory Used (MB)", format("%.2f", memory_stats[:used])])
49
- table.add_row(["Max Memory Used (MB)", format("%.2f", memory_stats[:max])])
50
- table.add_row(["Min Memory Used (MB)", format("%.2f", memory_stats[:min])])
51
- table.add_row(["Avg Memory Used (MB)", format("%.2f", memory_stats[:avg])])
52
- end
53
-
21
+ # Renders the table using the configured renderer
54
22
  #
55
- # Renders the table using the specified renderer
23
+ # @param table [Utils::Table::Table] The table to render
56
24
  #
57
25
  def render_table(table)
58
26
  renderer = Utils::Table::Config.configuration.renderer
59
27
  puts renderer.render(table)
60
28
  end
61
-
62
- #
63
- # Validates the benchmark_result object
64
- #
65
- def validate_benchmark_result(benchmark_result)
66
- required_methods = [:real, :utime, :stime, :total]
67
- missing_methods = required_methods.reject { |method| benchmark_result.respond_to?(method) }
68
- unless missing_methods.empty?
69
- raise ArgumentError, "benchmark_result is missing required methods: #{missing_methods.join(", ")}"
70
- end
71
- end
72
-
73
- #
74
- # Validates the memory_stats hash
75
- #
76
- def validate_memory_stats(memory_stats)
77
- required_keys = [:before, :after, :used, :max, :min, :avg]
78
- missing_keys = required_keys.reject { |key| memory_stats.key?(key) }
79
- unless missing_keys.empty?
80
- raise ArgumentError, "memory_stats is missing required keys: #{missing_keys.join(", ")}"
81
- end
82
- end
83
29
  end
84
30
  end
85
31
  end
@@ -5,6 +5,7 @@ module DevSuite
5
5
  module Reportor
6
6
  require_relative "reportor/base"
7
7
  require_relative "reportor/simple"
8
+ require_relative "reportor/helpers"
8
9
 
9
10
  class << self
10
11
  def create(reportor)
@@ -7,6 +7,7 @@ module DevSuite
7
7
 
8
8
  require_relative "performance/data"
9
9
  require_relative "performance/profiler"
10
+ require_relative "performance/profiler_manager"
10
11
  require_relative "performance/reportor"
11
12
  require_relative "performance/analyzer"
12
13
  require_relative "performance/config"
@@ -1,3 +1,3 @@
1
1
  module DevSuite
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/dev_suite.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dev_suite/version"
4
- require "dev_suite/utils"
5
- require "dev_suite/performance"
6
- require "dev_suite/directory_tree"
7
-
8
3
  module DevSuite
4
+ require_relative "dev_suite/version"
5
+ require_relative "dev_suite/cli"
6
+ require_relative "dev_suite/utils"
7
+ require_relative "dev_suite/performance"
8
+ require_relative "dev_suite/directory_tree"
9
+
9
10
  class Error < StandardError; end
10
11
  # Your code goes here...
11
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_suite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-11 00:00:00.000000000 Z
11
+ date: 2024-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark
@@ -30,19 +30,34 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
41
55
  description: This gem provides a suite of utilities for developers to enhance their
42
56
  productivity.
43
57
  email:
44
58
  - patrick204nqh@gmail.com
45
- executables: []
59
+ executables:
60
+ - devsuite
46
61
  extensions: []
47
62
  extra_rdoc_files: []
48
63
  files:
@@ -60,7 +75,14 @@ files:
60
75
  - bin/console
61
76
  - bin/setup
62
77
  - dev_suite.gemspec
78
+ - exe/devsuite
63
79
  - lib/dev_suite.rb
80
+ - lib/dev_suite/cli.rb
81
+ - lib/dev_suite/cli/commands.rb
82
+ - lib/dev_suite/cli/commands/base.rb
83
+ - lib/dev_suite/cli/commands/tree.rb
84
+ - lib/dev_suite/cli/commands/version.rb
85
+ - lib/dev_suite/cli/main.rb
64
86
  - lib/dev_suite/directory_tree.rb
65
87
  - lib/dev_suite/directory_tree/builder.rb
66
88
  - lib/dev_suite/directory_tree/builder/base.rb
@@ -82,10 +104,14 @@ files:
82
104
  - lib/dev_suite/performance/data/memory_usage.rb
83
105
  - lib/dev_suite/performance/profiler.rb
84
106
  - lib/dev_suite/performance/profiler/base.rb
85
- - lib/dev_suite/performance/profiler/benchmark.rb
107
+ - lib/dev_suite/performance/profiler/execution_time.rb
86
108
  - lib/dev_suite/performance/profiler/memory.rb
109
+ - lib/dev_suite/performance/profiler_manager.rb
87
110
  - lib/dev_suite/performance/reportor.rb
88
111
  - lib/dev_suite/performance/reportor/base.rb
112
+ - lib/dev_suite/performance/reportor/helpers.rb
113
+ - lib/dev_suite/performance/reportor/helpers/stat_mappings.rb
114
+ - lib/dev_suite/performance/reportor/helpers/table_builder.rb
89
115
  - lib/dev_suite/performance/reportor/simple.rb
90
116
  - lib/dev_suite/utils.rb
91
117
  - lib/dev_suite/utils/color.rb
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module DevSuite
4
- module Performance
5
- module Profiler
6
- class Benchmark < Base
7
- def run(&block)
8
- ::Benchmark.measure do
9
- block.call
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end