Skip to content
Permalink
Browse files

Added perf markers

  • Loading branch information...
axemclion committed Jul 9, 2019
1 parent 1105b27 commit e9058e805d0bc4f79c314aef2277d73670249c6f
@@ -3,6 +3,9 @@
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.util.Log;

import androidx.annotation.NonNull;
@@ -16,6 +19,7 @@
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.soloader.SoLoader;
@@ -48,6 +52,7 @@
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@@ -112,6 +117,7 @@ public String getJSMainModuleName() {
@Override
public void onCreate() {
super.onCreate();
APP_START_TIME = System.currentTimeMillis();
instance = this;

// Delete any previous temp files created by the app
@@ -126,8 +132,9 @@ public void onCreate() {

SoLoader.init(this, /* native exopackage */ false);

addTraceMarkers();
// Uncomment to listen to react markers for build that has telemetry enabled
// addReactMarkerListener();
//addReactMarkerListener();
}

@Override
@@ -153,6 +160,52 @@ public IPushNotificationsDrawer getPushNotificationsDrawer(Context context, AppL
return new CustomPushNotificationDrawer(context, defaultAppLaunchHelper);
}

private List<Bundle> mPerfMarkers = new ArrayList<>();

private void addTraceMarkers() {
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
WritableMap result = Arguments.createMap();
result.putDouble("startTime", APP_START_TIME);
WritableArray data = Arguments.createArray();
for (Bundle r : mPerfMarkers) {
WritableMap m = Arguments.createMap();
m.putDouble("time", r.getDouble("time"));
m.putString("name", r.getString("name"));
m.putString("tab", r.getString("tag"));
m.putInt("instanceKey", r.getInt("instanceKey"));
m.putInt("pid", r.getInt("pid"));
m.putInt("tid", r.getInt("tid"));
data.pushMap(m);
}

result.putArray("data", data);

ReactContext ctx = getReactGateway().getReactContext();
if (ctx != null) {
ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).
emit("perfMetrics", result);
}
}
}, 1000 * 15);

ReactMarker.addListener(new ReactMarker.MarkerListener() {
@Override
public void logMarker(ReactMarkerConstants name, @javax.annotation.Nullable String tag, int instanceKey) {
Bundle record = new Bundle();
record.putDouble("time", System.currentTimeMillis());
record.putString("name", name.toString());
record.putString("tag", tag);
record.putInt("instanceKey", instanceKey);
record.putInt("pid", Process.myPid());
record.putInt("tid", Process.myTid());

mPerfMarkers.add(record);
}
});
}

private void addReactMarkerListener() {
ReactMarker.addListener(new ReactMarker.MarkerListener() {
@Override
@@ -19,7 +19,7 @@ import ChannelMention from './channel_mention';
import EmojiSuggestion from './emoji_suggestion';
import SlashSuggestion from './slash_suggestion';
import DateSuggestion from './date_suggestion';

import loggerComponent from 'perf';
export default class Autocomplete extends PureComponent {
static propTypes = {
cursorPosition: PropTypes.number,
@@ -181,7 +181,7 @@ export default class Autocomplete extends PureComponent {

const maxListHeight = this.maxListHeight();

return (
return loggerComponent("autocomplete",
<View style={wrapperStyle}>
<View style={containerStyle}>
<AtMention
@@ -11,6 +11,7 @@ import {t} from 'app/utils/i18n';
import {alertErrorWithFallback} from 'app/utils/general';

import {getChannelFromChannelName} from './channel_link_utils';
import loggerComponent from 'perf';

export default class ChannelLink extends React.PureComponent {
static propTypes = {
@@ -93,7 +94,7 @@ export default class ChannelLink extends React.PureComponent {
suffix = this.props.channelName.substring(channel.name.length);
}

return (
return loggerComponent("channel_link",
<Text style={this.props.textStyle}>
<Text
style={this.props.linkStyle}
@@ -13,6 +13,7 @@ import EventEmitter from 'mattermost-redux/utils/event_emitter';

import CustomPropTypes from 'app/constants/custom_prop_types';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
import loggerComponent from 'perf';

function calculateMaxRows(height) {
return Math.round(height / 100);
@@ -129,7 +130,7 @@ export default class ChannelLoader extends PureComponent {
const style = getStyleSheet(theme);
const bg = this.props.backgroundColor || theme.centerChannelBg;

return (
return loggerComponent("channel_loader",
<View
style={[style.container, styleProp, {backgroundColor: bg}]}
onLayout={this.handleLayout}
@@ -12,6 +12,7 @@ import {

import CustomPropTypes from 'app/constants/custom_prop_types';
import ImageCacheManager from 'app/utils/image_cache_manager';
import loggerComponent from 'perf';

export default class Emoji extends React.PureComponent {
static propTypes = {
@@ -125,7 +126,7 @@ export default class Emoji extends React.PureComponent {
);
}

return (
return loggerComponent("emoji",
<Image
key={key}
style={{width, height}}
@@ -28,6 +28,7 @@ import {emptyFunction} from 'app/utils/general';
import {makeStyleSheetFromTheme, changeOpacity} from 'app/utils/theme';

import EmojiPickerRow from './emoji_picker_row';
import loggerComponent from 'perf';

const EMOJI_SIZE = 30;
const EMOJI_GUTTER = 7.5;
@@ -452,7 +453,7 @@ export default class EmojiPicker extends PureComponent {
}),
};

return (
return loggerComponent("emoji_picker",
<SafeAreaView excludeHeader={true}>
<KeyboardAvoidingView
behavior='padding'
@@ -36,6 +36,7 @@ import {
highlightMentions,
pullOutImages,
} from './transform';
import loggerComponent from 'perf';

export default class Markdown extends PureComponent {
static propTypes = {
@@ -443,7 +444,7 @@ export default class Markdown extends PureComponent {
}
}

return this.renderer.render(ast);
return loggerComponent("markdown", this.renderer.render(ast));
}
}

@@ -16,6 +16,7 @@ import AttachmentPreText from './attachment_pretext';
import AttachmentText from './attachment_text';
import AttachmentThumbnail from './attachment_thumbnail';
import AttachmentTitle from './attachment_title';
import loggerComponent from 'perf';

const STATUS_COLORS = {
good: '#00c100',
@@ -64,7 +65,7 @@ export default class MessageAttachment extends PureComponent {
}
}

return (
return loggerComponent("message_attachment",
<React.Fragment>
<AttachmentPreText
baseTextStyle={baseTextStyle}
@@ -24,6 +24,7 @@ import networkConnectionListener, {checkConnection} from 'app/utils/network';
import {t} from 'app/utils/i18n';

import {RequestStatus} from 'mattermost-redux/constants';
import loggerComponent from 'perf';

const HEIGHT = 38;
const MAX_WEBSOCKET_RETRIES = 3;
@@ -387,7 +388,7 @@ export default class NetworkIndicator extends PureComponent {
defaultMessage = 'No internet connection';
}

return (
return loggerComponent("network_indicator",
<Animated.View style={[styles.container, {top: this.top, backgroundColor: background, opacity: this.state.opacity}]}>
<Animated.View style={styles.wrapper}>
<FormattedText
@@ -11,6 +11,7 @@ import {
ViewPropTypes,
} from 'react-native';
import {intlShape} from 'react-intl';
import loggerComponent from 'perf';

import PostBody from 'app/components/post_body';
import PostHeader from 'app/components/post_header';
@@ -325,7 +326,7 @@ export default class Post extends PureComponent {
const replyBarStyle = this.replyBarStyle();
const rightColumnStyle = [style.rightColumn, (commentedOnPost && isLastReply && style.rightColumnPadding)];

return (
return loggerComponent("post",
<TouchableHighlight
style={[style.postStyle, highlighted]}
onPress={this.handlePress}
@@ -24,6 +24,7 @@ import {emptyFunction} from 'app/utils/general';
import {getMarkdownTextStyles, getMarkdownBlockStyles} from 'app/utils/markdown';
import {preventDoubleTap} from 'app/utils/tap';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
import loggerComponent from 'perf';

import telemetry from 'app/telemetry';

@@ -460,7 +461,7 @@ export default class PostBody extends PureComponent {
);
}

return (
return loggerComponent("post_body",
<View style={style.messageContainerWithReplyBar}>
<View style={replyBarStyle}/>
{body}
@@ -17,6 +17,7 @@ import ReplyIcon from 'app/components/reply_icon';
import BotTag from 'app/components/bot_tag';
import {emptyFunction} from 'app/utils/general';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
import loggerComponent from 'perf.js'

export default class PostHeader extends PureComponent {
static propTypes = {
@@ -225,7 +226,7 @@ export default class PostHeader extends PureComponent {
);
}

return (
return loggerComponent("post_header",
<React.Fragment>
<View style={[style.postInfoContainer, (isPendingOrFailedPost && style.pendingPost)]}>
<View style={{flexDirection: 'row', flex: 1}}>
@@ -19,6 +19,7 @@ import telemetry from 'app/telemetry';

import DateHeader from './date_header';
import NewMessagesDivider from './new_messages_divider';
import loggerComponent from 'perf';

const INITIAL_BATCH_TO_RENDER = 15;
const SCROLL_UP_MULTIPLIER = 3.5;
@@ -350,7 +351,7 @@ export default class PostList extends PureComponent {

const hasPostsKey = postIds.length ? 'true' : 'false';

return (
return loggerComponent("post_list",
<FlatList
key={`recyclerFor-${channelId}-${hasPostsKey}`}
ref={this.flatListRef}
@@ -8,6 +8,7 @@ import FileUploadPreview from 'app/components/file_upload_preview';

import Typing from './components/typing';
import PostTextBoxBase from './post_textbox_base';
import loggerComponent from 'perf';

const AUTOCOMPLETE_MARGIN = 20;
const AUTOCOMPLETE_MAX_HEIGHT = 200;
@@ -26,7 +27,7 @@ export default class PostTextBoxAndroid extends PostTextBoxBase {

const {cursorPosition, top} = this.state;

return (
return loggerComponent("post_textbox",
<React.Fragment>
<Typing/>
<FileUploadPreview
@@ -14,6 +14,7 @@ import {emptyFunction} from 'app/utils/general';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';

import placeholder from 'assets/images/profile.jpg';
import loggerComponent from 'perf';

const STATUS_BUFFER = Platform.select({
ios: 3,
@@ -169,7 +170,7 @@ export default class ProfilePicture extends PureComponent {
);
}

return (
return loggerComponent("profile_pic",
<View style={{width: this.props.size + STATUS_BUFFER, height: this.props.size + STATUS_BUFFER}}>
{image}
{(showStatus || edit) && (user && !user.is_bot) &&
@@ -11,6 +11,7 @@ import EventEmitter from 'mattermost-redux/utils/event_emitter';

import {NavigationTypes, ViewTypes} from 'app/constants';
import {getTranslations} from 'app/i18n';
import loggerComponent from 'perf';

export default class Root extends PureComponent {
static propTypes = {
@@ -146,7 +147,7 @@ export default class Root extends PureComponent {
render() {
const locale = this.props.locale;

return (
return loggerComponent("root",
<IntlProvider
ref={i => this._providerRef = i}
locale={locale}
@@ -11,6 +11,8 @@ import {
View,
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import logComponentPerf from 'perf';


import CustomPropTypes from 'app/constants/custom_prop_types';
import {changeOpacity} from 'app/utils/theme';
@@ -167,7 +169,7 @@ export default class SearchBarAndroid extends PureComponent {
inputNoBackground.backgroundColor = '#fff';
}

return (
return logComponentPerf("SearchBar",
<View
style={[
styles.container,
@@ -16,6 +16,7 @@ import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';

import List from './list';
import SwitchTeamsButton from './switch_teams_button';
import logComponentPerf from 'perf';

const {ANDROID_TOP_PORTRAIT} = ViewTypes;
let FilteredList = null;
@@ -160,9 +161,9 @@ export default class ChannelsList extends PureComponent {
style={styles.container}
>
<View style={styles.headerContainer}>
{title}
{logComponentPerf("Title", title)}
</View>
{list}
{logComponentPerf("list", list)}
</View>
);
}

0 comments on commit e9058e8

Please sign in to comment.
You can’t perform that action at this time.