Class MetricStore


  • public final class MetricStore
    extends Object
    MetricStore stores metric data which will be used by web visualize interface, logging, and so on. All metric classes should be JSON-serializable by ObjectMapper.
    • Method Detail

      • getStore

        public static MetricStore getStore()
        Getter for singleton instance.
        Returns:
        MetricStore object.
      • getMetricClassByName

        public <T extends MetricClass<T> getMetricClassByName​(String className)
        Get the metric class by its name.
        Type Parameters:
        T - type of the metric.
        Parameters:
        className - the name of the class.
        Returns:
        the class of the type of the metric.
      • putMetric

        public <T extends Metric> void putMetric​(T metric)
        Store a metric object. Metric object should implement Metric interface. This method will store a metric into a Map, which have metric's id as its key.
        Type Parameters:
        T - class of metric
        Parameters:
        metric - metric object.
      • getMetricWithId

        public <T extends Metric> T getMetricWithId​(Class<T> metricClass,
                                                    String id)
        Fetch metric by its metric class instance and its id.
        Type Parameters:
        T - class of metric
        Parameters:
        metricClass - class instance of metric.
        id - metric id, which can be fetched by getPlanId() method.
        Returns:
        a metric object.
      • getMetricMap

        public <T extends MetricMap<String,​Object> getMetricMap​(Class<T> metricClass)
        Fetch metric map by its metric class instance.
        Type Parameters:
        T - class of metric
        Parameters:
        metricClass - class instance of metric.
        Returns:
        a metric object.
      • getOrCreateMetric

        public <T extends Metric> T getOrCreateMetric​(Class<T> metricClass,
                                                      String id)
        Same as getMetricWithId(), but if there is no such metric, it will try to create new metric object using its constructor, which takes an id as a parameter.
        Type Parameters:
        T - class of metric
        Parameters:
        metricClass - class of metric.
        id - metric id, which can be fetched by getPlanId() method.
        Returns:
        a metric object. If there was no such metric, newly create one.
      • dumpMetricToJson

        public <T extends MetricString dumpMetricToJson​(Class<T> metricClass)
                                                   throws IOException
        Dumps JSON-serialized string of specific metric.
        Type Parameters:
        T - type of the metric to dump
        Parameters:
        metricClass - class of metric.
        Returns:
        dumped JSON string of all metric.
        Throws:
        IOException - when failed to write json.
      • dumpAllMetricToJson

        public String dumpAllMetricToJson()
                                   throws IOException
        Dumps JSON-serialized string of all stored metric.
        Returns:
        dumped JSON string of all metric.
        Throws:
        IOException - when failed to write file.
      • dumpAllMetricToFile

        public void dumpAllMetricToFile​(String filePath)
        Same as dumpAllMetricToJson(), but this will save it to the file.
        Parameters:
        filePath - path to dump JSON.
      • saveOptimizationMetricsToDB

        public void saveOptimizationMetricsToDB​(String address,
                                                String jobId,
                                                String dbId,
                                                String dbPasswd)
        Save the job metrics for the optimization to the DB, in the form of LibSVM, to a remote DB, if applicable. The metrics are as follows: the JCT (duration), and the IR DAG execution properties.
        Parameters:
        address - Address to the DB.
        jobId - Job ID, of which we record the metrics.
        dbId - the ID of the DB.
        dbPasswd - the Password to the DB.
      • triggerBroadcast

        public <T extends Metric> void triggerBroadcast​(Class<T> metricClass,
                                                        String id)
        Send changed metric data to MetricBroadcaster, which will broadcast it to all active WebSocket sessions. This method should be called manually if you want to send changed metric data to the frontend client. Also this method is synchronized.
        Type Parameters:
        T - type of the metric to broadcast
        Parameters:
        metricClass - class of the metric.
        id - id of the metric.