Coder Social home page Coder Social logo

watched's Introduction

1, How to use it

In root build.gradle:

allprojects {
    repositories {
        google()
        jcenter()

        maven { url 'https://jitpack.io' }
    }
}

In your app build.gradle:

 dependencies {
    debugImplementation 'com.github.vzhilong.watched:watched:0.1.0'
    releaseImplementation 'com.github.vzhilong.watched:watched_noop:0.1.0'
    testImplementation 'com.github.vzhilong.watched:watched_noop:0.1.0'
 }

In your HiApplication class:

class HiApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        if (getCurProcessName() == packageName) {
            Watched.init(this, arrayOf("com.vincent.watched.demo:service", "com.vincent.watched.demo"), interval = 500L)
        }
    }

    /**
     * get current process name
     *
     * @return
     */
    fun getCurProcessName(): String {
        var cmdlineReader: BufferedReader? = null
        try {
            cmdlineReader = BufferedReader(
                InputStreamReader(
                    FileInputStream("/proc/" + Process.myPid() + "/cmdline"), "iso-8859-1"
                )
            )
            var c: Int
            val processName = StringBuilder()
            while (true) {
                c = cmdlineReader.read()
                if (c <= 0) {
                    break
                }
                processName.append(c.toChar())
            }
            return processName.toString()
        } catch (e: IOException) {

        } finally {
            if (cmdlineReader != null) {
                try {
                    cmdlineReader.close()
                } catch (e: Throwable) {
                    e.printStackTrace()
                }
            }
        }

        return ""
    }
}

2, About watched

Usually we monitor our process's memory usage(java heap, native heap, graphics, stack, code and others) by Profiler, like this:

profiler sample

Now we can get the same result on the phone(java heap, native heap, graphics, stack, code, but others not include):

watched sample dialog config

watched's People

Contributors

vzhilong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.