|
|
|
profiling using awk
|
Original Message
|
Name: rp_sony
Date: July 22, 2005 at 06:41:10 Pacific
Subject: profiling using awkOS: cygwinCPU/Ram: intel |
Comment: I need help sorting som assembler code (instruction set profiling (static)), using awk. A piece of the code looks like this.... 44000040 <R_Do_Startup_DetectAndInitializeMemoryOrganization>: 44000040: b5f0 push {r4, r5, r6, r7, lr} 44000042: b08a sub sp, #40 44000044: 2000 mov r0, #0 44000046: 4669 mov r1, sp 44000048: 9001 str r0, [sp, #4] 4400004a: 7308 strb r0, [r1, #12] 4400004c: 7348 strb r0, [r1, #13] What I want to do with this code is to uniquely sort the instructions (strb, push, sub, mow etc) and present it like this push "number of times push is present in this file" strb "number of times strb is present in this file" mov "number of times mob is present in this file" and so on Greatly appreciate any help I can get /RP
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Jim Boothe
Date: July 22, 2005 at 07:08:55 Pacific
|
Reply: (edit)Based on the sample, this code processes only lines where word1 ends with a colon, and assumes word3 is the instruction. awk '{ if (match($1,".*:")) instr[$3]++ } END { for (i in instr) printf " %-8s %4d occurrences\n",i,instr[i] }' program.txt | sort mov 2 occurrences push 1 occurrences str 1 occurrences strb 2 occurrences sub 1 occurrences
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: rp_sony
Date: July 25, 2005 at 00:12:26 Pacific
|
Reply: (edit)Is there any easy way of adding the functionality of say counting 32 bits and 16 bits instructions like this 44000046: 4669 mov r1, sp 4400003c: 44000c58 strmi r0, [r0], #-3160 should give two parts: 16 bit instructions: mov 1 occurences 32 bit instructions: strmi 1 occurences Regards, /RP
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: rp_sony
Date: July 25, 2005 at 00:24:03 Pacific
|
Reply: (edit)I also want to be able to sort out those that are numbers (just throw them away). Rows like this: 4404c51c: 000003ac 420002e8 ......... Should not be counted!! Regards, /RP
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: Jim Boothe
Date: July 25, 2005 at 07:29:19 Pacific
|
Reply: (edit)I don't know one set from the other. Let me know if there is some way to programmatically determine 16-bit from 32-bit. The solution below takes a hard-coded approach where all 16-bit instructions are loaded into an array. But if one set is substantially shorter than the other, that would be the best set to identify and control on. For elimination of numerical instructions, I eliminate those that begin with a digit. If there are any like mov32, it would not eliminate those. For this solution, I had to eliminate the sort. You can see what a sort would do to the output below - it would sort the two groups together. But you probably want each group sorted, so I will follow up with a solution for that, but I wanted to post this basic code first. awk 'BEGIN \ { array16["mov"]=1 array16["sub"]=1 array16["push"]=1 }{ if (!match($1,":")) next instr=$3 if (match(instr,"^[0-9]")) next if (instr in array16) instr16[instr]++ else instr32[instr]++ } END \ { print "16-bit instructions" for (i in instr16) printf "%-8s %4d occurrences\n",i,instr16[i] print "\n32-bit instructions" for (i in instr32) printf "%-8s %4d occurrences\n",i,instr32[i] }' program.txt 16-bit instructions mov 2 occurrences sub 1 occurrences push 1 occurrences32-bit instructions mov42 1 occurrences strb 2 occurrences str 1 occurrences
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: Jim Boothe
Date: July 25, 2005 at 07:58:54 Pacific
|
Reply: (edit)This solution adds 9 leading characters to the front of each line for sort control (assumming a maximum instruction length of 8). After the sort, these 9 characters are cut. For ease of understanding, I posted the unsorted intermediate output followed by the actual final output.awk 'BEGIN \ { array16["mov"]=1 array16["sub"]=1 array16["push"]=1 }{ if (!match($1,":")) next instr=$3 if (match(instr,"^[0-9]")) next if (instr in array16) instr16[instr]++ else instr32[instr]++ } END \ { print "A 16-bit instructions" for (i in instr16) printf "A%-10s%-8s %4d occurrences\n",i,i,instr16[i] print "B" print "B 32-bit instructions" for (i in instr32) printf "B%-10s%-8s %4d occurrences\n",i,i,instr32[i] }' program.txt | sort | cut -c10- A 16-bit instructions Amov mov 2 occurrences Asub sub 1 occurrences Apush push 1 occurrences B B 32-bit instructions Bstrb strb 2 occurrences Bstr str 1 occurrences 16-bit instructions mov 2 occurrences push 1 occurrences sub 1 occurrences32-bit instructions str 1 occurrences strb 2 occurrences
Report Offensive Follow Up For Removal
|
Use following form to reply to current message:
|
|

|