App Startup
This guide demonstrates how to leverage Marco to track app startup performance. By adding markers at key points during the app’s lifecycle, one can gain insights into how long various parts of the startup process take.
Additionally, we can fetch data using Marco’s generate
command, and visualize
the results for better analysis.
Tracking App Startup Performance
Step 1: Add Start Marker
For App Startup, we will add a start marker at the beginning of the app’s lifecycle.
-
For Android, add a marker to track the start of the app in the
onCreate
method ofMainApplication
class. This is the first method that is called when the app is launched. -
For iOS, add a marker to track the start of the app in the
application
method of AppDelegate.m.import com.performancetracker.PerformanceTracker;override fun onCreate() {super.onCreate()PerformanceTracker.track("AppLaunchStart",System.currentTimeMillis(),null,true, // writeLogInFile is true to save the data to a fileapplicationContext // applicationContext is the context of the app to write the data to a file)// other code}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{[[PerformanceTracker sharedInstance] track:@"AppLaunchStart"timestamp:(long long) [[NSDate date] timeIntervalSince1970] * 1000meta: nilwriteLogInFile:YES];return [super application:application didFinishLaunchingWithOptions:launchOptions];}
Step 2: Add End Marker
Firstly let’s add a sample screen to track the end marker. Here we will simulate a real world scenarios using setTimeout
to delay the screen loading(Assuming this is a network call or some heavy operation).
import { PerformanceTracker } from '@d11/marco';
// enable logging to filePerformanceTracker.configure({ persistToFile: true,});
function HomeScreen(): React.JSX.Element { const [isLoading, setIsLoading] = useState(true); // Simulating Async operation5 collapsed lines
useEffect(() => { setTimeout(() => { setIsLoading(false); }, 1000); }, []);
if (isLoading) { return ( <PerformanceTracker tagName="LoadingState" style={styles.outerContainer}>3 collapsed lines
<View style={styles.container}> <ActivityIndicator size="large" color="#0000ff" /> </View> </PerformanceTracker> ); } return ( <SafeAreaView style={styles.outerContainer}> <PerformanceTracker tagName="HomeScreen_Loaded" style={styles.outerContainer}>3 collapsed lines
<View style={styles.container}> <Text testID="home_screen_text" style={styles.text}>Home Screen</Text> </View> </PerformanceTracker> </SafeAreaView> );}
const styles = StyleSheet.create({18 collapsed lines
container: { justifyContent: 'center', alignItems: 'center', backgroundColor: '#f0f0f0', borderWidth: 1, borderColor: 'black', borderRadius: 10, padding: 10, }, text: { fontSize: 24, fontWeight: 'bold', }, outerContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', },});
- For end marker, add a marker when the screen is fully drawn. This gives a sense of how long it takes for the app to be ready to interact with the user.
For this just wrap the screen or any component with
PerformanceTracker
and provide a tag name.
This will track the time it took to draw the PerformanceTracker component entirely.
Step 3: Instrumentation
Use any instrumentation tool to run the iteration. For example: maestro. After running the iteration, it will save the data in device itself.
Step 4: Create a marco.config.js
Create a marco.config.js
file at the root of project with the following content.
module.exports = { android: { packageName: 'com.example.app', outputPath: './app-startup-reports/android', dataDir: './app-startup-reports/android/log.json', port: '8080', }, ios: { packageName: 'com.example.app', outputPath: './app-startup-reports/ios', dataDir: './app-startup-reports/ios/log.json', port: '8080', },};
Step 5: Generate Data
Use generate
command to generate the data.
yarn marco generate --platform android
- It will save the data in specified path (./app-startup-reports/android/log.json).
Here is the sample report generated:
[ { "tagName": "AppLaunchStart", "timestamp": "1738089908375" }, { "tagName": "HomeScreen_Loaded", "timestamp": "1738089908973" },56 collapsed lines
{ "tagName": "AppLaunchStart", "timestamp": "1738089914779" }, { "tagName": "HomeScreen_Loaded", "timestamp": "1738089915349" }, { "tagName": "AppLaunchStart", "timestamp": "1738089918248" }, { "tagName": "HomeScreen_Loaded", "timestamp": "1738089918816" }, { "tagName": "AppLaunchStart", "timestamp": "1738089921612" }, { "tagName": "HomeScreen_Loaded", "timestamp": "1738089922182" }, { "tagName": "AppLaunchStart", "timestamp": "1738089926458" }, { "tagName": "HomeScreen_Loaded", "timestamp": "1738089927022" }, { "tagName": "AppLaunchStart", "timestamp": "1738089944241" }, { "tagName": "HomeScreen_Loaded", "timestamp": "1738089944833" }, { "tagName": "AppLaunchStart", "timestamp": "1738089949008" }, { "tagName": "HomeScreen_Loaded", "timestamp": "1738089949583" }, { "tagName": "AppLaunchStart", "timestamp": "1738089954020" }, { "tagName": "HomeScreen_Loaded", "timestamp": "1738089954616" }]
Step 6: Visualize Data
Use visualize
command to visualize the data.
yarn marco visualize --platform android
- It will open the dashboard in the browser.
- Below I had attached the screenshot of the dashboard.
- At left side, it will show all the markers with there occurrence.
- Iteration wise data is shown in bar chart.
- Raw data are processed and shown in timeline.
- Also have access to other metrics like mean, standard deviation, error rate to predict the correctness of the data.
👉 Code reference: Example