Simple Runtime Analyzer
Loading...
Searching...
No Matches
Plot Generation Script

The plot.py script is a Python utility designed to visualize performance analysis results generated by the Simple Runtime Analyzer C++ library. It reads and processes report files in CSV and JSON formats, producing an interactive scatter plot that illustrates the relationship between sample size and execution time. This tool provides a powerful visual aid for comparing the performance of different algorithms or data sets.

Key Features

  • Multi-Report Visualization: The script can process multiple report files and plot them on a single graph, enabling direct comparison.
  • Robust File Validation: It includes comprehensive error handling to ensure only valid data files are processed.
  • Interactive Plotting: Generates an interactive scatter plot using matplotlib, allowing users to inspect data points and customize the view.
  • Automatic PNG Export: The generated plot is automatically saved as a PNG image file for easy sharing and documentation.
  • Flexible Naming: The output filename adapts automatically based on the number of input reports, ensuring clear file organization.

File Validation and Error Handling

The script is built with robust error handling to prevent crashes and provide clear feedback to the user. Before plotting, it performs a series of checks on the provided files.

  • Processing Errors: If a file cannot be read, is empty, or is not a valid JSON or CSV format, the script will catch the error and display a clear message like: ❌ Error processing file file.csv: [error message]. This ensures that the process continues even if some files are corrupted or malformed.
  • No Valid Data: If none of the provided files contain valid data, the script will output the error: ❌ Error: No valid data files to plot and terminate. This prevents the generation of an empty or meaningless plot.

The script relies on pathlib for file system operations and json and csv for data decoding, gracefully handling exceptions from these libraries.

Interactive Plotting and Report Capacity

The script uses matplotlib to create a dynamic scatter plot, which is displayed in a separate, interactive window. This allows you to zoom in on specific data points, pan across the plot, and examine the data at various scales.

The script's built-in color palette contains six distinct colors. While it can theoretically handle any number of reports, the visualization is optimized for comparing up to six datasets at once. For more than six reports, the colors will repeat, which may reduce clarity. Each dataset is assigned a unique color and a legend entry for easy identification.

PNG File Generation and Naming Convention

After the plot window is displayed, the script automatically saves the generated graph to a PNG file in the same directory as the input files. The naming convention for the output file is designed to be both descriptive and concise, adapting to the number of reports processed.

  • Single Report: When plotting a single file, the output PNG will share the same base name as the input file, with a .png extension.
    • Example: runtime_report.csvruntime_report.png
  • Multiple Reports: When comparing two or more reports, the script generates a combined filename to indicate that it's a comparison plot. The name is constructed using the names of the first three files, followed by a suffix.
    • Example (3 files): report1.json, report2.csv, report3.txtreport1_report2_report3_comparison.png
    • Example (5 files): report1.json, report2.csv, report3.txt, report4.csv, report5.jsonreport1_report2_report3_and_2_more_comparison.png