cloudsim-plus-master/cloudsim-plus-master/cloudsim-plus-examples/src/main/java/org/cloudbus/cloudsim/examples/power/util/Helper.java
public void writeMetricHistoryToFile(
        List<? extends HostSimple> hosts,
        PowerVmAllocationPolicyMigration vmAllocationPolicy,
        String outputPath) {
        for (int j = 0; j < 10; j++) {
            HostSimple host = hosts.get(j);

            if (!vmAllocationPolicy.getTimeHistory().containsKey(host)) {
                continue;
            }
            File file = new File(outputPath + "_" + host.getId() + ".csv");
            try {
                file.createNewFile();
            } catch (IOException e1) {
                e1.printStackTrace();
                System.exit(0);
            }
            try {
                BufferedWriter writer = new BufferedWriter(new FileWriter(file));
                List<Double> timeData = vmAllocationPolicy.getTimeHistory().get(host);
                List<Double> utilizationData = vmAllocationPolicy.getUtilizationHistory().get(host);
                List<Double> metricData = vmAllocationPolicy.getMetricHistory().get(host);

                for (int i = 0; i < timeData.size(); i++) {
                    writer.write(String.format(
                        "%.2f,%.2f,%.2f\n",
                        timeData.get(i),
                        utilizationData.get(i),
                        metricData.get(i)));
                }
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(0);
            }
        }
    }
/**
     * Write metric history to a file.
     *
     * @param hosts              the hosts
     * @param vmAllocationPolicy the vm allocation policy
     * @param outputPath         the output path
     */
Write metric history to a file.
@param hosts              the hosts
@param vmAllocationPolicy the vm allocation policy
@param outputPath         the output path
Write metric history to a file . @param hosts the hosts @param vmAllocationPolicy the vm allocation policy @param outputPath the output path
public void writeMetricHistoryToFile(
        List<? extends HostSimple> hosts,
        PowerVmAllocationPolicyMigration vmAllocationPolicy,
        String outputPath) {
        for (int j = 0; j < 10; j++) {
            HostSimple host = hosts.get(j);
            if (!vmAllocationPolicy.getTimeHistory().containsKey(host)) {
                continue;
            }
            File file = new File(outputPath + "_" + host.getId() + ".csv");
            try {
                file.createNewFile();
            } catch (IOException e1) {
                e1.printStackTrace();
                System.exit(0);
            }
            try {
                BufferedWriter writer = new BufferedWriter(new FileWriter(file));
                List<Double> timeData = vmAllocationPolicy.getTimeHistory().get(host);
                List<Double> utilizationData = vmAllocationPolicy.getUtilizationHistory().get(host);
                List<Double> metricData = vmAllocationPolicy.getMetricHistory().get(host);
                for (int i = 0; i < timeData.size(); i++) {
                    writer.write(String.format(
                        "%.2f,%.2f,%.2f\n",
                        timeData.get(i),
                        utilizationData.get(i),
                        metricData.get(i)));
                }
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(0);
            }
        }
    }
public void writeMetricHistoryToFile ( List < ? extends HostSimple > hosts , PowerVmAllocationPolicyMigration vmAllocationPolicy , String outputPath ) { for ( int j = 0 ; j < 10 ; j ++ ) { HostSimple host = hosts . get ( j ) ; if ( ! vmAllocationPolicy . getTimeHistory ( ) . containsKey ( host ) ) { continue ; } File file = new File ( outputPath + "_" + host . getId ( ) + ".csv" ) ; try { file . createNewFile ( ) ; } catch ( IOException e1 ) { e1 . printStackTrace ( ) ; System . exit ( 0 ) ; } try { BufferedWriter writer = new BufferedWriter ( new FileWriter ( file ) ) ; List < Double > timeData = vmAllocationPolicy . getTimeHistory ( ) . get ( host ) ; List < Double > utilizationData = vmAllocationPolicy . getUtilizationHistory ( ) . get ( host ) ; List < Double > metricData = vmAllocationPolicy . getMetricHistory ( ) . get ( host ) ; for ( int i = 0 ; i < timeData . size ( ) ; i ++ ) { writer . write ( String . format ( "%.2f,%.2f,%.2f\n" , timeData . get ( i ) , utilizationData . get ( i ) , metricData . get ( i ) ) ) ; } writer . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; System . exit ( 0 ) ; } } }
Write metric history to a file.
Write metric history to a file .