NeuralScope
- Stars
- 6
- Language
- Objective-C
- Updated
NeuralScope - AI-Aware System Diagnostics Console
NeuralScope is a production-grade, hybrid Objective-C/Swift diagnostics console designed for AI applications. It provides comprehensive system monitoring, performance tracking, and ML inference analytics with local-first privacy.
π Features
- Real-time System Monitoring: CPU, memory, thermal state, and app lifecycle tracking
- ML Inference Tracking: Automatic Core ML model performance monitoring
- Intelligent Diagnostics: Heuristic analysis for performance bottlenecks
- Local-first Privacy: All data stored locally with encryption-ready architecture
- Hybrid Architecture: Objective-C core engine with SwiftUI interface
- Production Ready: Thread-safe, memory-efficient, and scalable
π¦ Installation
CocoaPods (Recommended)
pod 'NeuralScope', '~> 1.0'
Manual Installation
- Clone the repository:
git clone https://github.com/Manavarya09/NeuralScope.git
- Add the NeuralScope framework to your Xcode project
- Import the bridging header in your Swift files
π οΈ Quick Start
Basic Setup
import NeuralScope
// Initialize NeuralScope (automatically starts monitoring)
let neuralScope = NSNeuralScopeEngine.shared()
// Start monitoring (called automatically in AppDelegate)
neuralScope.startMonitoring()
SwiftUI Integration
import SwiftUI
import NeuralScope
struct ContentView: View {
@StateObject private var neuralScope = NeuralScopeEngine.shared
var body: some View {
NeuralScopeConsoleView()
}
}
π Core Components
System Monitoring
// Automatic system event tracking
NSSystemEventMonitor *monitor = [NSSystemEventMonitor shared];
// Manual event logging
[monitor logSystemEvent:NSSystemEventTypeAppDidBecomeActive
metadata:@{@"source": @"manual"}];
Performance Sampling
// Automatic performance monitoring
NSPerformanceSampler *sampler = [NSPerformanceSampler shared];
// Sample current metrics
NSDictionary *metrics = [sampler sampleCurrentMetrics];
NSLog(@"CPU Usage: %.1f%%", [metrics[@"cpuUsage"] floatValue]);
ML Inference Tracking
// Track ML model inference
NSMLInferenceTracker *tracker = [NSMLInferenceTracker shared];
// Log inference start
[tracker logInferenceStart:@"image-classifier" model:@"MobileNetV3"];
// Log inference completion with duration
[tracker logInferenceComplete:@"image-classifier" duration:0.023];
Diagnostics Engine
// Get diagnostic insights
NSDiagnosticsEngine *diagnostics = [NSDiagnosticsEngine shared];
NSArray<NSDiagnosticInsight *> *insights = [diagnostics analyzeRecentEvents];
// Process insights
for (NSDiagnosticInsight *insight in insights) {
NSLog(@"Insight: %@ - %@", insight.title, insight.description);
}
π§ Advanced Configuration
Custom Event Types
// Define custom telemetry events
NSTelemetryEvent *customEvent = [[NSTelemetryEvent alloc] init];
customEvent.eventID = [[NSUUID UUID] UUIDString];
customEvent.eventType = @"custom_metric";
customEvent.timestamp = [NSDate date];
customEvent.metadata = @{@"value": @42.5};
// Save to persistence layer
[[NSTelemetryPersistence shared] saveEvent:customEvent];
Background Monitoring
// NeuralScope automatically handles background/foreground transitions
// No additional configuration needed for basic monitoring
// For custom background tasks:
- (void)applicationDidEnterBackground:(UIApplication *)application {
// NeuralScope automatically pauses intensive monitoring
// Custom cleanup can be added here
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// NeuralScope automatically resumes monitoring
// Custom restoration can be added here
}
π± SwiftUI Integration
Complete Dashboard
struct MyApp: App {
var body: some Scene {
WindowGroup {
NeuralScopeConsoleView()
}
}
}
Custom Views
struct CustomMetricsView: View {
@StateObject private var neuralScope = NeuralScopeEngine.shared
var body: some View {
VStack {
Text("Custom Metrics")
.font(.title)
// Access NeuralScope data
if let latestEvent = neuralScope.recentEvents.first {
Text("Latest Event: \(latestEvent.eventType)")
}
}
}
}
π Data Persistence
Core Data Integration
NeuralScope uses Core Data for efficient local storage:
// Query telemetry data
NSFetchRequest *request = [NSTelemetryEvent fetchRequest];
request.predicate = [NSPredicate predicateWithFormat:@"eventType == %@", @"performance"];
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:NO]];
NSArray *results = [[NSTelemetryPersistence shared].managedObjectContext executeFetchRequest:request error:nil];
Data Export
// Export data for analysis
NSDictionary *exportData = [[NSTelemetryPersistence shared] exportDataForTimeRange:startDate endDate:endDate];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:exportData options:NSJSONWritingPrettyPrinted error:nil];
[jsonData writeToFile:exportPath atomically:YES];
π― ML Integration Examples
Core ML Model Tracking
import CoreML
import Vision
class ImageClassifier {
private let neuralScope = NSMLInferenceTracker.shared()!
func classify(image: UIImage) async throws -> String {
// Start tracking
neuralScope.logInferenceStart("image-classifier", model: "MobileNetV3")
let startTime = Date()
// Perform inference
let model = try await VNCoreMLModel(for: MobileNetV3().model)
let request = VNCoreMLRequest(model: model)
let handler = VNImageRequestHandler(cgImage: image.cgImage!)
try handler.perform([request])
let duration = Date().timeIntervalSince(startTime)
// Complete tracking
neuralScope.logInferenceComplete("image-classifier", duration: duration)
// Process results
guard let results = request.results as? [VNClassificationObservation],
let topResult = results.first else {
return "Unknown"
}
return topResult.identifier
}
}
Custom ML Pipeline Monitoring
@interface MLProcessor : NSObject
@property (nonatomic, strong) NSMLInferenceTracker *tracker;
@end
@implementation MLProcessor
- (instancetype)init {
self = [super init];
if (self) {
self.tracker = [NSMLInferenceTracker shared];
}
return self;
}
- (NSDictionary *)processPipeline:(NSData *)inputData {
// Track preprocessing
[self.tracker logInferenceStart:@"preprocessing" model:@"data-normalizer"];
// Preprocessing logic...
NSDictionary *preprocessedData = [self preprocessData:inputData];
[self.tracker logInferenceComplete:@"preprocessing" duration:0.1];
// Track model inference
[self.tracker logInferenceStart:@"inference" model:@"neural-network"];
// Model inference...
NSDictionary *results = [self runInference:preprocessedData];
[self.tracker logInferenceComplete:@"inference" duration:0.05];
return results;
}
@end
ποΈ Architecture
Hybrid Design
βββββββββββββββββββ βββββββββββββββββββ
β SwiftUI β β Objective-C β
β Interface βββββΊβ Core Engine β
β β β β
β β’ Dashboard β β β’ System Monitorβ
β β’ Settings β β β’ Performance β
β β’ Timeline β β β’ ML Tracking β
βββββββββββββββββββ β β’ Diagnostics β
β β’ Persistence β
βββββββββββββββββββ
Thread Safety
NeuralScope is designed for concurrent access:
- Main Thread: UI updates and user interactions
- Background Threads: Data processing and persistence
- GCD Integration: Automatic queue management
- Thread-safe APIs: All public methods are thread-safe
π Privacy & Security
Local-first Design
- All data stored locally on device
- No external network communication
- Encryption-ready architecture
- User-controlled data retention
Data Minimization
- Automatic data cleanup policies
- Configurable retention periods
- Minimal memory footprint
- Efficient storage usage
π Performance
Benchmarks (iPhone 15 Pro)
- Memory Usage: < 50MB baseline, < 100MB with data
- CPU Overhead: < 2% during normal monitoring
- Storage: ~1MB per day of typical usage
- ML Tracking: < 0.1ms per inference event
Optimization Features
- Lazy Loading: Components initialized on demand
- Background Processing: Non-blocking data operations
- Memory Management: Automatic cleanup and caching
- Battery Aware: Reduced monitoring during low power
π Troubleshooting
Common Issues
Build Errors
# Clean and rebuild
xcodebuild clean
xcodebuild build -project NeuralScope.xcodeproj
Missing Data
// Check if monitoring is active
if (![[NSNeuralScopeEngine shared] isMonitoring]) {
[[NSNeuralScopeEngine shared] startMonitoring];
}
Performance Issues
// Adjust sampling intervals
NSPerformanceSampler *sampler = [NSPerformanceSampler shared];
sampler.samplingInterval = 5.0; // Increase from default 1.0s
π API Reference
NSNeuralScopeEngine
+ (instancetype)shared- Get singleton instance- (void)startMonitoring- Begin system monitoring- (void)stopMonitoring- Stop system monitoring- (BOOL)isMonitoring- Check monitoring status
NSMLInferenceTracker
+ (instancetype)shared- Get singleton instance- (void)logInferenceStart:(NSString *)operation model:(NSString *)model- Start inference tracking- (void)logInferenceComplete:(NSString *)operation duration:(NSTimeInterval)duration- Complete inference tracking
NSTelemetryPersistence
+ (instancetype)shared- Get singleton instance- (void)saveEvent:(NSTelemetryEvent *)event- Save telemetry event- (NSArray<NSTelemetryEvent *> *)fetchEventsWithPredicate:(NSPredicate *)predicate- Query events
π€ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
π License
NeuralScope is available under the MIT License. See LICENSE for details.
π Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: NeuralScope Docs
Built with β€οΈ for the AI development community