Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: RAM debug message #551

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion android/app/src/main/java/com/noxplay/noxplayer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.noxplay.noxplayer

import android.annotation.SuppressLint
import android.app.PictureInPictureParams
import android.content.ComponentCallbacks2
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.os.Debug
import android.util.Rational
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
Expand All @@ -16,7 +18,7 @@ import com.facebook.react.bridge.Arguments
import expo.modules.ReactActivityDelegateWrapper
import timber.log.Timber

class MainActivity : ReactActivity() {
class MainActivity : ReactActivity(), ComponentCallbacks2 {
/**
* for react navigation;
*/
Expand Down Expand Up @@ -127,4 +129,24 @@ class MainActivity : ReactActivity() {
}
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
}

private fun logAPMRAM() {
val nativeHeapSize = Debug.getNativeHeapSize()
val nativeHeapFreeSize = Debug.getNativeHeapFreeSize()
val usedMemInBytes = nativeHeapSize - nativeHeapFreeSize
val usedMemInPercentage = usedMemInBytes * 100 / nativeHeapSize
Timber.tag("APMRAM").d("APM RAM usage: $usedMemInBytes/1000/1000 ($usedMemInPercentage)")
}

override fun onTrimMemory(level: Int) {
Timber.tag("APMRAMTrim").d("trim memory level $level emitted.")
logAPMRAM()
super.onTrimMemory(level)
}

override fun onLowMemory() {
Timber.tag("APMRAMLow").d("low system memory emitted.")
logAPMRAM()
super.onLowMemory()
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
"fflate": "^0.8.2",
"ffmpeg-kit-react-native": "^6.0.2",
"he": "^1.2.0",
"i18next": "^23.14.0",
"i18next": "^23.15.0",
"js-base64": "^3.7.7",
"libmuse": "https://github.com/lovegaoshi/muse.git#commit=9771b28a8da32df84ca09b5b0226dff530c4c7bc",
"lottie-react-native": "6.7.2",
"lru-cache": "7.14.0",
"md5": "^2.3.0",
"metro": "^0.80.11",
"metro": "^0.80.12",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"qs": "^6.13.0",
Expand Down Expand Up @@ -107,7 +107,7 @@
"react-native-url-polyfill": "^2.0.0",
"react-native-vector-icons": "^10.1.0",
"react-native-video": "^6.5.0",
"react-native-webview": "13.12.1",
"react-native-webview": "13.12.2",
"sp-react-native-in-app-updates": "^1.4.0",
"text-encoding-polyfill": "^0.6.7",
"use-debounce": "^10.0.3",
Expand Down Expand Up @@ -169,7 +169,7 @@
"react-test-renderer": "18.3.1",
"reactotron-react-native": "^5.1.8",
"rimraf": "^6.0.1",
"typescript": "~5.5.4"
"typescript": "~5.6.2"
},
"engines": {
"node": ">=18.0.0"
Expand Down
13 changes: 11 additions & 2 deletions src/components/commonui/AutoComplete.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { View, GestureResponderEvent, StyleSheet } from 'react-native';
import { Menu, Searchbar } from 'react-native-paper';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import { useDebounce } from 'use-debounce';
import { v4 as uuidv4 } from 'uuid';

import { useNoxSetting } from '@stores/useApp';

Expand All @@ -26,6 +27,7 @@ export default ({
resolveData,
pressed,
}: Props) => {
const autoCompleteId = useRef('');
const [debouncedValue] = useDebounce(value, 250);
const [showAutoComplete, setShowAutoComplete] = useState(false);
const [data, setData] = useState<string[]>([]);
Expand All @@ -49,7 +51,14 @@ export default ({
pressed.current = false;
return;
}
resolveData?.(debouncedValue).then(setData);
const newId = uuidv4();
autoCompleteId.current = newId;
resolveData?.(debouncedValue).then(data => {
if (autoCompleteId.current !== newId) {
return;
}
setData(data);
});
setShowAutoComplete(true);
}, [debouncedValue]);

Expand Down
23 changes: 1 addition & 22 deletions src/utils/mediafetch/ytbPlaylist.muse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,7 @@ import { fetchAudioInfo } from '@utils/mediafetch/ytbvideo';
import SongTS from '@objects/Song';
import { logger } from '../Logger';
import { Source } from '@enums/MediaFetch';

const musePlaylistItemToNoxSong = (val: any, data: any) => {
try {
return SongTS({
cid: `${Source.ytbvideo}-${val.videoId}`,
bvid: val.videoId,
name: val.title,
nameRaw: val.title,
singer: val.artists[0].name,
singerId: val.artists[0].id,
cover: val.thumbnails[val.thumbnails.length - 1].url,
lyric: '',
page: 1,
duration: val.duration_seconds,
album: data.title,
source: Source.ytbvideo,
metadataOnLoad: true,
});
} catch {
console.error(`[musePlaylistParse] fail: ${JSON.stringify(val)}`);
}
};
import { musePlaylistItemToNoxSong } from './ytbSearch.muse';

export const fetchYtmPlaylist = async (
playlistId: string,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/mediafetch/ytbSearch.muse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SongTS from '@objects/Song';
import { Source } from '@enums/MediaFetch';
import { logger } from '@utils/Logger';

const musePlaylistItemToNoxSong = (val: any, data: any) => {
export const musePlaylistItemToNoxSong = (val: any, data: any) => {
try {
return SongTS({
cid: `${Source.ytbvideo}-${val.videoId}`,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/mediafetch/ytbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ytClient: Promise<Innertube> = Innertube.create({
export default ytClient;

export const ytClientWeb: Promise<Innertube> = Innertube.create({
retrieve_player: true,
retrieve_player: false,
enable_session_cache: false,
generate_session_locally: false,
});
Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7133,14 +7133,14 @@ __metadata:
ffmpeg-kit-react-native: "npm:^6.0.2"
gts: "npm:^5.3.1"
he: "npm:^1.2.0"
i18next: "npm:^23.14.0"
i18next: "npm:^23.15.0"
jest: "npm:^29.7.0"
js-base64: "npm:^3.7.7"
libmuse: "https://github.com/lovegaoshi/muse.git#commit=9771b28a8da32df84ca09b5b0226dff530c4c7bc"
lottie-react-native: "npm:6.7.2"
lru-cache: "npm:7.14.0"
md5: "npm:^2.3.0"
metro: "npm:^0.80.11"
metro: "npm:^0.80.12"
metro-react-native-babel-preset: "npm:0.77.0"
patch-package: "npm:^8.0.0"
postinstall-postinstall: "npm:^2.1.0"
Expand Down Expand Up @@ -7178,13 +7178,13 @@ __metadata:
react-native-url-polyfill: "npm:^2.0.0"
react-native-vector-icons: "npm:^10.1.0"
react-native-video: "npm:^6.5.0"
react-native-webview: "npm:13.12.1"
react-native-webview: "npm:13.12.2"
react-test-renderer: "npm:18.3.1"
reactotron-react-native: "npm:^5.1.8"
rimraf: "npm:^6.0.1"
sp-react-native-in-app-updates: "npm:^1.4.0"
text-encoding-polyfill: "npm:^0.6.7"
typescript: "npm:~5.5.4"
typescript: "npm:~5.6.2"
use-debounce: "npm:^10.0.3"
uuid: "npm:^10.0.0"
web-streams-polyfill: "npm:^4.0.0"
Expand Down Expand Up @@ -11845,12 +11845,12 @@ __metadata:
languageName: node
linkType: hard

"i18next@npm:^23.14.0":
version: 23.14.0
resolution: "i18next@npm:23.14.0"
"i18next@npm:^23.15.0":
version: 23.15.0
resolution: "i18next@npm:23.15.0"
dependencies:
"@babel/runtime": "npm:^7.23.2"
checksum: 10c0/c26638a816e6213e515c158b17894ca3c54693911e1dc637cd279e11d53f8ded2494c3dcc6e2e94c639987ef63718193a1e2b4f3d5873fbcf89f266582140cd5
checksum: 10c0/0ccda93fbdb41f23e773df537f4467cccabff43aaba8c1ba617e6776a2f5e5952262870974ba7922eb8fc70f21262614c58c8b5d17998f4c749ca0f99f57b9db
languageName: node
linkType: hard

Expand Down Expand Up @@ -16504,16 +16504,16 @@ __metadata:
languageName: node
linkType: hard

"react-native-webview@npm:13.12.1":
version: 13.12.1
resolution: "react-native-webview@npm:13.12.1"
"react-native-webview@npm:13.12.2":
version: 13.12.2
resolution: "react-native-webview@npm:13.12.2"
dependencies:
escape-string-regexp: "npm:^4.0.0"
invariant: "npm:2.2.4"
peerDependencies:
react: "*"
react-native: "*"
checksum: 10c0/b7513cde5bc7ae10c302acacbba92a9336923f9a794b62dd53da19733943c3aef787309575e334c1467a3adcb70b8bce59b12bd0075ca5f4508f776a96b2f410
checksum: 10c0/f10921205b6c140bc87f7fbc65547243598653bd37c5aded2c17414774fb4ba4bbf23a5c13bf9180ccecd78c5f581aaa5a97127754bb6cc603611bea5744db79
languageName: node
linkType: hard

Expand Down Expand Up @@ -18802,13 +18802,13 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:~5.5.4":
version: 5.5.4
resolution: "typescript@npm:5.5.4"
"typescript@npm:~5.6.2":
version: 5.6.2
resolution: "typescript@npm:5.6.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/422be60f89e661eab29ac488c974b6cc0a660fb2228003b297c3d10c32c90f3bcffc1009b43876a082515a3c376b1eefcce823d6e78982e6878408b9a923199c
checksum: 10c0/3ed8297a8c7c56b7fec282532503d1ac795239d06e7c4966b42d4330c6cf433a170b53bcf93a130a7f14ccc5235de5560df4f1045eb7f3550b46ebed16d3c5e5
languageName: node
linkType: hard

Expand All @@ -18822,13 +18822,13 @@ __metadata:
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A~5.5.4#optional!builtin<compat/typescript>":
version: 5.5.4
resolution: "typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>::version=5.5.4&hash=379a07"
"typescript@patch:typescript@npm%3A~5.6.2#optional!builtin<compat/typescript>":
version: 5.6.2
resolution: "typescript@patch:typescript@npm%3A5.6.2#optional!builtin<compat/typescript>::version=5.6.2&hash=8c6c40"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/73409d7b9196a5a1217b3aaad929bf76294d3ce7d6e9766dd880ece296ee91cf7d7db6b16c6c6c630ee5096eccde726c0ef17c7dfa52b01a243e57ae1f09ef07
checksum: 10c0/94eb47e130d3edd964b76da85975601dcb3604b0c848a36f63ac448d0104e93819d94c8bdf6b07c00120f2ce9c05256b8b6092d23cf5cf1c6fa911159e4d572f
languageName: node
linkType: hard

Expand Down