fun stop()

in src/main/kotlin/com/uber/nanoscope/Nanoscope.kt [89:127]


        fun stop() {
            println("Flushing trace data... (Do not close app)")
            Adb.setSystemProperty("dev.nanoscope", "\'\'")
            val remotePath = "/data/data/$packageName/files/$filename"
            val remoteTmpPath = "$remotePath.tmp"
            while (!Adb.fileExists(remotePath)) {
                val linesWritten = Adb.lineCount(remoteTmpPath)
                if (linesWritten != null) {
                    print("\rEvents flushed: $linesWritten")
                }
                Thread.sleep(500)
            }

            val localFile = File.createTempFile("nanoscope", ".txt")
            val localPath = localFile.absolutePath
            println("\rPulling trace file... ($localPath)")
            Adb.pullFile(remotePath, localPath)

            if (extOption == null) {
               displayTrace(localFile, null, null)
            } else {
              // no need to wait for timer and state files to appear as they will
              // be present at the same time as the main trace file
              
              val remotePathSample = "/data/data/$packageName/files/$filename.timer"
              val remotePathState = "/data/data/$packageName/files/$filename.state"
              val localPathSample = localPath + ".timer"
              val localPathState = localPath + ".state"
              val localFileSample = File(localPathSample);
              val localFileState = File(localPathState);

              println("\rPulling timer file... ($localPathSample)")
              Adb.pullFile(remotePathSample, localPathSample)

              println("\rPulling state file... ($localPathState)")
              Adb.pullFile(remotePathState, localPathState)              
              displayTrace(localFile, localFileSample, localFileState)
            }
        }