Created
October 11, 2013 05:05
-
-
Save also/6929841 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fs = require 'fs' | |
| _ = require 'underscore' | |
| lead = require './dist/nodejs/node.js' | |
| parser = lead.require 'graphite_parser' | |
| dsl = lead.require 'dsl' | |
| filename = process.argv[2] | |
| s = fs.readFileSync filename, 'ascii' | |
| strings = {} | |
| calls = {} | |
| metrics = {} | |
| add = (a, k) -> | |
| a[k] = (a[k] ? 0) + 1 | |
| collect = (o) -> | |
| switch o.type | |
| when 's' | |
| add strings, o.values[0] | |
| when 'f' | |
| add calls, o.values[0] | |
| for a in o.values[1...] | |
| collect a | |
| when 'q' | |
| add metrics, o.values[0] | |
| for target in s.trim().split '\n' | |
| try | |
| parsed = parser.parse target | |
| #console.log JSON.stringify parsed | |
| collect parsed | |
| catch e | |
| console.log target | |
| console.log e | |
| result = {strings, calls, metrics} | |
| console.log result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment