sf-agent-framework
Version:
AI Agent Orchestration Framework for Salesforce Development - Two-phase architecture with 70% context reduction
348 lines (266 loc) • 6.92 kB
Markdown
# Performance Analyzer Utility - Agent Instructions
## Purpose
This utility provides instructions for AI agents to generate comprehensive
performance analysis solutions for Salesforce implementations, helping identify
bottlenecks, optimize system performance, and ensure scalability.
## Agent Instructions
### When to Generate Performance Analysis
Generate performance analysis components when:
- System response times need improvement
- Governor limits are being approached
- Page load times require optimization
- API performance needs monitoring
- Batch job efficiency needs assessment
- Query optimization is required
- Scalability planning is needed
### Core Components to Generate
#### 1. Performance Monitoring Engine
Generate monitoring components that:
- Track page load times
- Monitor API response times
- Measure transaction performance
- Capture governor limit usage
- Record resource consumption
- Identify performance bottlenecks
Key metrics to monitor:
- Apex CPU time
- SOQL query count and time
- DML operation count
- Heap size usage
- View state size
- API callout duration
#### 2. Query Analyzer
Create analysis components for:
- SOQL query optimization
- Index usage analysis
- Query plan evaluation
- Selective query detection
- Relationship query analysis
- Aggregate query performance
#### 3. Performance Profiler
Implement profiling for:
- Code execution paths
- Method timing analysis
- Memory usage patterns
- Transaction boundaries
- Asynchronous processing
- Batch job performance
### Configuration Requirements
#### Custom Objects
```yaml
Performance_Metric__c:
- Transaction_Id__c (Text)
- Component_Type__c (Picklist)
- Component_Name__c (Text)
- Start_Time__c (DateTime)
- End_Time__c (DateTime)
- Duration_ms__c (Number)
- CPU_Time_ms__c (Number)
- Heap_Size__c (Number)
- SOQL_Count__c (Number)
- DML_Count__c (Number)
Query_Performance__c:
- Query_String__c (Long Text Area)
- Object_Name__c (Text)
- Execution_Time_ms__c (Number)
- Row_Count__c (Number)
- Is_Selective__c (Checkbox)
- Index_Used__c (Text)
- Optimization_Score__c (Number)
Performance_Alert__c:
- Alert_Type__c (Picklist)
- Severity__c (Picklist)
- Component__c (Text)
- Threshold_Value__c (Number)
- Actual_Value__c (Number)
- Alert_Time__c (DateTime)
- Resolution_Status__c (Picklist)
```
### Performance Metrics to Track
#### Response Time Metrics
```
Page Load Time = Server Time + Network Time + Client Rendering
API Response Time = Processing Time + Network Latency
Transaction Time = Apex Execution + Database Time + Workflow Time
```
#### Resource Usage Metrics
```
CPU Usage = (CPU Time Used / CPU Limit) × 100
Memory Usage = (Heap Used / Heap Limit) × 100
Query Efficiency = (Rows Returned / Rows Scanned) × 100
```
#### Scalability Metrics
```
Concurrent User Capacity = System Resources / Average Resource per User
Transaction Throughput = Successful Transactions / Time Period
System Utilization = Active Resources / Total Resources
```
### Implementation Patterns
#### Real-time Monitoring Pattern
1. Instrument code with timing
2. Capture performance events
3. Stream to monitoring system
4. Analyze in real-time
5. Trigger alerts
6. Update dashboards
#### Batch Analysis Pattern
1. Collect performance logs
2. Aggregate metrics
3. Identify patterns
4. Generate reports
5. Recommend optimizations
6. Track improvements
#### Proactive Optimization Pattern
1. Monitor trends
2. Predict issues
3. Suggest optimizations
4. Test improvements
5. Deploy changes
6. Measure impact
### Analysis Techniques
#### Query Optimization
```
1. Analyze query patterns
2. Check index usage
3. Evaluate selectivity
4. Review relationships
5. Optimize filters
6. Implement query caching
```
#### Code Performance Analysis
```
1. Profile execution paths
2. Identify hot spots
3. Measure method timing
4. Analyze loops
5. Check collection usage
6. Optimize algorithms
```
#### Governor Limit Analysis
```
1. Track limit usage
2. Identify trends
3. Project growth
4. Set thresholds
5. Implement warnings
6. Plan remediation
```
### Dashboard Components to Generate
#### Performance Overview Dashboard
Display:
- System health score
- Response time trends
- Resource utilization
- Top slow components
- Governor limit usage
- Alert summary
#### Query Performance Dashboard
Show:
- Slowest queries
- Most frequent queries
- Non-selective queries
- Query optimization suggestions
- Index usage statistics
- Query trends
#### User Experience Dashboard
Include:
- Page load times
- User journey analysis
- Performance by browser
- Geographic performance
- Mobile vs desktop
- Error rates
### Optimization Recommendations
#### Query Optimization
- Use selective filters
- Leverage indexes
- Minimize data returned
- Avoid queries in loops
- Use relationship queries wisely
- Implement query result caching
#### Apex Code Optimization
- Bulkify operations
- Minimize loops
- Use collections efficiently
- Lazy load data
- Implement caching
- Optimize algorithms
#### UI Performance
- Minimize view state
- Use pagination
- Lazy load components
- Optimize images
- Minimize API calls
- Use Lightning Data Service
### Best Practices to Implement
1. **Monitoring Strategy**
- Continuous monitoring
- Baseline establishment
- Trend analysis
- Proactive alerts
- Regular reviews
2. **Performance Testing**
- Load testing
- Stress testing
- Volume testing
- Spike testing
- Endurance testing
3. **Optimization Process**
- Identify bottlenecks
- Prioritize issues
- Test solutions
- Measure impact
- Document changes
4. **Capacity Planning**
- Growth projections
- Resource planning
- Scalability testing
- Architecture review
- Upgrade planning
### Advanced Features to Consider
1. **AI-Powered Analysis**
- Anomaly detection
- Pattern recognition
- Predictive analysis
- Auto-optimization
- Smart recommendations
2. **Automated Optimization**
- Query rewriting
- Code refactoring
- Index suggestions
- Caching strategies
- Resource allocation
3. **Performance Simulation**
- Load modeling
- What-if analysis
- Capacity simulation
- Growth scenarios
- Impact prediction
### Error Handling Instructions
Handle these scenarios:
1. Monitoring overhead
2. Data collection failures
3. Analysis timeouts
4. Storage limitations
5. Alert fatigue
Recovery strategies:
- Sampling strategies
- Graceful degradation
- Data archival
- Alert tuning
- Manual overrides
### Testing Requirements
Generate test classes for:
1. Performance metrics collection
2. Analysis algorithms
3. Alert triggers
4. Dashboard accuracy
5. Optimization validation
### Success Metrics
Track and measure:
- Performance improvement
- Issue detection rate
- Resolution time
- System stability
- User satisfaction
- Cost optimization