Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // David Choi, DC5466, Hw3
- PARSER_BEGIN(FormatDTraceProfile)
- import java.io.*;
- import java.util.*;
- public class FormatDTraceProfile {
- private static int eol = 0;
- private static String eid, rid;
- private static String sql = "insert into ibprofile (eid, rid, line, events, ticks, cpu, count, function, stack) values(";
- public static void main(String args[]) throws ParseException {
- if (args == null || args.length != 2) {
- System.err.println("Usage: FormatDTraceProfile" + " EID RID");
- System.exit(1);
- }
- eid = args[0]; rid = args[1];
- FormatDTraceProfile formatter = new FormatDTraceProfile (System.in);
- formatter.output();
- }
- }
- PARSER_END(FormatDTraceProfile)
- SKIP :
- {
- " "
- | "\t"
- }
- TOKEN:
- {
- < COLON: ":" >
- | < CPU: "CPU" >
- | < ID: "ID" >
- | < FUNC: "FUNCTION" >
- | < NAME: "NAME" >
- | < BEGIN: "BEGIN" >
- | < END: "END" >
- | < TICK: "tick-" (["0"-"9"])+ "s" >
- | < DASHES: ("-")+ >
- | < KS: "Kernel stacks" >
- | < INTEGER: (["0"-"9"])+ >
- | < STACKELEM: (["!"-"_", "a"-"~"])+ "`" (["!"-"~"])+ > // A string of any printable ascii characters (except space) that has at least one '`' character in it.
- | < EOL: "\n" | "\r" | "\n\r" | "\r\n" >
- }
- TOKEN:
- {
- <ERROR: ~[] >
- }
- void output() :
- { Token n; }
- {
- (eol())*
- process()
- }
- void process() :
- { Token events, ticks, cpu_id, count, function, stack; String stacks = ""; }
- {
- <CPU> <ID> <FUNC> <COLON> <NAME> eol()
- <INTEGER> <INTEGER> <COLON> <BEGIN> eol()
- <INTEGER> events = <INTEGER> <COLON> ticks = <TICK> eol()
- <INTEGER> <INTEGER> <COLON> <END> eol()
- <DASHES> <KS> <DASHES> eol()
- (cpu_id = <INTEGER> eol()
- function = <STACKELEM> eol() ([stack = <STACKELEM> { stacks += stack + ":"; }] eol())*
- count = <INTEGER> eol()
- {
- System.out.println(sql+eid+", "+rid+", "+eol+", "+events+", '"+ticks+"', "+cpu_id+", "+count+", '"+String.valueOf(function).replace('\'', '^')+"', '"+stacks.replace('\'', '^')+"') ;");
- stacks = "";
- } )*
- }
- void eol() :
- { }
- {
- (LOOKAHEAD(2)<EOL>)+ { eol++; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement