Light-Weight Instrumentation From Relational Queries Over Program Traces

Simon F. Goldsmith, Robert O'Callahan, Alex Aiken2004

TL;DR

This paper introduces PTQL, a declarative, SQL-like language for querying program execution traces, and Partiqle, a compiler that transforms PTQL queries into efficient, lightweight instrumentation for Java programs. This approach significantly simplifies dynamic analysis, enabling developers to find performance bugs and subtle code issues with less manual effort and overhead.

What Problem Does This Paper Address?

Understanding the dynamic behavior of software is crucial for debugging, performance tuning, and correctness verification. Traditional methods for this, like manual code instrumentation or specialized, complex tools, are often tedious, error-prone, and difficult to maintain. Programmers resort to ad-hoc techniques, inserting print statements or custom logic, which quickly become unmanageable, especially in large, multithreaded, object-oriented systems. This leads to code that is harder to read, maintain, and can even introduce subtle bugs due to incorrect handling of concurrency or exceptions. The challenge is to provide a powerful yet accessible way to ask complex questions about program execution without overwhelming the developer or incurring significant performance penalties.

Methods

The core of this work lies in two main components:

  • Program Trace Query Language (PTQL): This language is designed to be declarative and SQL-like, allowing users to specify what information they want from program traces, rather than how to collect it. PTQL treats program traces as relational data, with events like method invocations and object allocations forming tables. Queries involve selecting data, specifying the tables (relations) to draw from, and defining conditions (predicates) that the data must satisfy. This relational approach leverages well-understood database optimization techniques.
  • Partiqle Compiler: This tool takes a PTQL query and a Java program as input and generates an instrumented version of the program. The instrumented program runs normally but also evaluates the PTQL query on-the-fly. Partiqle employs several novel optimizations to minimize the runtime overhead of this instrumentation:
  • Static Filtering: Predicates that can be resolved by analyzing the code itself (e.g., method names, class names) are used to eliminate unnecessary instrumentation sites.
  • Dynamic Filtering: Simple predicates that depend on a single event's data are evaluated at the instrumentation point.
  • Timing Analysis: A timing graph is constructed to understand the temporal relationships between events, enabling more precise and efficient query evaluation.
  • Admission Checks: These checks, based on the timing graph, prune records from runtime tables early if they cannot possibly satisfy join predicates, reducing memory usage and computation.
  • Post-dominator Analysis: This technique identifies points in the execution where all relevant query results can be finalized, allowing for on-the-fly output and pruning of intermediate data structures, thus minimizing memory footprint.

Datasets

The paper evaluates Partiqle and PTQL on a suite of benchmark programs, including:

  • SpecJVM98 benchmark suite: A standard set of Java benchmarks.
  • Apache Tomcat (v4): A popular web server and servlet container, which includes the Xerces XML parser.
  • Other benchmarks: Including a variety of Java programs.

The authors note that they also instrumented the Java class library, significantly increasing the total code size subject to instrumentation, though this is hard to measure precisely. No new benchmarks were introduced; instead, existing ones were used to demonstrate the system's capabilities.

Key Insights and Ideas

  • Declarative Querying for Dynamic Analysis: The core idea that a SQL-like declarative language (PTQL) can effectively express complex queries about program execution traces is powerful. This shifts the burden of complex instrumentation logic from the programmer to the compiler (Partiqle).
  • Leveraging Relational Algebra for Performance: Treating program traces as relations allows the application of established database optimization techniques to the problem of dynamic analysis instrumentation. This is a key insight for achieving "light-weight" instrumentation.
  • The Power of On-the-Fly Instrumentation: Evaluating queries during program execution (on-line) provides immediate feedback and simplifies the analysis workflow compared to offline trace processing.
  • Optimizations are Critical: The paper strongly emphasizes that without sophisticated optimizations like static/dynamic filtering, timing analysis, admission checks, and post-dominator analysis, the overhead of on-the-fly instrumentation would be prohibitive. These optimizations are not just helpful; they are essential for making the system practical.
  • Finding "Unknown" Bugs: The ability to express complex temporal and relational queries over program traces led to the discovery of significant performance bugs in well-known software (Tomcat, SpecJVM98, IBM Java class library) that were apparently unknown. This highlights the value of PTQL for bug detection.

Key Results

  • Usable Performance: The prototype system demonstrated "usable performance" for interesting queries on real-world Java programs, including Apache Tomcat.
  • Optimization Impact: The paper shows that the implemented optimizations are "critical to obtaining this performance." Figures 10 and 11 illustrate that while full instrumentation can incur overhead, the optimized versions (with admission checks and post-dominator analysis) significantly reduce this overhead compared to a naive approach. For example, memory overhead for some queries was reduced by orders of magnitude.
  • Bug Discovery: PTQL and Partiqle successfully identified several performance bugs:
  • A classic O(n²) string concatenation loop in the jack benchmark's lexer.
  • A situation in Tomcat's Xerces XML parser where CMStateSet objects returned different hash codes.
  • A potential performance issue in ObjectIdentifier.toString related to string concatenation for security certificate parsing.
  • Overhead Ratios: Tables 2 and 3 show runtime and memory overheads for various queries and benchmarks. For instance, runtime overheads for Tomcat with full optimization were often close to baseline (ratios around 1.0), with some exceptions. Memory overheads were also generally well-controlled.

Limitations and Future Work

  • Limitations:
    • The current implementation of the query evaluator is an interpreter, which can be less efficient than a compiled approach.
  • The post-dominator analysis, while powerful, can sometimes increase memory usage due to intensive traversals of Java collections by the query evaluator.
  • The system currently requires the user to add constraints to break symmetry or ensure the existence of a post-dominator node for certain queries.
  • Deletion propagation (removing dependent records when a record is deleted) is handled conservatively and could be more aggressive.
  • The current system does not handle multiple queries efficiently in a single run.
  • Future Work:
    • Compiler for Query Evaluator: Replace the interpreter with a compiler that generates specialized evaluation code for each query, using customized records and indexes.
  • Improved Query Language Expressiveness: Add features like real-time timestamps, new event types (field access, locks, threads), heap content access, arithmetic operations, arbitrary side-effect-free method calls, negation, subqueries, and aggregation.
  • Automatic Optimization: Develop the system to automatically transform queries to handle symmetry and post-dominator requirements, and to automatically introduce object lifetime tracking.
  • Approximate Query Evaluation: Explore sampling-based techniques for approximate query answers to handle extremely large traces or complex queries.
  • Static Analysis Integration: Use static analysis to further reduce instrumentation overhead by deducing query properties at compile time.
  • Multi-Query Evaluation: Support efficient evaluation of multiple queries simultaneously, potentially sharing data and instrumentation.

Summary updated

Abstract

Instrumenting programs with code to monitor their dynamic behaviour is a technique as old as computing. Today most instrumentation is either inserted manually by programmers which is tedious, or automatically by specialized tools, which are nontrivial to build and monitor particular properties. We introduce Program Trace Query Language (PTQL), a general language in which programmers can write expressive, declarative queries about program behaviour. PTQL is based on relational queries over program traces. We argue that PTQL is more amenable to human and machine understanding than competing languages. We also describe a compiler, Partiqle, that takes a PTQL query and a Java program and produces an instrumented program. This instrumented program runs normally but also evaluates the PTQL query on-line. We explain some novel optimizations required to compile relational queries into efficient instrumentation. To help evaluate our work, we present the results of applying a variety of PTQL queries to a set of benchmark programs, including the Apache Tomcat Web server. The results show that our prototype system already has usable performance, and that our optimizations are critical to obtaining this performance. Our queries also revealed significant (and apparently unknown) performance bugs in the jack SpecJVM98 benchmark, in Tomcat, and in the IBM Java class library, and some uncomfortably clever code in the Xerces XML parser.
BibTeX
@misc{goldsmith2004light,
  author = {Simon F. Goldsmith and Robert O'Callahan and Alex Aiken},
  title = {{Light-Weight Instrumentation From Relational Queries Over Program Traces}},
  year = {2004},
  doi = {10.21236/ada603315},
}

Loading related content...

Figure