Skip to content

Commit

Permalink
Merge pull request #36 from lpgauth/parse_transform
Browse files Browse the repository at this point in the history
Add parse transform to pre-compute packet (best effort)
  • Loading branch information
lpgauth authored Nov 6, 2016
2 parents b0beb37 + 93c9b4e commit 3007875
Show file tree
Hide file tree
Showing 25 changed files with 587 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ language: erlang
notifications:
email: false
otp_release:
- 19.1
- 18.3
- 17.5
script: "make travis"
sudo: false
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ High Performance Erlang StatsD Client
### Features

* Performance optimized
* Parse transform

## API
<a href="https://github.com/lpgauth/statsderl/blob/master/doc/statsderl.md#index" class="module">Function Index</a>
Expand Down Expand Up @@ -74,6 +75,13 @@ High Performance Erlang StatsD Client
</tr>
</table>

## Parse Transform

`statsderl_transform` is used to pre-compute (at compile time) the scaled sample rate and `StatsD` packet.

```erlang
-compile({parse_transform, statsderl_transform}).
```
## Examples

```erlang
Expand Down Expand Up @@ -120,10 +128,6 @@ ok.
make test
```

### TODOs

* parse transform for type conversion

## License

```license
Expand Down
Binary file modified bin/rebar3
Binary file not shown.
5 changes: 3 additions & 2 deletions doc/edoc-info
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%% encoding: UTF-8
{application,statsderl}.
{modules,[statsderl,statsderl_app,statsderl_protocol,statsderl_server,
statsderl_sup,statsderl_udp,statsderl_utils]}.
{modules,[statsderl,statsderl_app,statsderl_pool,statsderl_protocol,
statsderl_server,statsderl_sup,statsderl_transform,statsderl_udp,
statsderl_utils]}.
20 changes: 10 additions & 10 deletions doc/statsderl.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ value() = number()
### counter/3 ###

<pre><code>
counter(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
counter(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -65,7 +65,7 @@ counter(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()
### decrement/3 ###

<pre><code>
decrement(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
decrement(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -74,7 +74,7 @@ decrement(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value
### gauge/3 ###

<pre><code>
gauge(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
gauge(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -83,7 +83,7 @@ gauge(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</
### gauge_decrement/3 ###

<pre><code>
gauge_decrement(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
gauge_decrement(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -92,7 +92,7 @@ gauge_decrement(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value"
### gauge_increment/3 ###

<pre><code>
gauge_increment(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
gauge_increment(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -101,7 +101,7 @@ gauge_increment(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value"
### increment/3 ###

<pre><code>
increment(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
increment(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -110,7 +110,7 @@ increment(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value
### timing/3 ###

<pre><code>
timing(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
timing(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -119,7 +119,7 @@ timing(Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()<
### timing_fun/3 ###

<pre><code>
timing_fun(Key::<a href="#type-key">key()</a>, Fun::function(), SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
timing_fun(Key::<a href="#type-key">key()</a>, Fun::function(), Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -128,7 +128,7 @@ timing_fun(Key::<a href="#type-key">key()</a>, Fun::function(), SampleRate::<a h
### timing_now/3 ###

<pre><code>
timing_now(Key::<a href="#type-key">key()</a>, Timestamp::<a href="erlang.md#type-timestamp">erlang:timestamp()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
timing_now(Key::<a href="#type-key">key()</a>, Timestamp::<a href="erlang.md#type-timestamp">erlang:timestamp()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

Expand All @@ -137,7 +137,7 @@ timing_now(Key::<a href="#type-key">key()</a>, Timestamp::<a href="erlang.md#typ
### timing_now_us/3 ###

<pre><code>
timing_now_us(Key::<a href="#type-key">key()</a>, Timestamp::<a href="erlang.md#type-timestamp">erlang:timestamp()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
timing_now_us(Key::<a href="#type-key">key()</a>, Timestamp::<a href="erlang.md#type-timestamp">erlang:timestamp()</a>, Rate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; ok
</code></pre>
<br />

90 changes: 90 additions & 0 deletions doc/statsderl_pool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@


# Module statsderl_pool #
* [Data Types](#types)
* [Function Index](#index)
* [Function Details](#functions)

<a name="types"></a>

## Data Types ##




### <a name="type-key">key()</a> ###


<pre><code>
key() = iodata()
</code></pre>




### <a name="type-operation">operation()</a> ###


<pre><code>
operation() = {cast, iodata()} | {counter, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>, <a href="#type-sample_rate">sample_rate()</a>} | {gauge, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>} | {gauge_decrement, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>} | {gauge_increment, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>} | {timing, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>} | {timing_now, <a href="#type-key">key()</a>, <a href="erlang.md#type-timestamp">erlang:timestamp()</a>} | {timing_now_us, <a href="#type-key">key()</a>, <a href="erlang.md#type-timestamp">erlang:timestamp()</a>}
</code></pre>




### <a name="type-sample_rate">sample_rate()</a> ###


<pre><code>
sample_rate() = number()
</code></pre>




### <a name="type-value">value()</a> ###


<pre><code>
value() = number()
</code></pre>

<a name="index"></a>

## Function Index ##


<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#sample-2">sample/2</a></td><td></td></tr><tr><td valign="top"><a href="#sample_scaled-2">sample_scaled/2</a></td><td></td></tr><tr><td valign="top"><a href="#server_name-1">server_name/1</a></td><td></td></tr></table>


<a name="functions"></a>

## Function Details ##

<a name="sample-2"></a>

### sample/2 ###

<pre><code>
sample(Rate::<a href="#type-sample_rate">sample_rate()</a>, Operation::<a href="#type-operation">operation()</a>) -&gt; ok
</code></pre>
<br />

<a name="sample_scaled-2"></a>

### sample_scaled/2 ###

<pre><code>
sample_scaled(RateInt::non_neg_integer(), Operation::<a href="#type-operation">operation()</a>) -&gt; ok
</code></pre>
<br />

<a name="server_name-1"></a>

### server_name/1 ###

<pre><code>
server_name(X1::1..4) -&gt; atom()
</code></pre>
<br />

12 changes: 6 additions & 6 deletions doc/statsderl_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ key() = iodata()



### <a name="type-op_code">op_code()</a> ###
### <a name="type-operation">operation()</a> ###


<pre><code>
op_code() = decrement | gauge | gauge_decrement | gauge_increment | increment | timing
operation() = {cast, iodata()} | {counter, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>, <a href="#type-sample_rate">sample_rate()</a>} | {gauge, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>} | {gauge_decrement, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>} | {gauge_increment, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>} | {timing, <a href="#type-key">key()</a>, <a href="#type-value">value()</a>} | {timing_now, <a href="#type-key">key()</a>, <a href="erlang.md#type-timestamp">erlang:timestamp()</a>} | {timing_now_us, <a href="#type-key">key()</a>, <a href="erlang.md#type-timestamp">erlang:timestamp()</a>}
</code></pre>


Expand Down Expand Up @@ -54,19 +54,19 @@ value() = number()
## Function Index ##


<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#encode-4">encode/4</a></td><td></td></tr></table>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#encode-1">encode/1</a></td><td></td></tr></table>


<a name="functions"></a>

## Function Details ##

<a name="encode-4"></a>
<a name="encode-1"></a>

### encode/4 ###
### encode/1 ###

<pre><code>
encode(X1::<a href="#type-op_code">op_code()</a>, Key::<a href="#type-key">key()</a>, Value::<a href="#type-value">value()</a>, SampleRate::<a href="#type-sample_rate">sample_rate()</a>) -&gt; iodata()
encode(X1::<a href="#type-operation">operation()</a>) -&gt; iodata()
</code></pre>
<br />

42 changes: 42 additions & 0 deletions doc/statsderl_transform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@


# Module statsderl_transform #
* [Data Types](#types)
* [Function Index](#index)
* [Function Details](#functions)

<a name="types"></a>

## Data Types ##




### <a name="type-forms">forms()</a> ###


<pre><code>
forms() = [<a href="erl_parse.md#type-abstract_form">erl_parse:abstract_form()</a> | <a href="erl_parse.md#type-form_info">erl_parse:form_info()</a>]
</code></pre>

<a name="index"></a>

## Function Index ##


<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#parse_transform-2">parse_transform/2</a></td><td></td></tr></table>


<a name="functions"></a>

## Function Details ##

<a name="parse_transform-2"></a>

### parse_transform/2 ###

<pre><code>
parse_transform(Forms::<a href="#type-forms">forms()</a>, Options::[<a href="compile.md#type-option">compile:option()</a>]) -&gt; <a href="#type-forms">forms()</a>
</code></pre>
<br />

11 changes: 1 addition & 10 deletions doc/statsderl_udp.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## Function Index ##


<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#header-2">header/2</a></td><td></td></tr><tr><td valign="top"><a href="#send-3">send/3</a></td><td></td></tr></table>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#header-2">header/2</a></td><td></td></tr></table>


<a name="functions"></a>
Expand All @@ -25,12 +25,3 @@ header(IP::<a href="inet.md#type-ip_address">inet:ip_address()</a>, Port::<a hre
</code></pre>
<br />

<a name="send-3"></a>

### send/3 ###

<pre><code>
send(Socket::<a href="inet.md#type-socket">inet:socket()</a>, Header::iodata(), Data::iodata()) -&gt; ok | {error, term()}
</code></pre>
<br />

29 changes: 10 additions & 19 deletions doc/statsderl_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ base_key_part() = hostname | name | sname | undefined | iodata()
## Function Index ##


<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#base_key-1">base_key/1</a></td><td></td></tr><tr><td valign="top"><a href="#error_msg-2">error_msg/2</a></td><td></td></tr><tr><td valign="top"><a href="#getaddrs-1">getaddrs/1</a></td><td></td></tr><tr><td valign="top"><a href="#random-1">random/1</a></td><td></td></tr><tr><td valign="top"><a href="#random_element-1">random_element/1</a></td><td></td></tr><tr><td valign="top"><a href="#random_server-0">random_server/0</a></td><td></td></tr><tr><td valign="top"><a href="#server_name-1">server_name/1</a></td><td></td></tr><tr><td valign="top"><a href="#timestamp-0">timestamp/0</a></td><td></td></tr></table>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#base_key-1">base_key/1</a></td><td></td></tr><tr><td valign="top"><a href="#error_msg-2">error_msg/2</a></td><td></td></tr><tr><td valign="top"><a href="#getaddrs-1">getaddrs/1</a></td><td></td></tr><tr><td valign="top"><a href="#random_element-1">random_element/1</a></td><td></td></tr><tr><td valign="top"><a href="#timestamp-0">timestamp/0</a></td><td></td></tr><tr><td valign="top"><a href="#timing_now-1">timing_now/1</a></td><td></td></tr><tr><td valign="top"><a href="#timing_now_us-1">timing_now_us/1</a></td><td></td></tr></table>


<a name="functions"></a>
Expand Down Expand Up @@ -68,15 +68,6 @@ getaddrs(Address::<a href="inet.md#type-ip_address">inet:ip_address()</a> | <a h
</code></pre>
<br />

<a name="random-1"></a>

### random/1 ###

<pre><code>
random(N::pos_integer()) -&gt; pos_integer()
</code></pre>
<br />

<a name="random_element-1"></a>

### random_element/1 ###
Expand All @@ -86,30 +77,30 @@ random_element(List::[term()]) -&gt; term()
</code></pre>
<br />

<a name="random_server-0"></a>
<a name="timestamp-0"></a>

### random_server/0 ###
### timestamp/0 ###

<pre><code>
random_server() -&gt; atom()
timestamp() -&gt; <a href="erlang.md#type-timestamp">erlang:timestamp()</a>
</code></pre>
<br />

<a name="server_name-1"></a>
<a name="timing_now-1"></a>

### server_name/1 ###
### timing_now/1 ###

<pre><code>
server_name(X1::pos_integer()) -&gt; atom()
timing_now(Timestamp::<a href="erlang.md#type-timestamp">erlang:timestamp()</a>) -&gt; non_neg_integer()
</code></pre>
<br />

<a name="timestamp-0"></a>
<a name="timing_now_us-1"></a>

### timestamp/0 ###
### timing_now_us/1 ###

<pre><code>
timestamp() -&gt; <a href="erlang.md#type-timestamp">erlang:timestamp()</a>
timing_now_us(Timestamp::<a href="erlang.md#type-timestamp">erlang:timestamp()</a>) -&gt; non_neg_integer()
</code></pre>
<br />

Loading

0 comments on commit 3007875

Please sign in to comment.