Class ReportDecoder


  • public final class ReportDecoder
    extends java.lang.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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile createProfileOfStaticallyUsedCode​(java.util.Map<java.lang.String,​com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> mapping, java.lang.String fileContent, java.lang.String instrumentationArrayName)
      This function builds a report for given JS binary analyzing its content.
      static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile decodeReport​(java.util.Map<java.lang.String,​com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> mapping, java.util.Map<java.lang.String,​java.lang.Long> frequencies)  
      static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile mergeProfiles​(java.util.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 java.util.Map<java.lang.String,​com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> parseMapping​(java.lang.String mappingFileContent)
      Parses the file found at location mappingFilePath and populates the properties of this class
      static java.util.Map<java.lang.String,​com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> parseMappingFromFile​(java.lang.String mappingFilePath)  
      • Methods inherited from class java.lang.Object

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

      • parseMappingFromFile

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

        public static java.util.Map<java.lang.String,​com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> parseMapping​(java.lang.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​(java.util.Map<java.lang.String,​com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> mapping,
                                                                                                             java.util.Map<java.lang.String,​java.lang.Long> frequencies)
      • createProfileOfStaticallyUsedCode

        public static com.google.javascript.jscomp.instrumentation.reporter.proto.ReportProfile createProfileOfStaticallyUsedCode​(java.util.Map<java.lang.String,​com.google.javascript.jscomp.instrumentation.reporter.proto.InstrumentationPoint> mapping,
                                                                                                                                  java.lang.String fileContent,
                                                                                                                                  java.lang.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​(java.util.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.