delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/24/01:16:22

From: Genady Beryozkin <c0467082 AT techst02 DOT technion DOT ac DOT il>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Profiling allegro apps
Date: Tue, 21 Oct 1997 22:22:09 +0200
Organization: The Technion
Lines: 425
Message-ID: <344D0EF1.34B51ED9@t2.technion.ac.il>
References: <199710100003 DOT RAA14883 AT adit DOT ap DOT net>
NNTP-Posting-Host: galilee.org.il
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

This is a multi-part message in MIME format.
--------------ACE111AC21DF8C50F913A08B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Nate Eldredge wrote:
> 
> At 09:02  10/7/1997 GMT, Stefan Schimanski wrote:
> >Hello,
> >
> >does anybody know how to profile code written with djgpp and allegro. gprof
> >doesn't work because no profiling data is produced by the executable. I've
> >tested it with a simple Hello-world program and it worked. Could it be that
> >the timer code of allegro kills the profiler code inside the executable?
> Yeah, I think that's the case. Shawn?
> You might be able to implement some limited profiling by using an Allegro
> timer as a counter, and printing its value at various strategic places in
> the code.
> 
> Nate Eldredge
> eldredge AT ap DOT net

I can see this as a little problematic since allegro's timer is not
accurate at all. 
well - it is accurate but not suitable for profiling. you should do a
simple test to 
discover that - install a timer which executes each millisecond and
increase some counter by one each time. wait 10 minutes - your allegro
timer will report something like 9:55 ...

I have a timer library, but I haven't tested it with allegro yet.
I send it as an attachment - the .cpp file if for Borland C. The .cc
file is for djgpp. remove the main() function in djtimer.cc - it's
intended for testing.


Genady
--------------ACE111AC21DF8C50F913A08B
Content-Type: application/msword; name="Tctimer.doc"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="Tctimer.doc"

VENUSU1FUiAtIFJvdXRpbmVzIGZvciBoaWdoLXJlc29sdXRpb24gdGltaW5nIG9mIGV2ZW50
cyBmb3IgVHVyYm8gQw0KLS0tLS0tLS0tLS0tLS0t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WVkIHdpdGggMS1taWNyb3NlY29uZCBhY2N1cmFjeSBhbnl3YXkuDQoNCkFs
c28gbm90ZSB0aGF0IHRoZSBwcm9jZXNzIG9mIHJlYWRpbmcgdGhlIHRpbWUgdGFrZXMgdGlt
ZS4gSGVuY2UsIHJlc3VsdHMgb2YNCnRpbWluZyB2ZXJ5IHNob3J0IGV2ZW50cyB3aWxsIGJl
IHNrZXdlZCBieSB0aGUgb3ZlcmhlYWQgb2YgcmVhZGluZyB0aGUgdGltZXIuDQpUaGUgZm9s
bG93aW5nIHRhYmxlIHNob3dzIHRoZSB0aW1lIG1lYXN1cmVkIGJldHdlZW4gdHdvIGNhbGxz
IHRvIFJlYWRUaW1lciwNCm9uZSByaWdodCBhZnRlciB0aGUgb3RoZXIuDQoNCiAgVG9zaGli
YSAxMDAwICg0Ljc3TUh6IDgwODgpICAgIDEyNSBtaWNyb3NlY29uZHMNCiAgQVRUIDYzMDAg
KDhNSHogODA4NikgICAgICAgICAgICA1MyAgICAgIg0KICBEZXNrcHJvIDI4NiAoOE1IeiA4
MDI4NikgICAgICAgIDM1ICAgICAiDQogIFNwZXJyeSBJVCAoNy4xTUh6IDI4NiwgMCB3YWl0
KSAgMzIgICAgICINCiAgSUJNIFBTLzIgbW9kZWwgNTAgICAgICAgICAgICAgICAyNSAgICAg
Ig0KICBQQyBEZXNpZ25zIEdWMzg2ICgxNk1IeikgICAgICAgIDI3ICAgICAiDQoa
--------------ACE111AC21DF8C50F913A08B
Content-Type: text/plain; charset=us-ascii; name="Tctimer.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Tctimer.cpp"

#include <dos.h>

const TimerResolution=1193181.667;

void cardinal(long l,double *result)
{
	*result = ((l<0)?4294967296.0 + (long)l : (long)l);
}

void elapsedtime(long start, long stop, double *result)
{
	double r;

	cardinal(stop - start, &r);

	*result = (1000.0 * r) / TimerResolution;
}

void initializetimer(void)
{

  outportb(0x043,0x034);
  asm jmp short NullJump1

NullJump1:;

  outportb(0x040,0x000);
  asm jmp short NullJump2

NullJump2:;

  outportb(0x040,0x000);

}

void restoretimer(void)
{
  outportb(0x043,0x036);
  asm jmp short NullJump1

NullJump1:;

  outportb(0x040,0x000);
  asm jmp short NullJump2

NullJump2:;

  outportb(0x040,0x000);

}

long readtimer(void)
{
  asm cli             /* Disable interrupts */
  asm mov  dx,020h     /* Address PIC ocw3   */
  asm mov  al,00Ah     /* Ask to read irr    */
  asm out  dx,al
  asm mov  al,00h     /* Latch timer 0 */
  asm out  043h,al
  asm in   al,dx      /* Read irr      */
  asm mov  di,ax      /* Save it in DI */
  asm in   al,040h     /* Counter --> bx*/
  asm mov  bl,al      /* LSB in BL     */
  asm in   al,040h
  asm mov  bh,al      /* MSB in BH     */
  asm not  bx         /* Need ascending counter */
  asm in   al,021h     /* Read PIC imr  */
  asm mov  si,ax      /* Save it in SI */
  asm mov  al,00FFh    /* Mask all interrupts */
  asm out  021h,al
  asm mov  ax,040h     /* read low word of time */
  asm mov  es,ax      /* from BIOS data area   */
  asm mov  dx,es:[06Ch]
  asm mov  ax,si      /* Restore imr from SI   */
  asm out  021h,al
  asm sti             /* Enable interrupts */
  asm mov  ax,di      /* Retrieve old irr  */
  asm test al,001h     /* Counter hit 0?    */
  asm jz   done       /* Jump if not       */
  asm cmp  bx,0FFh     /* Counter > 0x0FF?    */
  asm ja   done       /* Done if so        */
  asm inc  dx         /* Else count int req. */
done:;
  asm mov ax,bx   /* set function result */
}

--------------ACE111AC21DF8C50F913A08B
Content-Type: text/plain; charset=us-ascii; name="Tctimer.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Tctimer.h"


void cardinal(long l, double *result);


void elapsedtime(long start, long stop, double *result);
/*Calculate time elapsed (in milliseconds) between Start and Stop*/

void initializetimer(void);
/*Reprogram the timer chip to allow 1 microsecond resolution*/

void restoretimer(void);
/*Restore the timer chip to its normal state*/

long readtimer(void);
/*Read the timer with 1 microsecond resolution*/


--------------ACE111AC21DF8C50F913A08B
Content-Type: text/plain; charset=us-ascii; name="djtimer.cc"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="djtimer.cc"

#include <pc.h>
#include <stdlib.h>
#include <dos.h>
#include <iostream.h>
//void __dosmemgetw(unsigned long _offset, int _xfers, void *_buffer);
#include <go32.h>
#include <string.h>
#include <conio.h>
#include <sys/movedata.h>
#include <time.h>
#define randomize() srandom(time(0))   // under djgpp

const double TimerResolution=1193181.667;

void cardinal(unsigned long l,double *result)
{
	*result = ((l<0)?4294967296.0 + (unsigned long)l : (unsigned long)l);
}

void elapsedtime(unsigned long start, unsigned long stop, double *result)
{
	double r;

	cardinal(stop - start, &r);

	*result = (1000.0 * r) / TimerResolution;
}

void initializetimer(void)
{

  outportb(0x043,0x034);
  asm ("jmp NullJump1;"
       "NullJump1:;");

  outportb(0x040,0x000);
  asm ("jmp NullJump2;"
       "NullJump2:;");

  outportb(0x040,0x000);

}

void restoretimer(void)
{
  outportb(0x043,0x036);
  asm ("jmp NullJump3;"
       "NullJump3:;");

  outportb(0x040,0x000);
  asm ("jmp NullJump4;"
       "NullJump4:;");

  outportb(0x040,0x000);

}

unsigned long readtimer(void)
{
  unsigned long eax,ebx,ecx,edx,esi,edi,dx;
  unsigned short low,high;

/*  asm ("cli");
  outportb(0x20,0xA);          // ask to read irr
  outportb(0x43,0x0);          // latch tiemr 0
  unsigned char irr=inportb(0x20);  // read irr
  unsigned char low=inportb(0x40);
  unsigned char high=inportb(0x40);
  unsigned short counter=~((high << 8) + low);
  unsigned char imr=inportb(0x21);
  outportb(0x21,0xFF);
  unsigned short counter2;
  dosmemget(0x46C,2,&counter2);
  outportb(0x21,imr);
  asm ("sti");
  if (irr==1) goto done;
  if (counter>0xFF) goto done;
  counter2++;
done:
  cout << counter2 << "," << counter << endl;
  return (counter2 << 16) + counter; */


__asm__ __volatile__ (
      "cli;"                  // Disable interrupts
      "movw  $0x20,%%dx; "      // Address PIC ocw3
      "movb  $0xA,%%al;  "      // Ask to read irr
      "outb  %%al,%%dx;  "
      "movb  $0,%%al;    "      // Latch timer 0
      "outb  %%al,$0x43; "
      "inb   %%dx,%%al;  "      // Read irr
      "movw  %%ax,%%di;  "      // Save it in DI
      "inb   $0x40,%%al; "      // Counter --> bx
      "movb  %%al,%%bl;  "      // LSB in BL
      "inb   $0x40,%%al; "
      "movb  %%al,%%bh;  "      // MSB in BH
      "notw  %%bx;       "      // Need ascending counter
      "inb   $0x21,%%al; "      // Read PIC imr
      "movw  %%ax,%%si;  "      // Save it in SI
      "movb  $0xFF,%%al; "      // Mask all interrupts
      "outb  %%al,$0x21; "
  : "=a" (eax), "=b"(ebx), "=d" (edx), "=S"(esi), "=D"(edi)
  :
  );
  dosmemget(0x46C,2,&dx);
  edx=dx;

__asm__ __volatile__ (
      "movw  %%si,%%ax ; "      //* Restore imr from SI
      "outb  %%al,$0x21; "
      "sti             ; "      //* Enable interrupts
      "movw  %%di,%%ax ; "      //* Retrieve old irr
      "testb $01,%%al  ; "      //* Counter hit 0?
      "jz    done      ; "      //* Jump if not
      "cmpw  $0xFF,%%bx; "      //* Counter > 0x0FF?
      "ja    done      ; "      //* Done if so
      "incw  %%dx      ; "      //* Else count int req.
      "done:           ; "
      "movw  %%bx,%%ax ; "
      : "=a" (low) , "=d" (high)
      : "a" (eax), "b" (ebx), "d" (edx), "S" (esi), "D" (edi));
                                // set function result

//      "movw  %%ax, %0" : "=a"(eax));
//      "movw  %%dx, %0" : "=d"(edx));

//  return dx << 16 + ax;
//    cout << "Low: " << low << "    High: " << high << "    Total: "
//         << high << 16 + low << endl;
    return (high << 16) + low;
}

int main()
{
// unsigned short int dx;
// dosmemget(0x46C,2,&dx);
// cout << dx;
 cout << "Press any key to start the timer" << endl;
 getch();
 initializetimer();
 cout << "Press any key to stop the timer" << endl;
 long TStart=readtimer();
 getch();
 long TStop=readtimer();
 double a;
 elapsedtime(TStart,TStop,&a);
 cout << endl << "Time passed : " << (long)(a/1000.) << " seconds " << endl;
 cout << endl << "---------------" << endl << endl;
// restoretimer();
                                        /*
 cout << "Press any key to start various delay tests . . . " ;
 cout.flush();
 getch(); cout << endl;
 randomize();
 for (int i=0 ; i < 50 ; i++)
 {
   int del=random() % 1000 + 10;
   cout << "Delaying for " << del << " milliseconds. ";
   cout.flush();
   TStart=readtimer();
   delay(del);
   TStop=readtimer();
   elapsedtime(TStart,TStop,&a);
   cout << " Measured " << (long)a << "ms. Press any key." << endl;
   cout.flush();
//   getch();
 }                                    */
                  // 2.9626
 cout << "Running 100,000,000,000 nop instructions";
 cout.flush();
 TStart=readtimer();
 asm volatile (
      "mov $0xFFFF,%ecx \n"
      "NullJump5:;"
      "nop;"
      "loop NullJump5;"
      );
// asm volatile ("movl $100000000000,%ecx \n"
//               "Here:\n"
//               "nop\n"
//               "loop aloop");
 TStop=readtimer();
 elapsedtime(TStart,TStop,&a);
 cout << endl << "Time passed : " << a << " ms " << endl;
 return 1;
}


--------------ACE111AC21DF8C50F913A08B
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Genady Beryozkin
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Genady Beryozkin
n:              Beryozkin;Genady
org:            The Technion
adr:            ;;;Natzrat Illit / Haifa;;;Israel
email;internet: c0467082 AT t2 DOT technion DOT ac DOT il
note:           Homepage : http://t2.technion.ac.il/~c0467082/
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
version:        2.1
end:            vcard


--------------ACE111AC21DF8C50F913A08B--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019