Bug: 280062135

Clone this repo:
  1. fb2d768 Add janitors to the OWNERS file am: cf076dd392 by Sadaf Ebrahimi · 5 months ago main master
  2. cf076dd Add janitors to the OWNERS file by Sadaf Ebrahimi · 5 months ago
  3. 27e8546 Enable windows target am: 5e1f582f65 am: b3bdb3834d by Matt Gilbride · 1 year, 2 months ago android15-automotiveos-dev android15-automotiveos-release android15-qpr1-release android15-qpr1-s3-release android15-qpr1-s4-release android15-qpr1-s5-release android15-qpr2-release android15-qpr2-s1-release android15-qpr2-s2-release android15-qpr2-s3-release android15-qpr2-s4-release android15-qpr2-s5-release android15-qpr2-s6-release android15-tests-dev aml_adb_351010000 aml_ads_351017080 aml_ads_351121120 aml_ads_351312060 aml_ads_351420000 aml_art_350913340 aml_art_351011240 aml_art_351011340 aml_art_351110180 aml_art_351310060 aml_art_351410020 aml_ase_351010000 aml_ase_351112060 aml_ase_351114000 aml_ase_351311040 aml_ase_351412000 aml_cbr_350910020 aml_cbr_351011020 aml_cbr_351111000 aml_cbr_351310040 aml_cbr_351410000 aml_cfg_351010000 aml_con_351010000 aml_con_351110000 aml_con_351412000 aml_doc_350915120 aml_doc_351012120 aml_doc_351113060 aml_doc_351311000 aml_doc_351412000 aml_ext_350912020 aml_ext_351122080 aml_ext_351312060 aml_ext_351423040 aml_hef_350921160 aml_hef_351016140 aml_hef_351120040 aml_hef_351314220 aml_hef_351420080 aml_ips_351010000 aml_ips_351111040 aml_ips_351310000 aml_ips_351410000 aml_med_350914000 aml_med_351010060 aml_med_351311020 aml_mpr_350914160 aml_mpr_351013100 aml_mpr_351013160 aml_mpr_351113060 aml_mpr_351113100 aml_mpr_351311140 aml_mpr_351416060 aml_net_350911020 aml_net_351010000 aml_net_351010020 aml_net_351111100 aml_net_351111140 aml_net_351310100 aml_net_351410000 aml_net_351410060 aml_odp_351020000 aml_odp_351121040 aml_odp_351313000 aml_odp_351421000 aml_per_350910080 aml_per_351014000 aml_per_351112280 aml_per_351112300 aml_per_351310020 aml_per_351410020 aml_res_351011000 aml_res_351111020 aml_res_351111040 aml_rkp_350910000 aml_rkp_351011000 aml_rkp_351310000 aml_sch_351010000 aml_sdk_350910000 aml_sdk_351110000 aml_sdk_351415000 aml_sta_350911020 aml_sta_351110040 aml_sta_351311000 aml_sta_351416000 aml_swc_351311020 aml_tet_350911120 aml_tet_351010220 aml_tet_351110060 aml_tet_351314140 aml_tet_351415080 aml_uwb_350911040 aml_uwb_351011040 aml_uwb_351310040 aml_wif_350912040 aml_wif_351010040 aml_wif_351110060 aml_wif_351310040 aml_wif_351410040 android-15.0.0_r10 android-15.0.0_r11 android-15.0.0_r12 android-15.0.0_r13 android-15.0.0_r14 android-15.0.0_r15 android-15.0.0_r16 android-15.0.0_r17 android-15.0.0_r20 android-15.0.0_r21 android-15.0.0_r22 android-15.0.0_r23 android-15.0.0_r26 android-15.0.0_r27 android-15.0.0_r28 android-15.0.0_r29 android-15.0.0_r30 android-15.0.0_r6 android-15.0.0_r7 android-15.0.0_r8 android-15.0.0_r9 android-automotiveos-15.0.0_lts1
  4. b3bdb38 Enable windows target am: 5e1f582f65 by Matt Gilbride · 1 year, 2 months ago
  5. 5e1f582 Enable windows target by Matt Gilbride · 1 year, 2 months ago

PerfMark

PerfMark Hummingbird

PerfMark is a low-overhead, manually-instrumented, tracing library for Java. Users can add the tracing function calls to their code to see how long each part takes.

Features

  • Very Low Overhead: When enabled, tracing a function call adds about 70ns. Tracing is done in a lock-free, wait-free, thread local buffer, which avoids interfering with your latency-sensitive code.

  • Dynamically Enabled: PerfMark can be enabled or disabled at runtime. When disabled, PerfMark has zero overhead, taking advantage of the JIT compiler to remove the tracing.

  • Inter-thread Communication: Existing profilers have difficulty expressing which thread wakes up and executes work on another thread. PerfMark allows users to express this relationship explicitly, making for a clear picture of how code flows.

  • Small Library Size: The PerfMark tracing API is only 5 KB in size, and has minimal dependencies making it easy to include in other projects. If no backend for recording the trace is present, the library safely disables itself.

  • Multiple Java Versions: The PerfMark API supports Java 6, making it easy to include on older or constrained environments. Additionally, PerfMark includes optimized backends for Java 6, Java 7, and Java 9. Each of these backends is automatically loaded at runtime (if possible) and uses advanced JVM features for maximum speed.

  • Chrome Trace Viewer Integration: PerfMark can export to the Chrome Trace Event Format, making it easy to view in your Web Browser.

Usage

To use PerfMark, add the following dependencies to your build.gradle:

dependencies {
    implementation 'io.perfmark:perfmark-api:0.25.0'
    // Only needed for applications, not libraries.
    implementation 'io.perfmark:perfmark-traceviewer:0.25.0'
}

Or in your pom.xml:

    <dependency>
      <groupId>io.perfmark</groupId>
      <artifactId>perfmark-api</artifactId>
      <version>0.25.0</version>
    </dependency>

In your code, add the PerfMark tracing calls like so:

Map<String, Header> parseHeaders(List<String> rawHeaders) {
  try (TaskCloseable task = PerfMark.traceTask("Parse HTTP headers")) {
    Map<String, String> headers = new HashMap<>();
    for (String rawHeader : rawHeaders) {
      Header header = parseHeader(rawHeader);
      headers.put(header.name(), header);
    }
    return headers;
  }
}

PerfMark can also be used to record asynchronous work:

Future<Response> buildResponse() {
  try (TaskCloseable task = PerfMark.traceTask("Build Response")) {
    Link link = PerfMark.linkOut();
    return executor.submit(() -> {
      try (TaskCloseable task2 = PerfMark.traceTask("Async Response")) {
        PerfMark.linkIn(link);
        return new Response(/* ... */);
      }
    });
  }
}

To view the traces in your browser, generate the HTML:

  PerfMark.setEnabled(true);
  PerfMark.event("My Task");
  TraceEventViewer.writeTraceHtml();

The output looks like:

PerfMark Hummingbird

Configuration

PerfMark provides some System Properties that allow controlling how it initializes. These can be set by providing them as JVM arguments. (e.g. -Dio.perfmark.PerfMark.startEnabled=true)

  • io.perfmark.PerfMark.startEnabled controls if PerfMark starts enabled. This boolean property makes it possible to start tracing calls immediately. This is helpful when it's difficult to invoke setEnabled() on PerfMark before task tracing calls have started.

  • io.perfmark.PerfMark.debug controls if PerfMark can log initializing steps. This property exists to disable class loading of the logger package (currently java.util.logging). If the debug property is set, the logger settings still need to be configured to report the logs. By default, all PerfMark logs use level FINE (SLF4J DEBUG) or lower, which means that they usually need additional setup to print.

    In addition to initialization, the debug property controls if other tracing failures can be logged. When calls involving deferred execution are used (e.g. startTask(T, StringFunction<T>)), the String function provided may throw an exception. In these cases, the exception is silently ignored. This makes it easy to ensure the start/stop call parity is maintained. To view these failures, the debug property can be set to log such problems. As above, the PerfMark logger should be configured as well to report these.

Versioning and API Stability

PerfMark uses Semantic Versioning, and thus will not break existing APIs within a minor version update. PerfMark may need to disable some functionality, and thus may need to make some tracing calls become No-ops. In such cases, it will remain safe to call these functions being recorded.

Users

PerfMark was designed originally for gRPC. It is also used by Zuul.