Trailing-Edge
-
PDP-10 Archives
-
SRI_NIC_PERM_SRC_3_19910112
-
utilities/pcsamp.mac
There are no other files named pcsamp.mac in the archive.
TITLE PCSAMP
SUBTTL J. BURCHFIEL JAN 10,1972
SEARCH monsym
A=1
B=2
C=3
D=4
E=5
TEMP=16
P=17
BEG: RESET
MOVE P,[IOWD 10,PDL]
MOVE A,[XWD TEMPS,TEMPS+1]
SETZM TEMPS
BLT A,ENDTMP
MOVSI A,^D04 ;CNTL-D ON CHANNEL 0
ATI
MOVEI A,400000
MOVE B,[XWD LEVTAB,CHNTAB]
SIR
MOVEI A,400000
MOVSI B,(1B0)
AIC
EIR
;COMPUTE PAGE TO BE USED FOR MAPPING
MOVEI A,ENDTMP ;GET ADDR OF PROG END
ADDI A,^D511
IDIVI A,^D512
MOVEM A,MAPPG
Q1: HRROI A,[ASCIZ/
PROGRAM TO BE SAMPLED:/]
PSOUT
MOVE A,[XWD JBLOCK,JBLOCK+1]
SETZM JBLOCK
BLT A,JBLOCK+10
MOVSI A,120003
MOVEM A,JBLOCK
MOVE A,[XWD 100,101]
MOVEM A,JBLOCK+1
HRROI A,[ASCIZ /EXE/] ;DEFAULT EXTENTION .exe
MOVEM A,JBLOCK+5
MOVEI A,JBLOCK
GTJFN
JRST Q1
MOVEM A,PRGJFN
Q2: HRROI A,[ASCIZ/
FILE TO STORE SAMPLE PCS:/]
PSOUT
MOVSI A,460003
MOVE B,[XWD 100,101]
GTJFN
JRST Q2
MOVEM A,OUTJFN
MOVE B,[XWD 070000,100000] ;ASCII NUMBERS
OPENF
PUSHJ P,ERR
Q3: HRROI A,[ASCIZ/
SAMPLING INTERVAL (MSEC) = /]
PSOUT
MOVEI A,101
MOVEI C,^D10
NIN
PUSHJ P,ERR
JUMPLE B,Q3
MOVEM B,INTRVL
HRROI A,[ASCIZ/
SAMPLING MAY BE FINISHED BY CNTL-D.
/]
PSOUT
MOVE A,OUTJFN
SETO B,
SETZ C,
ODTIM ;FILE HEADING INCLUDES DATE
HRROI B,[ASCIZ/
PROGRAM BEING WATCHED = /]
SETZ C,
SOUT
HRRZ B,PRGJFN
SETZ C,
JFNS ;AND PROGRAM
HRROI B,[ASCIZ/
SAMPLING INTERVAL (MSEC) = /]
SETZ C,
SOUT
MOVE B,INTRVL
MOVEI C,^D10
NOUT ;AND INTERVAL
PUSHJ P,ERR
; MOVEI B,37
; BOUT
hrroi 2,[byte (7) 15,12]
setz 3,
sout
MOVSI A,200000
CFORK ;CREATE INFERIOR FORK FOR PROGRAM
PUSHJ P,ERR
MOVEM A,FORK
HRLZ A,A
HRR A,PRGJFN
GET ;GET IT
MOVE A,FORK
SETZ B,
SFRKV ;AND START IT
MOVSI D,-^D10000 ;COLLECT UP TO 10000 PC SAMPLES
LP: MOVE A,INTRVL
DISMS
AOS NTRIES
MOVE A,FORK
ADD A,FORKIN ;TO GET AT LOWER FORKS
RFSTS
CAMN A,[ -1]
JRST LP ;HASNT STARTED YET
HLRZ A,A
ANDI A,7
;SEE IF LWER FORK IS STILL ALIVE AND KICKING
CAIG A,1
JRST ALIVE
CAIG A,3
JRST SORT ;ITS DEAD - FINISH UP
ALIVE: SUBI B,1 ;BACK UP PC
MOVEM B,SAMPPC
MOVE A,FORK
ADD A,FORKIN
RUNTM
MOVE B,INTRVL
ADD B,OLDTIM
CAMGE A,B ;HAS IT ACCUMULATED INTRVL OF RUNTIME?
JRST LP ;NO, KEEP ACCUMULATING
MOVEM A,OLDTIM ;YES, ACCOUNT AND STORE SAMPLE
STORE: MOVE B,SAMPPC
TLNE B,10000
AOSA NUSER
PUSHJ P,MON ;SEE IF REALLY MON MODE
HRRZM B,PCVEC(D)
AOBJN D,LP
SORT: HRRZM D,COUNT
SKIPN COUNT
JRST [HRRZI A,[ASCIZ /NO SAMPLES TAKEN
/]
PSOUT
HALTF]
MOVEI A,400000
DIR
MOVE A,FORK
ADD A,FORKIN
RUNTM
IMULI A,^D1000
IDIVI A,(B)
MOVEM A,RUNTIM
MOVEI A,101
; MOVEI B,37
; BOUT
hrroi 2,[byte (7) 15,12]
setz 3,
sout
MOVE B,COUNT
MOVEI C,^D10
NOUT ;INFORM USER ABOUT SAMPLES
PUSHJ P,ERR
HRROI A,[ASCIZ/ (DECIMAL) PC SAMPLES /]
PSOUT
MOVE D,COUNT
MOVEI C,-2(D)
SRTLP2: SETZ B,
SETZ E, ;0 INDICATES NO EXCHANGES
SRTLP1: MOVE A,PCVEC(B)
CAML A,PCVEC+1(B)
JRST SRT2
EXCH A,PCVEC+1(B)
MOVEM A,PCVEC(B)
SETO E, ;INDICATE EXCHANGE TOOK PLACE
SRT2: CAIGE B,(C) ;STUPID BUBBLE SORT
AOJA B,SRTLP1
JUMPE E,FIN ;QUIT IF NO EXCHANGES TOOK PLACE
CAILE C,0
SOJA C,SRTLP2
FIN: MOVE A,OUTJFN
; MOVEI B,37
; BOUT
hrroi 2,[byte (7) 15,12]
setz 3,
sout
MOVE B,COUNT
MOVEI C,^D10 ;FILE HEADING INCLUDES NUMBER OF SAMPLES
NOUT
PUSHJ P,ERR
HRROI B,[ASCIZ/ (DECIMAL) PC SAMPLES.
RUNTIME (MSEC) = /]
SETZ C,
SOUT
MOVE A,OUTJFN
MOVE B,RUNTIM
MOVEI C,^D10
NOUT ;AND RUNTIME
PUSHJ P,ERR
; MOVEI B,37
; BOUT
hrroi 2,[byte (7) 15,12]
setz 3,
sout
MOVE B,NUSER
IMULI B,^D100
IDIV B,COUNT
;ROUND OFF
LSH C,1
CAML C,COUNT
ADDI B,1
MOVEI C,^D10
NOUT
PUSHJ P,ERR
HRROI B,[ASCIZ/ PERCENT USER MODE.
/]
SETZ C,
SOUT
; MOVEI A,37 ;RATTLE TTY TO SIGNIFY END OF SORT
; PBOUT
hrroi 1,[byte (7) 15,12]
psout
;COMPUTE FREQUENCY DISTRIBUTION
SETO A, ;USED AS INDEX INTO TOTALS TABLE
MOVN B,COUNT
HRLZ B,B ;GET XWD -COUNT,0
TLOOP: MOVE C,PCVEC(B) ;GET PCVEC ENTRY
MOVE E,TOTALS(A)
ANDI E,777777
CAME C,E ;IS IT SAME AS CURRENT TOTALS ENTRY?
AOJ A, ;NO
HRRM C,TOTALS(A) ;STORE PC IN TOTALS
HLRZ D,TOTALS(A) ;GET COUNT
ADDI D,1 ;ADD 1
HRLM D,TOTALS(A) ;PUT IT BACK
AOBJN B,TLOOP ;KEEP GOING IF MORE TO DO
MOVEM A,OUTCNT ;SAVE LAST INDEX
;WRITE HEADING
MOVE A,OUTJFN
HRROI B,[ASCIZ /
LOC INST SAMPLES PCT
/]
SETZ C,
SOUT
PUSHJ P,WRITE ;OUTPUT THE FREQ DIST
MOVE A,OUTJFN
; HRRZI B,37
; BOUT
; BOUT
hrroi 2,[byte (7) 15,12]
setz 3,
sout
sout
;NOW SORT TOTALS BY THE COUNTS
RESORT: MOVE D,OUTCNT
ADDI D,1 ;D NOW CONTAINS TRUE C uNT
MOVEI C,-2(D)
RSRTL2: SETZ B,
SETZ E,
RSRTL1: MOVE A,TOTALS(B)
CAML A,TOTALS+1(B)
JRST RSRT2
EXCH A,TOTALS+1(B)
MOVEM A,TOTALS(B)
SETO E,
RSRT2: CAIGE B,(C)
AOJA B,RSRTL1
JUMPE E,DOWR
CAILE C,0
SOJA C,RSRTL2
DOWR: PUSHJ P,WRITE
HRROI B,[ASCIZ /
(# INDICATES MONITOR MODE)
/]
SETZ C,
SOUT
FIN2: CLOSF
PUSHJ P,ERR
; MOVEI A,37
; PBOUT
hrroi 1,[byte (7) 15,12]
psout
MOVE A,FORK ;KILL THE FORK
KFORK
HALTF
WRITE: PUSHJ P,SEP
MOVE D,OUTCNT
MOVE E,D
ADDI E,1
LSH E,-1
MOVEM E,MIDDLE ;INDEX OF MIDDLE OF PRINTOUT
MOVE A,OUTJFN
WRLOOP: HRRZI B,"*"
BOUT
HRRZ B,TOTALS(D)
MOVEM B,SAMPPC
PUSHJ P,MAP
MOVE C,[XWD 3B21!6,10]
NOUT
PUSHJ P,ERR
MOVE B,0(E) ;GET THE INSTRUCTION
LSH B,-^D27 ;JUST THE OPCODE
CAIN B,104 ;IS IT A JSYS?
JRST [HRROI B,[ASCIZ /# /]
JRST .+2]
HRROI B,[ASCIZ / /]
SETZ C,
SOUT
HLRZ B,0(E) ;GET LEFT HALF OF INSTRUCTION
MOVE C,[XWD 13B21!^D6,10]
NOUT
PUSHJ P,ERR
HRRZI B,","
BOUT
BOUT
HRRZ B,0(E) ;GET RIGHT HALF
MOVE C,[XWD 13B21!^D6,10]
NOUT
PUSHJ P,ERR
HLRZ B,TOTALS(D)
MOVE C,[XWD 1B20!^D10,^D10]
NOUT
PUSHJ P,ERR
;CALCULATE PERCENT TIME SPENT AT THIS INSTRUCTION
IMULI B,^D100
IDIV B,COUNT
;ROUND OFF
LSH C,1 ;REMAINDER*2
CAML C,COUNT
ADDI B,1 ;ADD ONE TO QUOT IF 2*REM .GE. DIVISOR
MOVE C,[XWD 1B20!^D10,^D10]
NOUT
PUSHJ P,ERR
HRRZI B,"*"
BOUT
CAMN D,MIDDLE ;ARE WE AT THE MIDDLE?
PUSHJ P,SRTMSG ;YES
; HRRZI B,37
; BOUT
hrroi 2,[byte (7) 15,12]
setz 3,
sout
SOJGE D,WRLOOP
PUSHJ P,SEP
AOS WRTEX
POPJ P,
;COME HERE IF PROG THINKS SAMPLE OCCURRED IN MONITOR MODE
;VERIFY THAT SAMPLED INSTRUCTION IS A JSYS
MON: PUSHJ P,MAP ;GET ADDRESS OF INST IN THIS FORK
MOVE E,0(E) ;GET THE INSTRUCTION
LSH E,-^D27
CAIE E,104 ;IS IT A JSYS?
PUSHJ P,NOTSYS
POPJ P,
NOTSYS: ADDI B,1
; AOS NUSER
POPJ P,
;ROUTINE TO MAP LOCATION IN SAMPPC INTO THIS FORK
;SAMPPC POINTS TO SAMPLE INSTRUCTION IN LOWER FORK
;ADDRESS OF THE INSTRUCTION IS RETURNEDD IN E
MAP: PUSH P,A ;SAVE A,B,C
PUSH P,B
PUSH P,C
HRRZ A,SAMPPC
LSH A,-^D9
HRL A,FORK
MOVS E,FORKIN
ADD A,E
HRLI B,400000
HRR B,MAPPG
MOVSI C,(1B2) ;READ ACCESS
PMAP
MOVE E,SAMPPC
ANDI E,777 ;GET DISP INTO PAGE
MOVE B,MAPPG
LSH B,^D9
IOR E,B
POP P,C
POP P,B
POP P,A
POPJ P,
SEP: MOVE A,OUTJFN
HRROI B,[ASCIZ /**********************************************
/]
SETZ C,
SOUT
POPJ P,
SRTMSG: MOVE TEMP,WRTEX
MOVE B,MADDRS(TEMP)
SETZ C,
SOUT
POPJ P,
INT: MOVE A,[XWD 10000,SORT]
MOVEM A,PCSAV
MOVEI A,^D04 ;DETACH CNTL-D
DTI
MOVE A,FORK
FFORK ;FREEZE LOWER FORK
DEBRK
HALTF
ERR: MOVE B,[XWD 400000,-1]
MOVEI A,101
SETZ C,
ERSTR
HALTF
HALTF
HALTF
MADDRS: XWD -1,LOCMSG
XWD -1,SAMMSG
LOCMSG: ASCIZ / (SORTED BY LOC)/
SAMMSG: ASCIZ / (SORTED BY SAMPLES)/
LEVTAB: PCSAV
0
0
CHNTAB: XWD 1,INT
REPEAT ^D35,< EXP 0>
LIT
PATCH: BLOCK 10
TEMPS:
PDL: BLOCK 10
JBLOCK: BLOCK 11
PCSAV: BLOCK 1
SAMPPC: BLOCK 1
OLDTIM: BLOCK 1
RUNTIM: BLOCK 1
NTRIES: BLOCK 1
NUSER: BLOCK 1
PRGJFN: BLOCK 1
OUTJFN: BLOCK 1
FORK: BLOCK 1
COUNT: BLOCK 1
INTRVL: BLOCK 1
OUTCNT: BLOCK 1
WRTEX: BLOCK 1
MIDDLE: BLOCK 1
MAPPG: BLOCK 1
FORKIN: BLOCK 1 ;OPTIONAL FORK INCREMENT
PCVEC: BLOCK ^D10000
DUMMY: BLOCK 1
TOTALS: BLOCK ^D10000
ENDTMP:
END BEG