java.lang.Object
com.google.javascript.jscomp.instrumentation.reporter.ReportDecoder

public final class ReportDecoder extends Object
Class that helps to decode reports received from JS binaries that have been instrumented. Report is usually a map of String => Long. Where key is encoded instrumentation point and value is number of times that code was executed. To decode report beside report itself we need mapping file that was produced when JS binary was compiled.

Expected usage: Map<String, InstrumentationPoint> mapping = ReportDecoder.parseMappingFromFile("mapping.txt"); Map<String, Long> encodedReport = readFile("report.txt"); ReportProfile report = ReportDecoder.decodeReport(mapping, encodedReport);

  • Method Summary

    Modifier and Type
    Method
    Description
    static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile
    createProfileOfStaticallyUsedCode(Map<String,com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> mapping, String fileContent, String instrumentationArrayName)
    This function builds a report for given JS binary analyzing its content.
    static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile
    decodeReport(Map<String,com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> mapping, Map<String,Long> frequencies)
     
    static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile
    mergeProfiles(List<com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile> profiles)
    Given list of profiles merges them, summing up execution counts for instrumentation points used across multiple profiles.
    static Map<String,com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint>
    parseMapping(String mappingFileContent)
    Parses the file found at location mappingFilePath and populates the properties of this class
    static Map<String,com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint>
    parseMappingFromFile(String mappingFilePath)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parseMappingFromFile

      public static Map<String,com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> parseMappingFromFile(String mappingFilePath) throws IOException
      Throws:
      IOException
    • parseMapping

      public static Map<String,com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> parseMapping(String mappingFileContent)
      Parses the file found at location mappingFilePath and populates the properties of this class
    • decodeReport

      public static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile decodeReport(Map<String,com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> mapping, Map<String,Long> frequencies)
    • createProfileOfStaticallyUsedCode

      public static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile createProfileOfStaticallyUsedCode(Map<String,com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> mapping, String fileContent, String instrumentationArrayName)
      This function builds a report for given JS binary analyzing its content. If an instrumentation point is present in the JS binary - it will be marked as executed once. If the instrumentation point was removed by the compiler as dead code - it will be marked as executed zero times. This function doesn't give 100% guarantee for finding unused code but it provides good enough approximation to be useful.
      Parameters:
      mapping - Parsed instrumentation mapping. Use parseMapping(java.lang.String) function to create it.
      fileContent - Content of a JS binary compiled with production instrumentation enabled.
      instrumentationArrayName - Name of the array that was passed as --production_instrumentation_array_name flag when compiling JS binary.
      Returns:
      Report containing all instrumentation points. If a point times_executed is zero - it means the function or branch was removed as dead code. If it's one - it's present in the JS binary.
    • mergeProfiles

      public static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile mergeProfiles(List<com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile> profiles)
      Given list of profiles merges them, summing up execution counts for instrumentation points used across multiple profiles. Be aware that instrumentation points are compared as equality so profiles should come from JS binaries compiled with at the same commit, otherwise changes in source code will cause differences in some instrumentation points.