Skip to content

Low overhead tracer for Kotlin based applications

Notifications You must be signed in to change notification settings

goncalopalaio/CatTrace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CatTrace

When everything else fails, you can always count with printf() debugging, in this case, printf() profiling.

Creating events

// Setup
CatTrace.setPid(0, name = "Process Name")    
import com.gplio.cattrace.trace

// Emit event with the start and end of a particular method
fun originalMethod(argument: String) = trace(name = "originalMethod", arguments = mapOf("argument" to argument)) {
    // Original body
}
// Instant event
CatTrace.instant("Start", CatTrace.InstantType.Global)
// Complete event
CatTrace.complete("Event that started and ended", startTime, endTime)
// Event
val event = CatTrace.begin("Long Operation")
// Long operation
event.end()
// Counter - Track values across time.
CatTrace.counter("beans", mapOf("value" to i))
// Thread names are continuously collected.
// Call threadMetadata to send a metadata event with their names.
CatTrace.sendThreadMetadata()

Reading events

Pipe the events into the script:

adb -s b8435fb0 logcat -v time | grep --line-buffered -Ei "CatTrace" | python3 cattrace.py

Viewing events

Open the .json file in https://ui.perfetto.dev/

How to include in your project

Follow https://jitpack.io/#goncalopalaio/CatTrace/ and get the latest version.

// settings.gradle
pluginManagement {
    repositories {
        // (...)
        maven { url 'https://jitpack.io' }
    }
}
dependencyResolutionManagement {
    repositories {
        // (...)
        maven { url 'https://jitpack.io' }
    }
}
(...)
// build.gradle (:app)
implementation 'com.github.goncalopalaio:CatTrace:0.3'

Known issues

  • Transition between threads
  • If different threads have the same id across multiple processes, only one of the threads display the name in Perfetto.

About

Low overhead tracer for Kotlin based applications

Resources

Stars

Watchers

Forks

Packages

No packages published