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

Csv timing output #78

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d83409a
Added a csv output to with timings for all stages.
Casper-NS Apr 28, 2023
ecb2006
Added a limit for number of frames collected.
Casper-NS Apr 28, 2023
0e5c14e
FLush and close the utput streams.
Casper-NS Apr 28, 2023
e7ee0b6
minor fix
Casper-NS Apr 28, 2023
2fbeaae
overall for switchable
Casper-NS Apr 28, 2023
61c8d2b
Semi working version, we have issues with stages being on different t…
Casper-NS Apr 28, 2023
e6d5d26
everything is logged and sequential now
Casper-NS May 3, 2023
08e87f5
Merge branch 'main' into csv-timing-output
Casper-NS May 3, 2023
814791c
Made some fixes and seperated when stages and overall are measured
Casper-NS May 3, 2023
bc020cc
removed outdated code
Casper-NS May 8, 2023
9c8b867
upped frame num
Casper-NS May 8, 2023
ae54cca
Added a csv output to with timings for all stages.
Casper-NS Apr 28, 2023
fbf6662
Added a limit for number of frames collected.
Casper-NS Apr 28, 2023
5ad4480
FLush and close the utput streams.
Casper-NS Apr 28, 2023
bdb8a33
minor fix
Casper-NS Apr 28, 2023
69746ac
overall for switchable
Casper-NS Apr 28, 2023
610c1f0
Semi working version, we have issues with stages being on different t…
Casper-NS Apr 28, 2023
aa0895f
everything is logged and sequential now
Casper-NS May 3, 2023
a5afd12
Made some fixes and seperated when stages and overall are measured
Casper-NS May 3, 2023
6242a93
upped frame num
Casper-NS May 8, 2023
d0449c1
rebased everything
Casper-NS May 8, 2023
dfd711a
Merge branch 'csv-timing-output' of https://github.com/cs-23-sw-6-21/…
Mati-AAU May 8, 2023
0bb87d7
4k mode
Mati-AAU May 8, 2023
6d8f0b7
Fixed unused import
Mati-AAU May 8, 2023
2ce7d05
removed unnecesary stages and readded letterboxing
Casper-NS May 8, 2023
d513185
Fixed pipeline
Mati-AAU May 8, 2023
ddd731c
fixes
Casper-NS May 8, 2023
9734b02
Merge remote-tracking branch 'origin/csv-timing-output' into csv-timi…
Casper-NS May 8, 2023
7ee0159
added missing doublebuffer thing
Casper-NS May 18, 2023
0b2b719
added time to compare with profiler'
Casper-NS Jun 25, 2023
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
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {

defaultConfig {
applicationId "dk.scuffed.whiteboardapp"
minSdk 29
minSdk 30
targetSdk 33
versionCode 1
versionName "1.0"
Expand All @@ -30,6 +30,7 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
compileOptions {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>


<application
android:allowBackup="true"
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/dk/scuffed/whiteboardapp/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package dk.scuffed.whiteboardapp

import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import dk.scuffed.whiteboardapp.opengl.OpenGLView
import dk.scuffed.whiteboardapp.pipeline.CSVWriter
import org.opencv.android.OpenCVLoader


class MainActivity : AppCompatActivity() {
private val CAMERA_PERMISSION_REQUEST_CODE = 100

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -32,6 +37,19 @@ class MainActivity : AppCompatActivity() {
val openGLView = OpenGLView(this)
buttonView.addView(openGLView)
}
// Check if the permission has already been granted
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
// Permission has already been granted, you can save CSV files
} else {
// Permission has not been granted yet, request it
requestPermissions(arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
}

if (!Environment.isExternalStorageManager()) {
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
startActivity(intent)
}
CSVWriter.programStartTime = System.nanoTime()
}

override fun onRequestPermissionsResult(
Expand All @@ -49,5 +67,17 @@ class MainActivity : AppCompatActivity() {
finish()
}
}
if (requestCode == 1)
{
// If request is cancelled, the grantResults array is empty
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission has been granted, you can save CSV files
} else {
Toast.makeText(this, "This app requires storage permission!", Toast.LENGTH_LONG)
.show()
finish()
}
return
}
}
}
33 changes: 33 additions & 0 deletions app/src/main/java/dk/scuffed/whiteboardapp/pipeline/CSVWriter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dk.scuffed.whiteboardapp.pipeline

import android.os.Environment
import java.io.File
import java.io.OutputStreamWriter

object CSVWriter {

var recordStageTimings = false

var programStartTime : Long = 1

var recordOverallTimings = true

val useGlFinish = true

var frameCounter = 0

val numberOfFrames = 1100

val MainWriter : OutputStreamWriter

init {
val dir = Environment.getExternalStorageDirectory()

val mainFile = File(dir, "Latency-Data.csv")

mainFile.createNewFile()

MainWriter = mainFile.writer()
}

}
50 changes: 34 additions & 16 deletions app/src/main/java/dk/scuffed/whiteboardapp/pipeline/Pipeline.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
package dk.scuffed.whiteboardapp.pipeline

import android.content.Context
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.opengl.GLES20
import android.util.Log
import android.util.Size
import android.view.View
import android.widget.Button
import dk.scuffed.whiteboardapp.MainActivity
import dk.scuffed.whiteboardapp.R
import dk.scuffed.whiteboardapp.opengl.*
import dk.scuffed.whiteboardapp.pipeline.stage_combinations.*
import dk.scuffed.whiteboardapp.pipeline.stages.*
import dk.scuffed.whiteboardapp.pipeline.stages.bitmap_process_stages.DumpToGalleryStage
import dk.scuffed.whiteboardapp.pipeline.stages.bitmap_process_stages.FramebufferToBitmapStage
import dk.scuffed.whiteboardapp.pipeline.stages.input_stages.CameraXStage
import dk.scuffed.whiteboardapp.pipeline.stages.input_stages.TextureStage
import dk.scuffed.whiteboardapp.pipeline.stages.opengl_process_stages.*
import dk.scuffed.whiteboardapp.pipeline.stages.opengl_process_stages.LetterboxingStage
import dk.scuffed.whiteboardapp.pipeline.stages.output_stages.DrawFramebufferStage
import dk.scuffed.whiteboardapp.pipeline.stages.pipeline_stages.SwitchablePointPipeline
import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.DraggablePointsStage

const val useDoubleBuffering = true
const val useDoubleBuffering = false
const val use4K = false

internal class Pipeline(context: Context, private val initialResolution: Size) : IPipeline {
internal class Pipeline(private val context: Context, private val initialResolution: Size) : IPipeline {

private var stages = mutableListOf<Stage>()
var stages = mutableListOf<Stage>()
private var nextTextureUnit: Int = 0

private fun indexToTextureUnit(i: Int): Int{
Expand All @@ -49,26 +45,48 @@ internal class Pipeline(context: Context, private val initialResolution: Size) :
val cameraXStage = CameraXStage(context, this)


val entirePipeline = fullPipeline(context, cameraXStage, this)
val entirePipeline = mainThreadPipeline(context, cameraXStage, this)

//dumpToGalleryFull(context, entirePipeline.second.frameBufferInfo, this)


val letterbox = LetterboxingStage(context, entirePipeline.second.frameBufferInfo, this)
val letterbox = LetterboxingStage(context, entirePipeline.frameBufferInfo, this)

DrawFramebufferStage(
context,
letterbox.frameBufferInfo,
this
)

if (CSVWriter.recordOverallTimings){
CSVWriter.MainWriter.write("Overall;")
CSVWriter.MainWriter.write("Time")
}
CSVWriter.MainWriter.write("\n")
}

override fun draw() {
val startTime = System.nanoTime()
stages.forEach { stage -> stage.performUpdate() }
val endTime = System.nanoTime()
val duration = (endTime - startTime).toDouble() / 1000000.0
Log.i("Pipeline", "Frame took ${duration}ms")

if (CSVWriter.recordOverallTimings || CSVWriter.recordStageTimings)
{
if (CSVWriter.recordOverallTimings)
{
CSVWriter.MainWriter.write("$duration;${(System.nanoTime() - CSVWriter.programStartTime).toDouble() / 1000000.0}")
}
CSVWriter.MainWriter.write("\n")
CSVWriter.frameCounter += 1
if (CSVWriter.frameCounter == CSVWriter.numberOfFrames)
{
(context as MainActivity).findViewById<Button>(R.id.round_button).visibility = View.INVISIBLE
CSVWriter.recordStageTimings = false
CSVWriter.recordOverallTimings = false
CSVWriter.MainWriter.flush()
CSVWriter.MainWriter.close()
}
}
}

override fun onResolutionChanged(resolution: Size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal fun addColour(
mask: GLOutputStage,
pipeline: IPipeline
): GLOutputStage {

val adjusted = HSVAdjustmentsStage(
context,
colours.frameBufferInfo,
Expand Down
Loading