Skip to content

Scope Inspection

Sergej Shafarenka edited this page Jul 11, 2019 · 4 revisions

Magnet comes with a magnetx-app-stetho-scope (stetho-scope for short) extension capable of dumping current scope tree starting from the root scope. This gives developers a good overview over how magnet allocates instances. It is implemented as a Stetho dumpapp plugin and thus can be used via command line interface.

Scope dumping in available starting from 3.3-rc4.

Configuring

If you already use magnetx-app extension you can activate stetho-scope in debug builds by adding following dependencies to your app/build.gradle:

dependencies {
    debugImplementation 'com.facebook.stetho:stetho:1.5.1'
    debugImplementation 'de.halfbit:magnetx-app-stetho-scope:3.3-rc4'
}

This is all configuration needed. As usual with Magnet, no code changes are required. Rebuild your app and jump to the next section to learn how to dump scopes. If you don't use magnetx-app extension yet, start using it or copy-paste-modify magnex-app-stetho-scope module on your own.

Dumping

git clone git@github.com:facebook/stetho.git, goto stetho/scripts and find dumpapp script there. It is a python script, so make sure python is installed on your machine. Launch your application on emulator or on a real device and run ./dumpapp magnet scope command. If everything is configured right a scope dump similar to the one down below will be printed to the console.

Example scope dump:

 [1] magnet.internal.MagnetScope@bbf4e4a
    BOUND Application de.halfbit.a3.A3App@18b11bb
    BOUND ContentResolver android.app.ContextImpl$ApplicationContentResolver@93fb6d8
    BOUND android.content.Context@application de.halfbit.a3.A3App@18b11bb
    BOUND android.content.res.Resources@application android.content.res.HwResources@ce6da31
    TOPMOST MainPageProvider de.halfbit.a3.catalog.CatalogPageProvider@7ac0516
    TOPMOST MediaPermissions de.halfbit.a3.catalog.device.commons.permissions.DefaultMediaPermissions@2cf0e97
    TOPMOST CharsetCorrector de.halfbit.a3.catalog.device.commons.scanner.DefaultCharsetCorrector@8656884
    TOPMOST DeviceScanner de.halfbit.a3.catalog.device.commons.scanner.DefaultDeviceMediaScanner@31de86d
    TOPMOST ResolverAlbumScanner de.halfbit.a3.catalog.device.commons.scanner.resolvers.ResolverAlbumScanner@1db5ca2
    TOPMOST ResolverMediaScanner de.halfbit.a3.catalog.device.commons.scanner.resolvers.ResolverMediaScanner@7ebfd33
    TOPMOST A3Database de.halfbit.a3.database.A3Database_Impl@f1288f0
    TOPMOST AssetDao de.halfbit.a3.database.asset.AssetDao_Impl@a3d9e69
    TOPMOST Eventus de.halfbit.commons.eventus.DefaultEventus@b6a0ee
    TOPMOST Delegate magnetx.AppExtension$Delegate@8df398f
    [2] magnet.internal.MagnetScope@f4da172
       BOUND Context de.halfbit.a3.MainActivity@ccea7de
       BOUND Resources android.content.res.HwResources@b6aa9c3
       BOUND LayoutInflater com.android.internal.policy.HwPhoneLayoutInflater@bf5e240
       BOUND FragmentActivity de.halfbit.a3.MainActivity@ccea7de
       BOUND FragmentManager FragmentManager{210579 in HostCallbacks{25062be}}
       BOUND LifecycleOwner de.halfbit.a3.MainActivity@ccea7de
       TOPMOST Salvador de.halfbit.glide.SalvadorGlide@7441f1f
       [3] magnet.internal.MagnetScope@a76e26c
          BOUND View androidx.constraintlayout.motion.widget.MotionLayout{9238035 V.E...... ........ 0,0-1080,1810 #7f080057 app:id/catalogContainer}
          BOUND Fragment CatalogFragment{32becca (4c7d4a7e-5add-4bab-b37d-80795129aaf8) id=0x7f0800c0}
          BOUND FragmentManager FragmentManager{a158e3b in CatalogFragment{32becca}}
          BOUND LifecycleOwner CatalogFragment{32becca (4c7d4a7e-5add-4bab-b37d-80795129aaf8) id=0x7f0800c0}
          TOPMOST CatalogView de.halfbit.a3.catalog.DefaultCatalogView@925b958
          TOPMOST CatalogViewBinder de.halfbit.a3.catalog.DefaultCatalogViewBinder@598eab1
          [4] <device> magnet.internal.MagnetScope@f840b96
             BOUND View androidx.swiperefreshlayout.widget.SwipeRefreshLayout{2c4d317 V.ED..... ........ 0,0-1080,1516}
             BOUND Fragment DeviceFragment{e91304 (fccbdfd6-de5c-4758-b847-365531c26443) id=0x7f080160}
             BOUND FragmentManager FragmentManager{2080ed in DeviceFragment{e91304}}
             BOUND LifecycleOwner DeviceFragment{e91304 (fccbdfd6-de5c-4758-b847-365531c26443) id=0x7f080160}
             BOUND BindableViewModelProvider magnetx.lifecycle.FragmentBindableViewModelProvider@96d4b22
             TOPMOST DeviceView de.halfbit.a3.catalog.device.DefaultDeviceView@eb989b3
             TOPMOST DeviceViewBinder de.halfbit.a3.catalog.device.DeviceViewBinder@665b70
             [5] magnet.internal.MagnetScope@4113ee9
                BOUND View androidx.recyclerview.widget.RecyclerView{db8f76e VFED..... .F...... 0,0-1080,1516 #7f0800f6 app:id/recycler}
                BOUND Fragment MediaFragment{8355a26 (763ee605-19ab-484c-a80f-436deb86d829) id=0x7f08007b}
                BOUND FragmentManager FragmentManager{390e0f in MediaFragment{8355a26}}
                BOUND LifecycleOwner MediaFragment{8355a26 (763ee605-19ab-484c-a80f-436deb86d829) id=0x7f08007b}
                TOPMOST MediaView de.halfbit.a3.catalog.device.scenes.media.DefaultMediaView@92dbe9c
                TOPMOST MediaViewBinder de.halfbit.a3.catalog.device.scenes.media.MediaViewBinder@135e0a5
          [4] magnet.internal.MagnetScope@3011c7a
             BOUND View androidx.constraintlayout.widget.ConstraintLayout{e827c2b V.E...... ........ -1080,0-0,1516}
             BOUND Fragment LibraryFragment{3a62888 (fcf56084-edc9-4a2f-80d3-a6f4ce1d34a0) id=0x7f080160}
             BOUND FragmentManager FragmentManager{f48e221 in LibraryFragment{3a62888}}
             BOUND LifecycleOwner LibraryFragment{3a62888 (fcf56084-edc9-4a2f-80d3-a6f4ce1d34a0) id=0x7f080160}
             TOPMOST LibraryView de.halfbit.a3.catalog.library.DefaultLibraryView@d748646
             TOPMOST LibraryViewBinder de.halfbit.a3.catalog.library.LibraryViewBinder@baab007
Clone this wiki locally