为什么cat <file>给我“无效参数”?</file>

时间:2014-01-31 00:11:39

标签: java android cpu-usage power-management

我正在尝试编写一个Android应用程序来收集设备的使用情况统计信息(只是为了了解Android开发,以及如何工作,我很新)。我现在想要得到的是我的设备核心的频率(它有4个核心)。

我正在尝试

cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq
                            OR
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq

但是从cpu0获取值后,它似乎不起作用。我没有崩溃应用程序,但我已经尝试了很多东西,包括在终端中搞乱,它告诉我我给它一个无效的论点。我会在下面加上代码,如果有人可以提供帮助,你会很棒!

try {    
        //Process process = Runtime.getRuntime().exec("su");
        RandomAccessFile reader = new RandomAccessFile
                ("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
        String load = reader.readLine();
        freqs[0] = Integer.parseInt(load);
        reader = new RandomAccessFile
                ("/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq", "r");
        load = reader.readLine();
        freqs[1] = Integer.parseInt(load);
        reader = new RandomAccessFile
                ("/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq", "r");
        load = reader.readLine();
        freqs[2] = Integer.parseInt(load);
        reader = new RandomAccessFile
                ("/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq", "r");
        load = reader.readLine();
        freqs[3] = Integer.parseInt(load);

       //A for loop I had tried and failed to implement

        /*RandomAccessFile reader = null;
        for (i = 0; i < cores; i++){
            reader = new RandomAccessFile("/sys/devices/system/cpu/cpu" + i 
                    + "/cpufreq/cpuinfo_cur_freq", "r");
            String load = reader.readLine();
            freqs[i] = Integer.parseInt(load);
        }*/         

    } catch (IOException ex) {
        ex.printStackTrace();
    }

core0 freq看起来正确,其余读取0,再次感谢!

0 个答案:

没有答案