|
|
|
| Screenshot | Demo Video |
A comprehensive performance monitoring framework for iOS, macOS, tvOS, and watchOS applications. PerformanceKit provides real-time monitoring of CPU usage, FPS, memory consumption, and system information through an easy-to-use overlay view.
Note: This project was inspired by GDPerformanceView-Swift by Daniil Gavrilov. PerformanceKit builds upon those concepts with modern SwiftUI support, improved architecture, and enhanced customization options.
- Real-time Performance Monitoring: Track CPU usage, FPS, and memory consumption in real-time
- Drag & Drop Overlay: Interactive overlay that can be positioned anywhere on screen
- Customizable Display: Choose which metrics to display and customize the appearance
- Cross-Platform Support: Works on iOS, macOS, tvOS, and watchOS
- SwiftUI & UIKit Support: Seamless integration with both SwiftUI and UIKit
- Programmatic Access: Access performance data programmatically via delegate pattern
- Lifecycle Aware: Automatically pauses when app enters background
- iOS 14.0+
- macOS 11.0+
- tvOS 14.0+
- watchOS 7.0+
- Swift 5.7+
- Xcode 14.0+
Add PerformanceKit to your project using Swift Package Manager:
- In Xcode, select File → Add Packages...
- Enter the package URL:
https://github.com/nazar-41/PerformanceKit.git - Select the version rule you want to use
- Click Add Package
Or add it to your Package.swift:
dependencies: [
.package(url: "https://github.com/nazar-41/PerformanceKit.git", from: "1.0.0")
]import SwiftUI
import PerformanceKit
struct ContentView: View {
var body: some View {
YourContentView()
.performanceMonitor() // Adds the performance overlay
}
}import UIKit
import PerformanceKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Start monitoring programmatically
PerformanceMonitor.shared().delegate = self
PerformanceMonitor.shared().start()
}
}
extension ViewController: PerformanceMonitorDelegate {
func performanceMonitor(didReport performanceReport: PerformanceReport) {
print("CPU: \(performanceReport.cpuUsage)%")
print("FPS: \(performanceReport.fps)")
}
}.performanceMonitor(
options: [.performance, .memory, .application],
style: .light
).performanceMonitor(
style: .custom(
backgroundColor: .blue.opacity(0.8),
borderColor: .white,
borderWidth: 2,
cornerRadius: 16,
textColor: .white
)
)// Access shared instance
let monitor = PerformanceMonitor.shared()
// Start monitoring
monitor.start()
// Access current report
if let report = monitor.currentReport {
print("Current FPS: \(report.fps)")
}
// Set delegate for updates
monitor.delegate = self
// Pause monitoring
monitor.pause()The main class for managing performance monitoring.
currentReport: PerformanceReport?- The latest performance reportdelegate: PerformanceMonitorDelegate?- Delegate for receiving updates
start()- Begins performance monitoringpause()- Pauses performance monitoringstatic shared() -> PerformanceMonitor- Returns the shared instance
A SwiftUI view that displays performance metrics in a draggable overlay.
init(
monitor: PerformanceMonitor = .shared(),
options: DisplayOptions = .default,
style: PerformanceMonitor.Style = .dark
)SwiftUI view modifier for easy integration:
func performanceMonitor(
isEnabled: Bool = true,
options: DisplayOptions = .default,
style: PerformanceMonitor.Style = .dark,
monitor: PerformanceMonitor = .shared()
) -> some ViewPerformanceKit allows you to customize which metrics are displayed:
// Show only performance metrics
DisplayOptions.performance
// Show performance and memory
[.performance, .memory]
// Show everything
DisplayOptions.all
// Default options
DisplayOptions.default // [.performance, .memory]Available options:
.performance- CPU usage and FPS.memory- Memory usage.application- App version and build.device- Device model.system- OS name and version
Choose from predefined styles or create your own:
// Predefined styles
PerformanceMonitor.Style.dark
PerformanceMonitor.Style.light
// Custom style
PerformanceMonitor.Style.custom(
backgroundColor: .blue.opacity(0.8),
borderColor: .white,
borderWidth: 2,
cornerRadius: 16,
textColor: .white
)The PerformanceReport type alias provides access to all monitored metrics:
typealias PerformanceReport = (
cpuUsage: Double, // CPU usage percentage (0-100)
fps: Int, // Frames per second
memoryUsage: MemoryUsage // Memory usage information
)
typealias MemoryUsage = (
used: UInt64, // Used memory in bytes
total: UInt64 // Total memory in bytes
)- Development Only: Consider disabling PerformanceKit in production releases
- Conditional Enabling: Use feature flags to enable/disable monitoring
- User Experience: Position the overlay where it doesn't interfere with app interaction
- Battery Considerations: Continuous monitoring may impact battery life during development
Contributions are welcome! Please feel free to submit a Pull Request.
For issues, questions, or feature requests, please create an issue on GitHub.