Profiler
تتيح لك إضافة profiler قياس أداء دوال JS الخاصة بك والتقاط كل من الوسائط والنتيجة لكل استدعاء.
التثبيت
Section titled التثبيتnpm i @openreplay/tracker-profiler
الاستخدام
Section titled الاستخدامقم بتهيئة المتعقّب (tracker) وحمّل الإضافة داخله. ثم زيّن أي دالة في الكود الخاص بك باستخدام الدالة المُولَّدة.
إذا كان موقعك تطبيق صفحة واحدة (SPA)
Section titled إذا كان موقعك تطبيق صفحة واحدة (SPA)import OpenReplay from '@openreplay/tracker';
import trackerProfiler from '@openreplay/tracker-profiler';
const tracker = new OpenReplay({
projectKey: PROJECT_KEY
});
const profiler = tracker.use(trackerProfiler());
tracker.start();
// ...
const fn = profiler('MyFunction')(() => {
// Inspecting function body
}, thisArg); // thisArg is optional
إذا كان تطبيق الويب الخاص بك يُعرَض من جانب الخادم (SSR)
Section titled إذا كان تطبيق الويب الخاص بك يُعرَض من جانب الخادم (SSR)اتبع المثال أدناه إذا كان تطبيقك يعمل بنظام SSR. تأكد من استدعاء tracker.start() بمجرد بدء تشغيل التطبيق (في useEffect أو componentDidMount).
import OpenReplay from '@openreplay/tracker/cjs';
import trackerProfiler from '@openreplay/tracker-profiler/cjs';
//...
const tracker = new OpenReplay({
projectKey: PROJECT_KEY
});
const profiler = tracker.use(trackerProfiler());
//...
function MyApp() {
useEffect(() => { // use componentDidMount in case of React Class Component
tracker.start();
}, [])
}
//...
const fn = profiler('MyFunction')(() => {
// Inspecting function body
}, thisArg); // thisArg is optional
لديك أسئلة؟
Section titled لديك أسئلة؟هل تواجه صعوبة في إعداد هذه الإضافة؟ يُرجى الانضمام إلى Slack الخاص بنا أو زيارة المنتدى والحصول على المساعدة من مجتمعنا.