Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(log_processing): add log processing time analysis tool #11

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

sangshuduo
Copy link
Owner

  • Introduced a new tool to find log processing times from log files.
  • Added functionality to display top files with the longest processing times.
  • Implemented average processing time calculation across all files.
  • Included necessary dependencies like chrono, regex, and clap for functionality.
  • Created a new Cargo.toml for the 'find_log_processtime' package.

- Introduced a new tool to find log processing times from log files.
- Added functionality to display top files with the longest processing times.
- Implemented average processing time calculation across all files.
- Included necessary dependencies like chrono, regex, and clap for functionality.
- Created a new Cargo.toml for the 'find_log_processtime' package.
Copy link
Contributor

mentatbot bot commented Feb 20, 2025

I'm getting to work. See my steps and track my cost here.

  • Wake on any new activity.
    I always see new activity while actively working. When paused, I'll only respond when tagged unless this box is checked.

Copy link
Contributor

@mentatbot mentatbot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution! I've reviewed the new log processing time analysis tool. The implementation is generally good with clear structure and error handling. Here are some suggestions for improvement:

Strengths

  • Good use of error handling with anyhow
  • Clear command-line interface using clap
  • Progress bar implementation for better UX
  • Proper handling of ANSI escape codes
  • Good separation of concerns in functions

Suggestions for Improvement

  1. Consider adding unit tests for core functionality
  2. The codebase would benefit from more documentation, especially for public functions
  3. Some constants could be extracted for better maintainability
  4. Consider adding input validation for the number of files in the Top command
  5. The timestamp format could be made configurable for different log formats

use std::fs::File;
use std::io::{BufRead, BufReader};

/// Find log processing times from a log file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding more detailed documentation about the expected log file format and examples of usage.

let mut prev_dt: Option<NaiveDateTime> = None;
let mut prev_file: Option<String> = None;

// Timestamp format: milliseconds (3 digits).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding documentation with an example helps users understand the expected timestamp format.

Suggested change
// Timestamp format: milliseconds (3 digits).
/// Format string for parsing timestamps in log files
/// Example: "2024-02-20 10:15:30.123"

Command::Top {
num_files,
log_file,
} => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add validation to ensure num_files is greater than 0.

Suggested change
} => {
if num_files == 0 {
anyhow::bail!("Number of files must be greater than 0");
}


/// Compute processing time differences from the log file.
/// Returns a vector of tuples (processing time in seconds, filename).
fn compute_diffs(log_file: &str) -> Result<Vec<(f64, String)>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a custom type for the return value instead of using a tuple. This would make the code more maintainable and self-documenting. For example:

struct ProcessingTime {
    duration: f64,
    filename: String,
}

version = "0.1.0"
edition = "2021"

[dependencies]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependencies look good and up-to-date. Consider adding thiserror for custom error types if you plan to expand the error handling.

- Introduced a new `ProcessingTime` struct to encapsulate duration and filename.
- Modified `compute_diffs` function to return a vector of `ProcessingTime` instead of tuples.
- Updated sorting and printing logic to utilize the new struct for clarity.
- Improved code readability and maintainability.
@sangshuduo sangshuduo merged commit 79fdb5a into main Feb 20, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant