benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 0f6686a1-8f1a-568f-bc73-5bf6d1c7c903

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import subprocess
import time
import json
import platform

LOGFILE_PATH = "logfile.log"


def task_func(interval, duration):
    """
    Monitors and logs CPU usage at specified intervals over a given duration.

    Parameters:
    interval (int): The frequency, in seconds, at which CPU usage data is captured. Must be greater than zero.
    duration (int): The total duration, in seconds, for which CPU usage is monitored. Must be greater than zero.

    Returns:
    str: Path to the log file where CPU usage data is saved. Returns None if an IOError occurs during file operations.

    Raises:
    ValueError: If either 'interval' or 'duration' is less than or equal to zero.

    Requirements:
    - subprocess
    - time
    - json
    - platform

    Note: 
    Actual run time of the function may slightly exceed the specified 'duration' due to processing time and system response delay.
    The function records the CPU usage percentage at regular intervals for a specified duration.
    The data is captured every 'interval' seconds until the 'duration' is reached or exceeded.
    Each record includes a timestamp and the CPU usage percentage at that moment.
    The data is saved in JSON format in a log file named 'logfile.log'.
    The function supports different commands for CPU usage monitoring on Windows and Unix/Linux platforms.
    
    Example:
    >>> task_func(5, 60)
    'logfile.log'
    """

instruct prompt

Monitors and logs CPU usage at specified intervals over a given duration.
Note that: Actual run time of the function may slightly exceed the specified 'duration' due to processing time and system response delay. The function records the CPU usage percentage at regular intervals for a specified duration. The data is captured every 'interval' seconds until the 'duration' is reached or exceeded. Each record includes a timestamp and the CPU usage percentage at that moment. The data is saved in JSON format in a log file named 'logfile.log'. The function supports different commands for CPU usage monitoring on Windows and Unix/Linux platforms.
The function should raise the exception for: ValueError: If either 'interval' or 'duration' is less than or equal to zero.
The function should output with:
    str: Path to the log file where CPU usage data is saved. Returns None if an IOError occurs during file operations.
You should write self-contained code starting with:

Code

import subprocess
import time
import json
import platform
LOGFILE_PATH = "logfile.log"
def task_func(interval, duration):

code prompt

Code

import subprocess
import time
import json
import platform
LOGFILE_PATH = "logfile.log"
def task_func(interval, duration):

entry point

task_func

libs

  • subprocess
  • platform
  • json
  • time

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import