Tracking Multiple Events
This guide is created to track multiple events and how to visualize the data. For this example, we will extend the app startup example to track multiple events. Checkout the App Startup guide for more context.
Let’s breakdown the Startup Time of the app.
Tracking Multiple Events
We already have one start marker AppLaunchStart (say T1
) and one end marker HomeScreen_Loaded (say T
). Lets add few more markers
T2: Add Main Application OnCreate Marker
7 collapsed lines
override fun onCreate() { // App Launch Start PerformanceTracker.track( "AppLaunchStart", System.currentTimeMillis(), null, true, applicationContext ) super.onCreate()
// Application OnCreate code
PerformanceTracker.track( "Application_onCreate", System.currentTimeMillis(), null, true, applicationContext ) }
T3: Add Activity OnCreate Marker
Add a marker to track the start of the activity in the onCreate
method of MainActivity
class. This is the first method that is called when the activity is going to be created.
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)
PerformanceTracker.track( "ActivityCreated", System.currentTimeMillis(), null, true, applicationContext ) }
T4: Add a marker at the mount of HomeScreen
import { PerformanceTracker } from '@d11/marco';
// enable logging to filePerformanceTracker.configure({ persistToFile: true,});
function HomeScreen(): React.JSX.Element { const [isLoading, setIsLoading] = useState(true);
useEffect(() => { PerformanceTracker.track("HomeScreen_Mounted", Date.now()); }, []);
23 collapsed lines
// Simulating Async operation useEffect(() => { setTimeout(() => { setIsLoading(false); }, 1000); }, []);
if (isLoading) { return ( <View style={styles.container}> <ActivityIndicator size="large" color="#0000ff" /> </View> ); } return ( <SafeAreaView style={styles.outerContainer}> <PerformanceTracker tagName="HomeScreen_Loaded" style={styles.outerContainer}> <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', },});
T5: Add a marker on display of LoadingState
import { PerformanceTracker } from '@d11/marco';
// enable logging to file3 collapsed lines
PerformanceTracker.configure({ persistToFile: true,});
function HomeScreen(): React.JSX.Element {12 collapsed lines
const [isLoading, setIsLoading] = useState(true);
useEffect(() => { PerformanceTracker.track("HomeScreen_Mounted", Date.now()); }, []);
// Simulating Async operation useEffect(() => { setTimeout(() => { setIsLoading(false); }, 1000); }, []);
if (isLoading) { return ( <PerformanceTracker tagName="LoadingState"> <View style={styles.container}> <ActivityIndicator size="large" color="#0000ff" /> </View> </PerformanceTracker> ); } return (7 collapsed lines
<SafeAreaView style={styles.outerContainer}> <PerformanceTracker tagName="HomeScreen_Loaded" style={styles.outerContainer}> <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', },});
Instrumentation
Again perform the same steps as in App Startup guide to run the iteration.
Generate Data
Use the same marco config file as in App Startup guide.
Run generate
command to generate the data.
yarn marco generate --platform android
Visualize Data
Run visualize
command to visualize the data.
yarn marco visualize --platform android
- Below I had attached the screenshot of the dashboard .
- At left side, we can see all the markers with there occurrence.
- Bar chart shows that between which 2 events most of the time is spent.
- Correctness of the data is predicted using mean, standard deviation, error rate.
- And at last we can see the difference between any 2 events iteration wise.
👉 Code reference: Example