B4J Question Execution time

bogdanc

Active Member
Licensed User
Longtime User
Hi All.

How to get the execution time of sub.
For example i want to check execution time of mysql.

Thanks
 

bogdanc

Active Member
Licensed User
Longtime User
Thank You Erel.
I did as You suggested.

I'm using jSQL module to talk with my database.

I used a timer to query DB for periodical check (every 5sec).

Main:
B4X:
Sub Interval_query_tick
TextField2.Text=mysql1.DB_GET_RESPOND
End Sub

On module class mysql:

B4X:
Sub DB_GET_RESPOND
    Dim n As Long= DateTime.Now   
    Dim Cursor2 As ResultSet
    Cursor2 = sql1.ExecQuery("SELECT KEY FROM prod.main ORDER BY prod.KEY DESC LIMIT 1")
    Do While Cursor2.NextRow
        Return  (( DateTime.Now-n) * 0.001)
    Loop
End Sub


Is it a better way to query and get execution / respond time?


I want check 2 data bases on same time.
I was thinking to use 2 timers one per DB.

is it a good idea?
 
Upvote 0

bogdanc

Active Member
Licensed User
Longtime User
Hi Erel!

I'm trying to check respond from mysql server.
I have some issue and I need to build app to check if is server responding quickly or not.
Is is any beer solution to check mysql db performance.
I want to build it with B4J.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The code should be:
B4X:
Sub DB_GET_RESPOND As Double
    Dim n As Long= DateTime.Now  
    Dim Cursor2 As ResultSet = sql1.ExecQuery("SELECT KEY FROM prod.main ORDER BY prod.KEY DESC LIMIT 1")
    Cursor2.Close
    Return  (( DateTime.Now-n) * 0.001)
End Sub

1. Add a Try / Catch block to catch any errors.
2. It is better to use sql1.ExecQueryAsyc to avoid blocking the UI. It will be a bit more complicated.
 
Upvote 0

bogdanc

Active Member
Licensed User
Longtime User
Hi Erel!

Ad1)
I modified to:

B4X:
    Dim n As Long= DateTime.Now   
    Try
    Dim Cursor2 As ResultSet  = sql1.ExecQuery("
"SELECT KEY FROM prod.main ORDER BY prod.KEY DESC LIMIT 1"
")
     Cursor2.Close
    Log("TS Time exec [s]:" &  (( DateTime.Now-n) * 0.001))
    Return  (( DateTime.Now-n) * 0.001)
    Catch
        Log("ERROR:"& Cursor2)
        Return "Tesstabd error"& Cursor2
    End Try

I added try and catch.

Ad)

Is there any tutorial to shows how to use ExecQueryAsyc?


Thanks
 
Upvote 0
Top