This repository has been archived by the owner on Oct 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 372
/
CpuSpyApp.java
executable file
·77 lines (64 loc) · 2.24 KB
/
CpuSpyApp.java
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
//-----------------------------------------------------------------------------
//
// (C) Brandon Valosek, 2011 <[email protected]>
// (C) Willi Ye, 2015 <[email protected]>
//
//-----------------------------------------------------------------------------
// Modified by Willi Ye to work with big.LITTLE
package com.bvalosek.cpuspy;
import android.content.Context;
import android.util.SparseArray;
import com.grarak.kerneladiutor.utils.AppSettings;
import com.grarak.kerneladiutor.utils.Utils;
/**
* main application class
*/
public class CpuSpyApp {
private final int mCore;
private final Context mContext;
/**
* the long-living object used to monitor the system frequency states
*/
private final CpuStateMonitor mMonitor;
public CpuSpyApp(int core, Context context) {
mCore = core;
mContext = context;
mMonitor = new CpuStateMonitor(core);
loadOffsets();
}
/**
* @return the internal CpuStateMonitor object
*/
public CpuStateMonitor getCpuStateMonitor() {
return mMonitor;
}
/**
* Load the saved string of offsets from preferences and put it into the
* state monitor
*/
private void loadOffsets() {
String prefs = AppSettings.getCpuSpyOffsets(mCore, mContext);
if (prefs.isEmpty()) return;
// split the string by peroids and then the info by commas and load
SparseArray<Long> offsets = new SparseArray<>();
String[] sOffsets = prefs.split(",");
for (String offset : sOffsets) {
String[] parts = offset.split(" ");
offsets.put(Utils.strToInt(parts[0]), Utils.strToLong(parts[1]));
}
mMonitor.setOffsets(offsets);
}
/**
* Save the state-time offsets as a string e.g. "100 24, 200 251, 500 124
* etc
*/
public void saveOffsets() {
// build the string by iterating over the freq->duration map
StringBuilder str = new StringBuilder();
SparseArray<Long> offsets = mMonitor.getOffsets();
for (int i = 0; i < offsets.size(); i++) {
str.append(offsets.keyAt(i)).append(" ").append(offsets.valueAt(i)).append(",");
}
AppSettings.saveCpuSpyOffsets(str.toString(), mCore, mContext);
}
}