摘要: Source-level instrumentation allows a programmer to construct meaningful views of performance by associating measurements with specific program constructs. Often, however, these measurements are limited to the routine level because fine-grained instrumentation and compiler optimizations can interact to produce inaccurate results: optimizations can invalidate the results of instrumentation by inappropriately moving instructions in or out of the range of measurement and instrumentation can inhibit the application of optimizations, altering the executed code and distorting views of its performance. Existing tools avoid these issues by allowing instrumentation only at the routine level where restructuring optimizations are not applicable. We introduce the notion of “instrumentation-aware” compiling that allows accurate instrumentation down to the granularity of source-level statements and expressions despite aggressive optimizations. We discuss the implementation of a prototype instrumentation-aware, optimizing C compiler that preserves the placement of performance timer operations. We demonstrate its use, not only in C code, but also in the more complex, multilevel compilation environment for ZPL code.