summaryrefslogtreecommitdiff
path: root/BenchmarkFramework/app/src/main/java/org/linaro/iasenov/benchmarkframework/Chart.java
blob: 0ab9ab55f5ebd1e1336151abcda72461ca5c2a56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package org.linaro.iasenov.benchmarkframework;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;


import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.ViewPortHandler;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by iasenov on 10/5/16.
 */
public class Chart extends AppCompatActivity {

    private static String TAG = "Chart";

    final String[] nameTestItems = {"MemSpeed",
                                    "RandMem",
                                    "Linaro-Libc-Bench",
                                    "Linaro-StringBench",
                                    "Linaro-Harness",
                                    "Linaro-Dhrystone",
                                    "Iozone",
                                    "Bonnie++",
                                    "Algorithm(ART)",
                                    "BMsGame(ART)",
                                    "Caffeine(ART)",
                                    "Jit-out(ART)",
                                    "Math(ART)",
                                    "Micro(ART)",
                                    "Stanford(ART)",
                                    "DrawArc(GPU)",
                                    "DrawCircle2(GPU)",
                                    "DrawImage(GPU)",
                                    "DrawRect(GPU)",
                                    "DrawText(GPU)",
                                    "DrawCircle(GPU)",
                                    "Kubench(GPU)",
                                    "Nehe08(GPU)",
                                    "Nehe16(GPU)",
                                    "TeapotES(GPU)",
                                    "Tiotester",
                                    "Himeno",
                                    "Stream",
                                    "FS-Mark",
                                    "Bork",
                                    "SciMark",
                                    "Smallpt",
                                    "Tscp"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        List<ArrayList<BarEntry>> groupList = new ArrayList<ArrayList<BarEntry>>();
        ArrayList<BarEntry> group = new ArrayList<>();
        ArrayList<String> labels = new ArrayList<String>();

        ArrayList<BarEntry> group_average = new ArrayList<>();

        int index = 0;
        boolean isAllNeededEntriesInitialized = false;
        int repeat = 1;


        for (int j = 0; j < nameTestItems.length; j++) {

            if (MainActivity.mapTimes.containsKey(nameTestItems[j])) {

                //Log.i(TAG,nameTestItems[j] + "--->" + MainActivity.mapTimes.get(nameTestItems[j]));

                String points[] = MainActivity.mapTimes.get(nameTestItems[j]).split(":");

                repeat = points.length;
                //Log.i(TAG, "repeatttt:" + repeat);
                int sumPoints = 0;

                for(int i = 0; i < points.length; i++){

                    if(!isAllNeededEntriesInitialized) {
                        group = new ArrayList<>();
                        groupList.add(group);

                        if(i == points.length -1 ) {
                            groupList.add(group_average);
                        }
                    }


                    double pointD = Double.parseDouble(points[i]);

                    int point = (int)(50*100/pointD);
                    sumPoints = sumPoints + point;

                    if(isAllNeededEntriesInitialized){
                        group = groupList.get(i) ;
                    }

                    group.add(new BarEntry(point, index));
                    //groupList.add(group);
                }

                group_average.add(new BarEntry(sumPoints/repeat, index));

                isAllNeededEntriesInitialized = true;//all group arrays are initialized and filled with firts results
                labels.add(nameTestItems[j]);

                index++;
            }
        }


        BarData data = new BarData(labels);

        for(int k = 0; k < repeat ;k++){
            ArrayList<BarEntry> entries = groupList.get(k);
            BarDataSet dataset = new BarDataSet(entries, "Points");
            dataset.setColors(ColorTemplate.COLORFUL_COLORS);

            final Echo echo = new Echo(k+1);

            dataset.setValueFormatter(new ValueFormatter() {

                @Override
                public String getFormattedValue(float value, Entry entry, int i, ViewPortHandler viewPortHandler) {
                    return (int) value + " [" + echo.x +"]";
                }
            });


            data.addDataSet(dataset);

            if(k == repeat-1){ //add data for average
                //Log.i(TAG, "k:"+k + " repeat:"+repeat);
                entries = groupList.get(k+1);
                dataset = new BarDataSet(entries, "Points");
                dataset.setColor(ColorTemplate.rgb("#b6b2ae")); //set different color for average points

                if(repeat > 1) { //Show average group when repeat > 1
                    dataset.setValueFormatter(new ValueFormatter() {

                        @Override
                        public String getFormattedValue(float value, Entry entry, int i, ViewPortHandler viewPortHandler) {
                            return (int) value + " [avg]";
                        }
                    });
                    data.addDataSet(dataset);
                }
            }

        }


        //final HorizontalBarChart chart = new HorizontalBarChart(this);
        //setContentView(chart);

        setContentView(R.layout.chart);

        // Find the toolbar view inside the activity layout
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarId);
        // Sets the Toolbar to act as the ActionBar for this Activity window.
        // Make sure the toolbar exists in the activity and is not null
        setSupportActionBar(toolbar);


        final HorizontalBarChart chart = (HorizontalBarChart) findViewById(R.id.chartId);
        Button saveBtn = (Button) findViewById(R.id.saveButtonId);

        saveBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            //On click function
            public void onClick(View v) {
                chart.saveToGallery("Chart_" + MainActivity.autoTestFileNameIdentifier + ".jpg", 100);
                Toast.makeText(v.getContext(), "Chart was saved to Gallery",
                        Toast.LENGTH_SHORT).show();
            }
        });


        data.setValueTextSize(8f);
        chart.setData(data);



        chart.setDescription("# Benchmark Results");

        chart.setDragEnabled(true); // on by default
        //chart.setVisibleXRangeMaximum(15);
        //chart.setVisibleXRangeMaximum(20);
        chart.animateXY(3000, 3000);

        chart.setDrawValueAboveBar(false);
        chart.setTouchEnabled(false);


        chart.getAxisLeft().setStartAtZero(true);
        chart.getAxisRight().setStartAtZero(true);


        chart.invalidate();

        setTitle("Benchmark Chart");
    }

    public class Echo{
        int x;

        public Echo(int x){
            this.x = x;
        }
    }


//**********************************************************************************************
}//Chart
//**********************************************************************************************