Guest User

D log parse script - slow

a guest
Jun 9th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.11 KB | None | 0 0
  1. import std.stdio;
  2. import std.string;
  3. import std.array;
  4. import std.algorithm : splitter;
  5. import std.typecons : tuple, Tuple;
  6. import std.conv : to;
  7.  
  8. void read_log(string filename) {
  9.     File file = File(filename, "r");
  10.     Tuple!(char[], int, char[])[] npushed;
  11.     Tuple!(int, char[], int, bool, bool)[] pushed;
  12.     foreach (line; file.byLine) {
  13.         if (line.indexOf("SOC_NOT_PUSHED") != -1) {
  14.             auto tarr = line.split();
  15.             npushed ~= tuple(tarr[2] ~ tarr[3], to!int(tarr[$ - 1]), tarr[$ - 2]);
  16.             continue;
  17.         }
  18.         if (line.indexOf("SYNC_PUSH:") != -1) {
  19.             auto rel = line.split("SYNC_PUSH:")[1].strip();
  20.             auto att = rel.split(" at ");
  21.             auto ina = att[1].split(" in ");
  22.             auto msa = ina[1].split(" ms ");
  23.             pushed ~= tuple(to!int(att[0]), ina[0], to!int(msa[0]),
  24.                     msa[1].indexOf("PA-SOC_POP") != -1, msa[1].indexOf("CU-SOC_POP") != -1);
  25.         }
  26.     }
  27.     // Doing more stuff with these arrays later. For now, just printing lengths
  28.     writeln(npushed.length);
  29.     writeln(pushed.length);
  30. }
Add Comment
Please, Sign In to add comment