0% found this document useful (0 votes)
11 views5 pages

Report

try

Uploaded by

Raghul Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Report

try

Uploaded by

Raghul Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

RESOURCE UTILIZATION OF A PROGRAM

CPU Usage:
 Total CPU Usage
 CPU Usage by Process
 Number of CPU Cores Utilized

Memory Usage (RAM)


 Total RAM Usage
 RAM Usage by Process

Disk I/O
 Disk Read/Write Operations
 Disk Space Usage

Network I/O
 Network Bandwidth Usage

Execution Time
 Total Execution Time
 Time Spent on Specific Tasks

GPU Usage (if applicable)


 Total GPU Usage
 GPU Usage by Process
FOR THE FOLDER, IMAGES AND EXCEL FILES

File Size
 Image Files: Size of each image file.
 PDF File: Size of the generated PDF file.
 Excel File: Size of the generated Excel file.

File Count
 Total Image Count: Number of images generated.
 Processed Image Count: Number of images added to the PDF.

PDF File Specific Parameters


 Total Pages: Number of pages in the PDF.
 Creation Date: Date and time when the PDF was created.
 Modification Date: Last modification date of the PDF.
 CPU, RAM and Storage usage

Excel File Specific Parameters


 Total Sheets: Number of sheets in the Excel file.
 Row and Column Counts
 CPU, RAM and Storage usage
 Creation Date: Date and time when the Excel file was created.

File Integrity and Validation


 Path Verification: Ensure the file paths exist and are accessible.
 Access Permissions: Verify read/write permissions for each file.
These should done by the program itself.
Python code of the example program:
This program will process a video and save the frames of the video with people in it inside a
folder. And it will create a resource utilization log file which has all the other details.

import cv2
import matplotlib.pyplot as plt
import os
import psutil
import GPUtil
import time

# Initialize the HOG descriptor/person detector


hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

# Function to detect humans in a frame


def detect_humans(frame):
# Resize the frame to reduce detection time and improve detection accuracy
frame_resized = cv2.resize(frame, (frame.shape[1] // 2, frame.shape[0] // 2))
# Detect humans in the frame
boxes, weights = hog.detectMultiScale(frame_resized, winStride=(8, 8))
return boxes

# Function to save frames with humans


def save_frame_with_humans(frame, frame_index, output_dir):
boxes = detect_humans(frame)
if len(boxes) > 0:
for (x, y, w, h) in boxes:
x, y, w, h = x * 2, y * 2, w * 2, h * 2
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
# Save the frame as an image
output_path = os.path.join(output_dir, f'frame_{frame_index}.jpg')
cv2.imwrite(output_path, frame)

# Function to log resource usage


def log_resource_usage(pid, log_file, start_time):
process = psutil.Process(pid)
gpus = GPUtil.getGPUs()
disk_io = psutil.disk_io_counters()
net_io = psutil.net_io_counters()
cpu_percent = process.cpu_percent(interval=0.1)
memory_info = process.memory_info()
num_threads = process.num_threads()
disk_usage = psutil.disk_usage('/')
elapsed_time = time.time() - start_time
with open(log_file, 'a') as f:
f.write(f"Time: {time.time()}, CPU Usage: {cpu_percent}%, "
f"Memory Usage: {memory_info.rss / (1024 ** 2):.2f} MB, "
f"Memory Percent: {process.memory_percent():.2f}%, "
f"Number of Threads: {num_threads}, "
f"Disk Read: {disk_io.read_bytes / (1024 ** 2):.2f} MB, "
f"Disk Write: {disk_io.write_bytes / (1024 ** 2):.2f} MB, "
f"Disk Usage: {disk_usage.percent}%, "
f"Network Sent: {net_io.bytes_sent / (1024 ** 2):.2f} MB, "
f"Network Received: {net_io.bytes_recv / (1024 ** 2):.2f} MB, "
f"Total Execution Time: {elapsed_time:.2f} seconds\n")
for gpu in gpus:
f.write(f"GPU {gpu.id}: {gpu.name}, "
f"GPU Memory Free: {gpu.memoryFree}MB, "
f"GPU Memory Used: {gpu.memoryUsed}MB, "
f"GPU Memory Total: {gpu.memoryTotal}MB, "
f"GPU Utilization: {gpu.load * 100}%, "
f"GPU Temperature: {gpu.temperature} C\n")

# Main function to process the video


def process_video(input_video_path, output_dir, log_file):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
cap = cv2.VideoCapture(input_video_path)
frame_index = 0
pid = os.getpid()
start_time = time.time()
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
save_frame_with_humans(frame, frame_index, output_dir)
log_resource_usage(pid, log_file, start_time)
frame_index += 1
cap.release()

# Example usage
input_video_path = 'input_video.mp4' # Path to your input video file
output_dir = 'output_images' # Directory to save output images
log_file = 'resource_usage.log' # Log file to save resource usage data
process_video(input_video_path, output_dir, log_file)
Example of the images generated:

Example of the resource_usage.log file:

Time: 1717399749.541451, CPU Usage: 14.2%, Memory Usage: 156.48 MB, Memory
Percent: 1.94%, Number of Threads: 21, Disk Read: 130539.97 MB, Disk Write:
96744.77 MB, Disk Usage: 76.3%, Network Sent: 8079.24 MB, Network Received:
24129.20 MB, Total Execution Time: 3.18 seconds

You might also like