Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. // David Choi, DC5466, Hw3
  2. PARSER_BEGIN(FormatDTraceProfile)
  3.  
  4. import java.io.*;
  5. import java.util.*;
  6.  
  7. public class FormatDTraceProfile {
  8.     private static int eol = 0;
  9.     private static String eid, rid;
  10.     private static String sql = "insert into ibprofile (eid, rid, line, events, ticks, cpu, count, function, stack) values(";
  11.     public static void main(String args[]) throws ParseException {
  12.        if (args == null || args.length != 2) {
  13.           System.err.println("Usage: FormatDTraceProfile" + " EID RID");
  14.           System.exit(1);      
  15.        }
  16.        eid = args[0]; rid = args[1];
  17.        FormatDTraceProfile formatter = new FormatDTraceProfile (System.in);
  18.        formatter.output();
  19.     }
  20. }
  21.  
  22. PARSER_END(FormatDTraceProfile)
  23.  
  24. SKIP :
  25. {
  26.     " "
  27.   | "\t"
  28. }
  29.  
  30. TOKEN:
  31. {
  32.     < COLON:    ":" >
  33.   | < CPU:      "CPU" >
  34.   | < ID:       "ID" >
  35.   | < FUNC:     "FUNCTION" >
  36.   | < NAME:     "NAME" >
  37.   | < BEGIN:    "BEGIN" >
  38.   | < END:      "END" >
  39.   | < TICK:     "tick-" (["0"-"9"])+ "s" >
  40.   | < DASHES:   ("-")+ >
  41.   | < KS:       "Kernel stacks" >
  42.   | < INTEGER:  (["0"-"9"])+ >
  43.   | < STACKELEM: (["!"-"_", "a"-"~"])+ "`" (["!"-"~"])+  > // A string of any printable ascii characters (except space) that has at least one '`' character in it.
  44.   | < EOL:      "\n" | "\r" | "\n\r" | "\r\n" >
  45. }
  46.  
  47. TOKEN:
  48. {
  49.     <ERROR: ~[] >
  50. }
  51.  
  52. void output() :
  53. { Token n; }
  54. {  
  55.   (eol())*
  56.   process()
  57. }
  58.  
  59. void process() :
  60. { Token events, ticks, cpu_id, count, function, stack; String stacks = ""; }
  61. {
  62.    <CPU> <ID> <FUNC> <COLON> <NAME> eol()
  63.    <INTEGER> <INTEGER> <COLON> <BEGIN> eol()
  64.    <INTEGER> events = <INTEGER> <COLON> ticks = <TICK> eol()
  65.    <INTEGER> <INTEGER> <COLON> <END> eol()
  66.    <DASHES> <KS> <DASHES> eol()
  67.    (cpu_id = <INTEGER> eol()
  68.    function = <STACKELEM> eol() ([stack = <STACKELEM> { stacks += stack + ":"; }] eol())*
  69.    count = <INTEGER> eol()
  70.    {
  71.      System.out.println(sql+eid+", "+rid+", "+eol+", "+events+", '"+ticks+"', "+cpu_id+", "+count+", '"+String.valueOf(function).replace('\'', '^')+"', '"+stacks.replace('\'', '^')+"') ;");
  72.      stacks = "";
  73.    } )*
  74. }
  75.  
  76. void eol() :
  77. { }
  78. {
  79.     (LOOKAHEAD(2)<EOL>)+ { eol++; }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement