forked from replay/ngx_http_consistent_hash
/
tt_decay.cpp
43 lines (38 loc) · 1002 Bytes
/
tt_decay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// main.cpp
// tt_decay
//
// Created by Andrew Thomson on 10/30/13.
// Copyright (c) 2013 Andrew Thomson. All rights reserved.
//
#include <iostream>
#include <fstream>
#include "top_talkers.h"
#include "counter.h"
typedef top_talkers<int, counter> tt_type;
int main(int argc, const char * argv[])
{
if (argc < 3) {
std::cout<<"Usage: "<<argv[0]<<"size decay_period input"<<std::endl;
return 1;
}
int size = atoi(argv[1]);
int decay = atoi(argv[2]);
std::ifstream infile(argv[3]);
tt_type tt(size);
specified_timesource ts(0.0);
int timestamp;
int conv_id;
int last_dump = 0;
while(infile >> timestamp >> conv_id) {
if (last_dump + decay < timestamp) {
last_dump = timestamp;
std::cout << "Dump "<<timestamp <<std::endl;
top_talkers_print<int, counter>(tt);
}
ts.set(timestamp);
counter dc(ts, 1.0, decay);
tt.update(conv_id, dc);
}
return 0;
}