A beautiful native macOS application built with SwiftUI that visualizes CPU scheduling algorithms with realistic mock data and stunning animations.
- Features
- Technical Logics
- Getting Started
- Project Structure
- Architecture
- Contributing
- Code of Conduct
- License
- Credits
- FCFS (First-Come, First-Served)
- SJF (Shortest Job First)
- SRTF (Shortest Remaining Time First)
- Round Robin (with adjustable time quantum)
- Priority (Non-Preemptive)
- Priority (Preemptive)
- Interactive Gantt Charts using Swift Charts
- Animated timeline with hover effects
- Real-time metrics display
- Per-process analysis with detailed tables
- Side-by-side comparison of multiple algorithms
- Performance metrics: Turnaround time, waiting time, response time, CPU utilization, throughput
- Context switch tracking
- Bar charts for metric comparison
- Interactive tutorials on CPU scheduling concepts
- Step-by-step explanations for each algorithm
- Quiz questions to test understanding
- Algorithm reference cards with pros/cons
- Live CPU/memory graphs with mock data
- Process list with sortable columns
- Real-time updates using Timer
- Animated sparklines
CPU scheduling determines which process in the ready queue is to be allocated the CPU. This visualization app demonstrates several fundamental scheduling algorithms, each with its unique logic:
- Logic: The simplest scheduling algorithm. Processes are assigned the CPU in the order they request it (FIFO queue).
- Preemption: Non-preemptive. Once a process gets the CPU, it keeps it until it releases the CPU, either by terminating or by requesting I/O.
- Characteristics: Easy to implement but can suffer from the "convoy effect" where short processes wait a long time for a single long process to finish, increasing average waiting time.
- Logic: Associates with each process the length of its next CPU burst. The CPU is assigned to the process with the smallest next CPU burst.
- Preemption: Non-preemptive.
- Characteristics: Provably optimal in terms of minimizing the average waiting time for a given set of processes. The difficulty lies in accurately predicting the length of the next CPU request.
- Logic: The preemptive version of SJF. If a new process arrives with a CPU burst length shorter than what is left of the currently executing process, the CPU is preempted.
- Preemption: Preemptive.
- Characteristics: Extremely fast response times for short processes but can lead to starvation of long processes if short processes keep arriving.
- Logic: Similar to FCFS, but preemption is added to switch between processes. A small unit of time, called a time quantum or time slice, is defined. The CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to one time quantum.
- Preemption: Preemptive.
- Characteristics: Excellent response time, especially for time-sharing systems. Performance depends heavily on the size of the time quantum.
- Logic: A priority number is associated with each process. The CPU is allocated to the process with the highest priority (usually denoted by the lowest integer value).
- Preemption: Non-preemptive. Once a process gets the CPU, it runs until completion.
- Characteristics: Can lead to starvation of low-priority processes. A solution to starvation is aging (gradually increasing the priority of processes that wait in the system for a long time).
- Logic: Similar to non-preemptive priority, but if a newly arrived process has a higher priority than the currently running process, the CPU is preempted.
- Preemption: Preemptive.
- Characteristics: Ensures the most important task is always running, but increases context switching overhead.
- macOS 14.0 (Ventura) or later
- Xcode 15.0 or later
- Swift 5.9 or later
- Clone or download this repository:
git clone https://github.com/r69shabh/CPUSchdUI.git
- Open
CPUSchedulerUI.xcodeprojin Xcode. - Select "My Mac" as the run destination.
- Press
βRto build and run.
- Add Processes: Click the
+button in the Simulator tab. You can choose "Load Scenario" for preset examples or add processes manually. - Select Algorithm: Click the algorithm dropdown to choose from the 6 available algorithms (adjust time quantum if using Round Robin).
- Run Simulation: Click "Run" or press
βReturnto watch the animated Gantt chart appear. Scroll down for detailed metrics. - Compare Algorithms: Switch to the Comparison tab, toggle algorithm checkboxes, load a scenario, and click "Compare".
CPUSchedulerUI/
βββ Models/
β βββ AppColors.swift # Color palette & typography
β βββ Process.swift # Process & TimelineEvent models
β βββ Algorithm.swift # Algorithm definitions
β βββ PerformanceMetrics.swift # Metrics structures
β βββ SchedulingResult.swift # Result wrapper
β βββ Tutorial.swift # Tutorial models
βββ ViewModels/
β βββ SimulatorViewModel.swift
β βββ ComparisonViewModel.swift
β βββ MonitorViewModel.swift
β βββ TutorialViewModel.swift
βββ Views/
β βββ MainWindowView.swift # Split view with sidebar
β βββ Simulator/ # Main simulation interface
β βββ Visualization/ # Gantt charts
β βββ Metrics/ # Metrics display
β βββ Comparison/ # Algorithm comparison
β βββ Monitor/ # System monitor
β βββ Education/ # Tutorials
β βββ Settings/ # Preferences
β βββ Components/ # Reusable UI components
βββ Services/
β βββ MockDataService.swift # Realistic mock data generation
β βββ PreferencesService.swift # User preferences
βββ Resources/
βββ Assets.xcassets/ # App icons & colors
- Pattern: MVVM (Model-View-ViewModel)
- UI Framework: SwiftUI with native macOS components
- Charts: Swift Charts for data visualization
- State Management:
@StateObject,@Published,@AppStorage - Animations: Spring animations, matched geometry effects
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please make sure to update tests as appropriate and adhere to the project's coding standards.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. Let's build a welcoming and inclusive community.
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ using SwiftUI and Swift Charts for macOS 14+