Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Collecting trace information – PB Docs 90 – PowerBuilder Library

Collecting trace information – PB Docs 90

Collecting trace information

There are three ways to collect trace information. You can
use:

  • The Profiling tab on the System Options dialog box
  • A window similar to the Profiling tab
  • Trace objects and functions

Use the Profiling tab if you want to trace an entire application
run in the development environment. For more information, see “Tracing an entire application
in PowerBuilder”
.

Use a window or trace objects and functions if you want to
create a trace file for selected parts of the application or the
entire application, either in the development environment or when
running an executable file. See “Using a window” and “Collecting trace information
using PowerScript functions”
.

note.gif Collection time The timer values in the trace file exclude the time taken
to collect the trace data. Because an application can be idle (while
displaying a MessageBox, for example), percentage metrics are most
meaningful when you control tracing programmatically, which can
help minimize idle time. Percentages are less meaningful when you
create a trace file for a complete application.

Whichever method you use, you can specify:

  • The name and location
    of the trace file and optional labels for blocks of trace data
  • The kind of timer used in the trace file
  • The activities you want recorded in the trace file

Trace file names and labels

The default name of the trace file is the name of the application
with the extension PBP. The trace file is saved
in the directory where the PBL or executable file resides and overwrites
any existing file of the same name. If you run several different
tests on the same application, you should change the trace file
name for each test.

You can also associate a label with the trace data. If you
are tracing several different parts of an application in a single
test run, you can associate a different label with the trace data
(the trace block) for each part of the application.

Timer kinds

There are three kinds of timer: clock, process, and thread.
If your analysis does not require timing information, you can omit
timing information from the trace file to improve performance.

If you do not specify a timer kind, the time at which each
activity begins and ends is recorded using the clock timer, which
measures an absolute time with reference to an external activity,
such as the machine’s start-up time. The clock timer measures
time in microseconds. Depending on the speed of your machine’s
central processing unit, the clock timer can offer a resolution
of less than one microsecond. A timer’s resolution is the
smallest unit of time the timer can measure.

You can also use process or thread timers, which measure time
in microseconds with reference to when the process or thread being
executed started. You should always use the thread timer for distributed
applications. Both process and thread timers exclude the time taken
by any other running processes or threads so that they give you
a more accurate measurement of how long the process or thread is
taking to execute, but both have a lower resolution than the clock
timer.

Trace activities

You can choose to record in the trace file the time at which
any of the following activities occurs. If you are using the System
Options dialog box or a window, you select the check boxes for the
activities you want. If you are using PowerScript functions to collect
trace information, you use the TraceActivity enumerated
type to identify the activity.

Table 31-1: Trace activities
Trace Activities check box What is recorded TraceActivity value
Routine Entry/Exit Routine entry or exit ActRoutine!
Routine Line Hits Execution of any line in any routine ActLine!
Embedded SQL Use of an embedded SQL verb ActESQL!
Object Creation/
Destruction
Object creation or destruction ActObjectCreate!, ActObjectDestroy!
User Defined Activities A user-defined activity that records
an informational message
ActUser!
System Errors A system error or warning ActError!
Garbage Collection Garbage collection ActGarbageCollect!
Not available Routine entry and exit, embedded SQL verbs,
object creation and destruction, and garbage collection
ActProfile!
Not available All except ActLine! ActTrace!

When you begin and end tracing, an activity of type ActBegin!
is automatically recorded in the trace file. User-defined activities,
which you use to log informational messages to the trace file, are
the only trace activities enabled by default.

Tracing an entire application in PowerBuilder

Use the Profiling tab on the System Options dialog box if
you want to collect trace data for an entire application run in
the PowerBuilder development environment.

proc.gif To trace an entire application in PowerBuilder:

  1. Select Tools>System Options from
    the PowerBar and select the Profiling tab.

  2. Specify a name for the trace file, select the
    trace options you want, and click OK.

    When you run the application, the activities you selected
    are logged in the trace file.

Using a window

You can create a window that is similar to the Profiling tab
on the System Options dialog box and add it to any application that
is under development, so that you can start and stop tracing when
testing specific actions. This window lets you specify a trace file
name, label, and timer kind, as well as which activities you want
to trace:

trace02.gif

The following instance variables are defined for the window:

The open event for the window sets some defaults:

The following code shows the script for the Clicked event
of the Start Trace button. The text for the button is set to Start
Trace in the painter. When the user clicks Start Trace, the button
label changes to Stop Trace. The Clicked event script checks the
text on the button before either starting or stopping tracing. This
script uses the functions described in “Collecting trace information
using PowerScript functions”
:

of_errmsg function

The window uses two functions to handle error messages. The of_errmsg function
displays a message box:

of_converterror function

The of_converterror function converts
the ErrorReturn parameter to a string:

Collecting trace information using PowerScript functions

You use the PowerScript system functions listed in Table 31-2 to collect information
in a trace file. Each of these functions returns a value of type ErrorReturn,
an enumerated datatype.

Table 31-2: PowerScript trace functions
Use this PowerScript function To do this
TraceOpen Open a named trace file and set the timer
kind.
TraceEnableActivity Enable logging of the specified activity.
TraceBegin Start logging all enabled activities.
You can pass an optional label for the trace block.
TraceError Log a severity level and error message
to the trace file.
TraceUser Log a reference number and informational
message to the trace file.
TraceEnd Stop logging all enabled activities.
TraceDisableActivity Disable logging of the specified activity.
TraceClose Close the open trace file.

In general, you call the functions in the order shown in the
table. That is, you must call TraceOpen before
you call any other trace functions. You call TraceClose when
you have finished tracing.

TraceEnableActivity and TraceDisableActivity can
be called only when a trace file is open but tracing has not begun
or has stopped–that is, before you call TraceBegin or
after you call TraceEnd.

TraceUser and TraceError can
be called only when the trace file is open and tracing is active–that
is, after you call TraceBegin and before you
call TraceEnd.

About TraceUser and TraceError

You can use TraceUser to record specific
events in the trace file, such as the beginning and end of a body
of code. You can also record the execution of a statement you never
expected to reach, such as the DEFAULT statement
in a CHOOSE CASE block. TraceError works
just like TraceUser, but you can use it to signal
more severe problems.

Both TraceUser and TraceError take
a number and text string as arguments. You can use a simple text
string that states what activity occurred, or you can build a string
that provides more diagnostic information by including some context, such
as the current values of variables. Run the application with only
ActUser! or ActError! tracing turned on and then use the Profiling
Trace View to pinpoint problems quickly.

Example: trace data collection

In this example, the user selects a timer kind from a drop-down
list and enters a name for the trace file in a single-line edit
box. Typically you would use the ErrorReturn return
value from every trace call to return an error message if the call
fails. For brevity, the example shows this only for the TraceOpen call.

Several trace activities are disabled for a second trace block.
The activities that are not specifically disabled
remain enabled until TraceClose is called.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x