الفرق بين المراجعتين ل"ReactNative/systrace"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
ط
 
(8 مراجعات متوسطة بواسطة مستخدمين اثنين آخرين غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE:Systrace في React Native}}</noinclude>
+
<noinclude>{{DISPLAYTITLE:الواجهة Systrace في React Native}}</noinclude>
إن <code>Systrace</code> هي أداة تعريف الأداء، تعتمد على العلامات (marker-based profiling tool) المعيارية لمنصة Android، وتُثبّت مع حزمة أدوات منصّة Android. تُحاط كتل الشفرة البرمجيّة المشخَّصة بوسوم البداية، والنهاية فتظهر على شكل مخططٍ ملوَّنٍ، وتحوي كل من Android SDK، و<nowiki/>[[ReactNative|React Native]]  على الوسوم المعيارية التي يمكن إظهارها.
+
إن <code>Systrace</code> هي أداة تعريف الأداء، تعتمد على العلامات (marker-based profiling tool) المعيارية لمنصة Android، وتُثبّت مع حزمة أدوات منصّة Android. تُحاط كتل الشفرة البرمجيّة المشخَّصة بوسوم البداية، والنهاية فتظهر على شكل مخططٍ ملوَّنٍ، وتحوي كل من Android SDK، و [[ReactNative|React Native]]  على الوسوم المعيارية التي يمكن إظهارها.
 
__toc__
 
__toc__
 
== مثال ==
 
== مثال ==
تسمح <code>Systrace</code> بوسمٍ أحداث ‪‏‫‬‫‪‎‎‏JavaScript (JS) بوسمٍ، وبقيمةٍ صحيحةٍ، وهذا المثال لالتقاط أحداث JS غير المرتبطة بالزمن (non-Timed) ضمن EasyProfiler   
+
تسمح <code>Systrace</code> بوسمٍ أحداث ‎‎‏JavaScript بوسمٍ، وبقيمةٍ صحيحةٍ، وهذا المثال لالتقاط أحداث JS غير المرتبطة بالزمن (non-Timed) ضمن EasyProfiler.  
  
* مثال لمكون دالّة (Function Component Example)
+
* [https://snack.expo.dev/@hsoubwiki/systrace-function-component-example مثال لمكون دالّة (Function Component)]
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
import React from "react";
 
import React from "react";
import { Button, Text, View, StyleSheet, Systrace } from "react-native";
+
import { Button, Text, View, SafeAreaView, StyleSheet, Systrace } from "react-native";
+
 
 
const App = () =>  {
 
const App = () =>  {
+
 
 const enableProfiling = () => {
+
  const enableProfiling = () => {
   Systrace.setEnabled(true); // Call setEnabled to turn on the profiling.
+
    Systrace.setEnabled(true); // Call setEnabled to turn on the profiling.
   Systrace.beginEvent('event_label')
+
    Systrace.beginEvent('event_label')
   Systrace.counterEvent('event_label', 10);
+
    Systrace.counterEvent('event_label', 10);
 
   }
 
   }
+
 
 const stopProfiling = () => {
+
  const stopProfiling = () => {
   Systrace.endEvent()
+
    Systrace.endEvent()
 
   }
 
   }
+
 
 return (
+
  return (
   <View style={styles.container}>
+
    <SafeAreaView style={styles.container}>
     <Text style={[styles.header, styles.paragraph]}>React Native Systrace API</Text>
+
      <Text style={[styles.header, styles.paragraph]}>React Native Systrace API</Text>
     <Button title="Capture the non-Timed JS events in EasyProfiler" onPress={()=> enableProfiling()}/>
+
    <View style={styles.buttonRow}>
     <Button title="Stop capturing" onPress={()=> stopProfiling()} color="#FF0000"/>
+
      <Button title="Capture the non-Timed JS events in EasyProfiler" onPress={()=> enableProfiling()}/>
   </View>
+
      <Button title="Stop capturing" onPress={()=> stopProfiling()} color="#FF0000"/>
 +
    </View>
 +
    </SafeAreaView>
 
   );
 
   );
 
}
 
}
+
 
 
const styles = StyleSheet.create({
 
const styles = StyleSheet.create({
 container: {
+
  container: {
   flex: 1,
+
    flex: 1,
   backgroundColor: '#fff',
+
    backgroundColor: '#fff',
   alignItems: 'center',
+
    alignItems: 'center',
   justifyContent: 'center',
+
    justifyContent: 'center',
   paddingTop: 44,
+
    paddingTop: 44,
   padding: 8
+
    padding: 8
 
   },
 
   },
  header: {
+
  header: {
   fontSize: 18,
+
    fontSize: 18,
   fontWeight: "bold",
+
    fontWeight: "bold",
   textAlign: "center"
+
    textAlign: "center"
 
   },
 
   },
 paragraph: {
+
  paragraph: {
   margin: 24,
+
    margin: 24,
   textAlign: "center"
+
    fontSize: 25,
 +
    textAlign: "center"
 +
  },
 +
  buttonRow: {
 +
    flexBasis: 150,
 +
    marginVertical: 16,
 +
    justifyContent: 'space-evenly'
 
   }
 
   }
 
});
 
});
+
 
 
export default App;
 
export default App;
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* مثال لمكوّن صنف (Class Component Example )
+
* [https://snack.expo.dev/@hsoubwiki/systrace-class-component-example مثال لمكوّن صنف (Class Component)]
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
import React, { Component } from "react";
 
import React, { Component } from "react";
import { Button, Text, View, StyleSheet, Systrace } from "react-native";
+
import { Button, Text, View, SafeAreaView, StyleSheet, Systrace } from "react-native";
+
 
 
class App extends Component {
 
class App extends Component {
+
 
 enableProfiling = () => {
+
  enableProfiling = () => {
   Systrace.setEnabled(true); // Call setEnabled to turn on the profiling.
+
    Systrace.setEnabled(true); // Call setEnabled to turn on the profiling.
   Systrace.beginEvent('event_label')
+
    Systrace.beginEvent('event_label')
   Systrace.counterEvent('event_label', 10);
+
    Systrace.counterEvent('event_label', 10);
 
   }
 
   }
+
 
 stopProfiling = () => {
+
  stopProfiling = () => {
   Systrace.endEvent()
+
    Systrace.endEvent()
 
   }
 
   }
+
 
 render() {
+
  render() {
   return (
+
    return (
     <View style={styles.container}>
+
      <SafeAreaView style={styles.container}>
       <Text style={[styles.header, styles.paragraph]}>React Native Systrace API</Text>
+
        <Text style={[styles.header, styles.paragraph]}>React Native Systrace API</Text>
       <Button title="Capture the non-Timed JS events in EasyProfiler" onPress={()=> this.enableProfiling()}/>
+
      <View style={styles.buttonRow}>
       <Button title="Stop capturing" onPress={()=> this.stopProfiling()} color="#FF0000"/>
+
        <Button title="Capture the non-Timed JS events in EasyProfiler" onPress={()=> this.enableProfiling()}/>
     </View>
+
        <Button title="Stop capturing" onPress={()=> this.stopProfiling()} color="#FF0000"/>
   );
+
      </View>
 +
      </SafeAreaView>
 +
    );
 
   }
 
   }
 
}
 
}
+
 
 
const styles = StyleSheet.create({
 
const styles = StyleSheet.create({
 container: {
+
  container: {
   flex: 1,
+
    flex: 1,
   backgroundColor: '#fff',
+
    backgroundColor: '#fff',
   alignItems: 'center',
+
    alignItems: 'center',
   justifyContent: 'center',
+
    justifyContent: 'center',
   paddingTop: 44,
+
    paddingTop: 44,
   padding: 8
+
    padding: 8
 
   },
 
   },
  header: {
+
  header: {
   fontSize: 18,
+
    fontSize: 18,
   fontWeight: "bold",
+
    fontWeight: "bold",
   textAlign: "center"
+
    textAlign: "center"
 
   },
 
   },
 paragraph: {
+
  paragraph: {
   margin: 24,
+
    margin: 24,
   textAlign: "center"
+
    fontSize: 25,
 +
    textAlign: "center"
 +
  },
 +
  buttonRow: {
 +
    flexBasis: 150,
 +
    marginVertical: 16,
 +
    justifyContent: 'space-evenly'
 
   }
 
   }
 
});
 
});
+
 
 
export default App;
 
export default App;
 
</syntaxhighlight>
 
</syntaxhighlight>
سطر 108: سطر 123:
 
== التوابع ==
 
== التوابع ==
  
=== <code>installReactHook()‎</code> ===
+
=== <code>installReactHook()‎</code> ===  
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
static installReactHook(useFiber)
 
static installReactHook(useFiber)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== <code>setEnabled()</code> ===
+
=== <code>setEnabled()</code> ===
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
static setEnabled(enabled)
 
static setEnabled(enabled)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== <code>isEnabled()</code> ===
+
=== <code>isEnabled()</code> ===
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
static isEnabled()
 
static isEnabled()
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== <code>beginEvent()‎</code> ===
+
=== <code>beginEvent()‎</code> ===
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
static beginEvent(profileName?, args?)
 
static beginEvent(profileName?, args?)
 
</syntaxhighlight>يُستخدم هذا التابع لبدء التشخيص.
 
</syntaxhighlight>يُستخدم هذا التابع لبدء التشخيص.
  
=== <code>endEvent()</code> ===
+
=== <code>endEvent()</code> ===
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
static endEvent()
 
static endEvent()
 
</syntaxhighlight>يُستخدم هذا التابع لإنهاء التشخيص، ويطلب بعد بدء التابع <code>()beginEvent</code> التشخيص ضمن إطار مكدس الاستدعاءات.
 
</syntaxhighlight>يُستخدم هذا التابع لإنهاء التشخيص، ويطلب بعد بدء التابع <code>()beginEvent</code> التشخيص ضمن إطار مكدس الاستدعاءات.
  
=== <code>beginAsyncEvent()</code> ===
+
=== <code>beginAsyncEvent()</code> ===
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
static beginAsyncEvent(profileName?)
 
static beginAsyncEvent(profileName?)
 
</syntaxhighlight>يُستخدم التابع ‎‏<code>()beginAsyncEvent</code> لبدء التشخيص ثم يقوم التابع <code>()endAsyncEvent</code> بإنهائه، ويمكن أن يحصل الإنهاء ضمن عمليّةٍ (thread) أخرى أو خارج إطار مكدس الاستدعاءات، مثل انتظار إعادة قيمة المتغير cookie المستخدم كدخل في استدعاء تابع الإنهاء <code>()endAsyncEvent</code>.
 
</syntaxhighlight>يُستخدم التابع ‎‏<code>()beginAsyncEvent</code> لبدء التشخيص ثم يقوم التابع <code>()endAsyncEvent</code> بإنهائه، ويمكن أن يحصل الإنهاء ضمن عمليّةٍ (thread) أخرى أو خارج إطار مكدس الاستدعاءات، مثل انتظار إعادة قيمة المتغير cookie المستخدم كدخل في استدعاء تابع الإنهاء <code>()endAsyncEvent</code>.
  
=== <code>endAsyncEvent()</code> ===
+
=== <code>endAsyncEvent()</code> ===
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
static endAsyncEvent(profileName?, cookie?)
 
static endAsyncEvent(profileName?, cookie?)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== <code>counterEvent()</code> ===
+
=== <code>counterEvent()</code> ===
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
 
static counterEvent(profileName?, value?)
 
static counterEvent(profileName?, value?)
سطر 152: سطر 167:
 
* [https://facebook.github.io/react-native/docs/systrace صفحة Systrace في توثيق React Native الرسميّ]
 
* [https://facebook.github.io/react-native/docs/systrace صفحة Systrace في توثيق React Native الرسميّ]
 
[[تصنيف:ReactNative]]
 
[[تصنيف:ReactNative]]
 +
[[تصنيف:React Native API]]

المراجعة الحالية بتاريخ 14:13، 9 أكتوبر 2021

إن Systrace هي أداة تعريف الأداء، تعتمد على العلامات (marker-based profiling tool) المعيارية لمنصة Android، وتُثبّت مع حزمة أدوات منصّة Android. تُحاط كتل الشفرة البرمجيّة المشخَّصة بوسوم البداية، والنهاية فتظهر على شكل مخططٍ ملوَّنٍ، وتحوي كل من Android SDK، و React Native على الوسوم المعيارية التي يمكن إظهارها.

مثال

تسمح Systrace بوسمٍ أحداث ‎‎‏JavaScript بوسمٍ، وبقيمةٍ صحيحةٍ، وهذا المثال لالتقاط أحداث JS غير المرتبطة بالزمن (non-Timed) ضمن EasyProfiler.

import React from "react";
import { Button, Text, View, SafeAreaView, StyleSheet, Systrace } from "react-native";

const App = () =>  {

  const enableProfiling = () => {
    Systrace.setEnabled(true); // Call setEnabled to turn on the profiling.
    Systrace.beginEvent('event_label')
    Systrace.counterEvent('event_label', 10);
  }

  const stopProfiling = () => {
    Systrace.endEvent()
  }

  return (
    <SafeAreaView style={styles.container}>
      <Text style={[styles.header, styles.paragraph]}>React Native Systrace API</Text>
    <View style={styles.buttonRow}>
      <Button title="Capture the non-Timed JS events in EasyProfiler" onPress={()=> enableProfiling()}/>
      <Button title="Stop capturing" onPress={()=> stopProfiling()} color="#FF0000"/>
    </View>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: 44,
    padding: 8
  },
   header: {
    fontSize: 18,
    fontWeight: "bold",
    textAlign: "center"
  },
  paragraph: {
    margin: 24,
    fontSize: 25,
    textAlign: "center"
  },
  buttonRow: {
    flexBasis: 150,
    marginVertical: 16,
    justifyContent: 'space-evenly'
  }
});

export default App;
import React, { Component } from "react";
import { Button, Text, View, SafeAreaView, StyleSheet, Systrace } from "react-native";

class App extends Component {

  enableProfiling = () => {
    Systrace.setEnabled(true); // Call setEnabled to turn on the profiling.
    Systrace.beginEvent('event_label')
    Systrace.counterEvent('event_label', 10);
  }

  stopProfiling = () => {
    Systrace.endEvent()
  }

  render() {
    return (
      <SafeAreaView style={styles.container}>
        <Text style={[styles.header, styles.paragraph]}>React Native Systrace API</Text>
      <View style={styles.buttonRow}>
        <Button title="Capture the non-Timed JS events in EasyProfiler" onPress={()=> this.enableProfiling()}/>
        <Button title="Stop capturing" onPress={()=> this.stopProfiling()} color="#FF0000"/>
      </View>
      </SafeAreaView>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: 44,
    padding: 8
  },
   header: {
    fontSize: 18,
    fontWeight: "bold",
    textAlign: "center"
  },
  paragraph: {
    margin: 24,
    fontSize: 25,
    textAlign: "center"
  },
  buttonRow: {
    flexBasis: 150,
    marginVertical: 16,
    justifyContent: 'space-evenly'
  }
});

export default App;

التوابع

installReactHook()‎

static installReactHook(useFiber)

setEnabled()‎

static setEnabled(enabled)

isEnabled()‎

static isEnabled()

beginEvent()‎

static beginEvent(profileName?, args?)

يُستخدم هذا التابع لبدء التشخيص.

endEvent()‎

static endEvent()

يُستخدم هذا التابع لإنهاء التشخيص، ويطلب بعد بدء التابع ()beginEvent التشخيص ضمن إطار مكدس الاستدعاءات.

beginAsyncEvent()‎

static beginAsyncEvent(profileName?)

يُستخدم التابع ‎‏()beginAsyncEvent لبدء التشخيص ثم يقوم التابع ()endAsyncEvent بإنهائه، ويمكن أن يحصل الإنهاء ضمن عمليّةٍ (thread) أخرى أو خارج إطار مكدس الاستدعاءات، مثل انتظار إعادة قيمة المتغير cookie المستخدم كدخل في استدعاء تابع الإنهاء ()endAsyncEvent.

endAsyncEvent()‎

static endAsyncEvent(profileName?, cookie?)

counterEvent()‎

static counterEvent(profileName?, value?)

يُستخدم هذا التّابع لتسجيل قيمة المتغيّر profileName ضمن الخطّ الزمني Systrace.

مصادر