Exemplo n.º 1
0
def test_cpu_freq_procfs(tmp_path: pathlib.Path) -> None:
    populate_directory(
        str(tmp_path),
        {
            "sysfs": {
                "devices": {
                    "system": {
                        "cpu": {}
                    }
                }
            },
            "procfs": {
                "cpuinfo":
                """
core id: 0
physical id: 0
cpu MHz: 2000

core id: 1
physical id: 0
cpu MHz: 2500
"""
            },
        },
    )

    with replace_info_directories(sysfs=str(tmp_path / "sysfs"),
                                  procfs=str(tmp_path / "procfs")):
        assert pypsutil.percpu_freq() == [  # type: ignore
            pypsutil.CPUFrequencies(current=2000, min=0, max=0),
            pypsutil.CPUFrequencies(current=2500, min=0, max=0),
        ]

        assert pypsutil.cpu_freq() == (  # type: ignore
            pypsutil.CPUFrequencies(current=2250, min=0, max=0))
Exemplo n.º 2
0
    def test_cpu_freq_range() -> None:
        freqs = pypsutil.cpu_freq()  # type: ignore[attr-defined]  # pylint: disable=no-member
        if freqs is None:
            pytest.skip("Unable to determine CPU frequencies")

        assert freqs.current > 0
        assert freqs.min == 0.0 or freqs.current >= freqs.min
        assert freqs.max == 0.0 or freqs.current <= freqs.max
Exemplo n.º 3
0
def test_cpu_freq_none(tmp_path: pathlib.Path) -> None:
    populate_directory(
        str(tmp_path),
        {
            "sysfs": {},
            "procfs": {}
        },
    )

    with replace_info_directories(sysfs=str(tmp_path / "sysfs"),
                                  procfs=str(tmp_path / "procfs")):
        assert pypsutil.percpu_freq() == []  # type: ignore

        assert pypsutil.cpu_freq() is None  # type: ignore
Exemplo n.º 4
0
def test_cpu_freq_sysfs(tmp_path: pathlib.Path) -> None:
    populate_directory(
        str(tmp_path),
        {
            "devices": {
                "system": {
                    "cpu": {
                        "cpu0": {
                            "cpufreq": {
                                "scaling_min_freq": "1000000",
                                "scaling_cur_freq": "2000000",
                                "scaling_max_freq": "3000000",
                            },
                        },
                        "cpu1": {
                            "cpufreq": {
                                "scaling_min_freq": "1500000",
                                "scaling_cur_freq": "2500000",
                                "scaling_max_freq": "3500000",
                            },
                        },
                        "online": "0-4",
                    }
                }
            }
        },
    )

    with replace_info_directories(sysfs=str(tmp_path)):
        assert pypsutil.percpu_freq() == [  # type: ignore
            pypsutil.CPUFrequencies(current=2000, min=1000, max=3000),
            pypsutil.CPUFrequencies(current=2500, min=1500, max=3500),
        ]

        assert pypsutil.cpu_freq() == (  # type: ignore
            pypsutil.CPUFrequencies(current=2250, min=1250, max=3250))
Exemplo n.º 5
0
 def cpu_freq(
     percpu: bool = False,
 ) -> Union[pypsutil.CPUFrequencies, List[pypsutil.CPUFrequencies]]:
     return pypsutil.percpu_freq() if percpu else pypsutil.cpu_freq()  # type: ignore
time.sleep(3)
message_bit = []
"""
The transmit unit is pretty easy to understand. However, here needs more explanation.
We monitor the CPU frequency 9-10 time in each 5-second interval and add the signals to frequency list.
At the end of 5 seconds, we calculate of average of the frequency list to make sure the signal is 1 or 0.
Feel free the to modify the timing and let me know if you find a better tweak.
Note: in the tested device, CPU frequency is 2800Mhz under load and 1000 when ideal. So, I chose a threshold of 2000.
"""
busy_threshold = 2000
number_of_bits = 80
for i in range(number_of_bits):
    frequency = []
    start = int(time.time())
    while int(time.time()) - start < 5:
        if pypsutil.cpu_freq().current > busy_threshold:
            frequency.append(1)
        else:
            frequency.append(0)
        time.sleep(0.5)
    signal = sum(frequency) / len(frequency)
    if signal > 0.5:
        message_bit.append(1)
    else:
        message_bit.append(0)
    print(message_bit)

print(message_bit)
message_bit = ''.join(str(x) for x in message_bit)
"""
We added { to the beginning of the message and } to the end of it.