Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 15 files changed
  • 0 comments
  • 1 contributor
46 libinstrument/datastore.cpp
@@ -135,23 +135,20 @@ void DataStore::registerHealth(time_interval_t time,
135 135 if(canStore(obj_size)) {
136 136 OracleResult::ptr o_res(new OracleResult(time - i_time, o_id, health, confidence));
137 137
138   - thread_info[id]->addOracleResult(o_res);
139   -
140   - current_storage_size += obj_size;
141   -
142   - debug("Thread %ld, Oracle %ld: Registered Oracle Result (Health: %f, Confidence: %f), Storage: %f%%",
143   - id,
144   - o_id,
145   - health,
146   - confidence,
147   - 100.0 * current_storage_size / max_storage_size);
  138 + if(thread_info[id]->addOracleResult(o_res)) {
  139 + current_storage_size += obj_size;
  140 +
  141 + debug("Thread %ld, Oracle %ld: Registered Oracle Result (Health: %f, Confidence: %f), Storage: %f%%",
  142 + id, o_id, health, confidence,
  143 + 100.0 * current_storage_size / max_storage_size);
  144 + }
  145 + else
  146 + debug("Thread %ld, Oracle %ld: Ignored Oracle Result (Health: %f, Confidence: %f)",
  147 + id, o_id, health, confidence);
148 148 }
149 149 else {
150 150 debug("Thread %ld, Oracle %ld: Dropped Oracle Result (Health: %f, Confidence: %f), Storage: Full(%f%%)",
151   - id,
152   - o_id,
153   - health,
154   - confidence,
  151 + id, o_id, health, confidence,
155 152 100.0 * current_storage_size / max_storage_size);
156 153 }
157 154
@@ -192,19 +189,20 @@ void DataStore::commitObservation(pthread_t pthread_id) {
192 189
193 190 size_t obj_size = sizeof(Observation) + obs->size();
194 191 if(canStore(obj_size)) {
195   - current_storage_size += obj_size;
196   - thread_info[id]->addObservation(obs);
197   - debug("Thread %ld, Probe %ld: Commited Observation with size %ld, Storage: %f%%",
198   - id,
199   - obs->p_id,
200   - obs->size(),
201   - 100.0 * current_storage_size / max_storage_size);
  192 + if(thread_info[id]->addObservation(obs)){
  193 + current_storage_size += obj_size;
  194 +
  195 + debug("Thread %ld, Probe %ld: Commited Observation with size %ld, Storage: %f%%",
  196 + id, obs->p_id, obs->size(),
  197 + 100.0 * current_storage_size / max_storage_size);
  198 + }
  199 + else
  200 + debug("Thread %ld, Probe %ld: Ignored Observation with size %ld",
  201 + id, obs->p_id, obs->size());
202 202 }
203 203 else {
204 204 debug("Thread %ld, Probe %ld: Dropped Observation with size %ld, Storage: Full(%f%%)",
205   - id,
206   - obs->p_id,
207   - obs->size(),
  205 + id, obs->p_id, obs->size(),
208 206 100.0 * current_storage_size / max_storage_size);
209 207 }
210 208 observation_buffer.erase(id);
86 libinstrument/datastore/allocationmonitor.h
... ... @@ -1,86 +0,0 @@
1   -#pragma once
2   -
3   -#include "../types.h"
4   -
5   -#include <map>
6   -#include <boost/shared_ptr.hpp>
7   -
8   -using namespace std;
9   -
10   -template <class StoredType, class OwnerType>
11   -class AllocationMonitor {
12   - class Item {
13   - public:
14   - boost::shared_ptr<StoredType> obs;
15   - size_t size;
16   - OwnerType owner;
17   -
18   - inline Item(boost::shared_ptr<StoredType> obs,
19   - size_t size,
20   - const OwnerType & owner){
21   - this->obs = obs;
22   - this->size = size;
23   - this->owner = owner;
24   - }
25   - };
26   -
27   - typedef map<alloc_id_t, Item> storage_t;
28   -
29   - size_t max_bytes;
30   - size_t occupancy;
31   - alloc_id_t uid;
32   -
33   - storage_t storage;
34   -
35   -public:
36   -
37   - inline AllocationMonitor(size_t max_bytes) {
38   - this->max_bytes = max_bytes;
39   - this->occupancy = 0;
40   - this->uid = 0;
41   - }
42   -
43   - inline bool canStore(size_t size) const {
44   - return max_bytes >= size + occupancy;
45   - }
46   -
47   - inline size_t getOccupancy() const {
48   - return occupancy;
49   - }
50   -
51   - inline size_t getSize() const {
52   - return max_bytes;
53   - }
54   -
55   - inline void softResize(size_t size) {
56   - max_bytes = size;
57   - }
58   -
59   - inline void resize(size_t size) {
60   - assert(occupancy <= size);
61   -
62   - if(occupancy <= size)
63   - max_bytes = size;
64   - }
65   -
66   - inline alloc_id_t store(boost::shared_ptr<StoredType> obs, size_t size, const OwnerType & owner) {
67   - assert(canStore(size));
68   -
69   - observation_id_t id = ++uid;
70   - occupancy += size;
71   - storage.insert(typename storage_t::value_type(id, Item(obs, size, owner)));
72   -
73   - return id;
74   - }
75   -
76   - inline OwnerType * free(observation_id_t observation_id) {
77   - typename storage_t::iterator it = storage.find(observation_id);
78   -
79   - assert(it != storage.end());
80   -
81   - OwnerType * ret = it->second.owner;
82   - storage.erase(it);
83   - return ret;
84   - }
85   -
86   -};
12 libinstrument/datastore/threadinfo.cpp
@@ -6,14 +6,22 @@ ThreadInfo::ThreadInfo(time_interval_t start, thread_id_t parent_id) {
6 6 this->parent_id = parent_id;
7 7 }
8 8
9   -void ThreadInfo::addObservation(Observation::const_ptr obs){
  9 +bool ThreadInfo::addObservation(Observation::const_ptr obs){
10 10 assert(observations.empty() || obs->time > observations.back()->time);
  11 + if(transaction_stack.empty()) //Drop observations that are not related to any transaction
  12 + return false;
  13 +
11 14 observations.push_back(obs);
  15 + return true;
12 16 }
13 17
14   -void ThreadInfo::addOracleResult(OracleResult::const_ptr o_res){
  18 +bool ThreadInfo::addOracleResult(OracleResult::const_ptr o_res){
15 19 assert(oracle_results.empty() || o_res->time > oracle_results.back()->time);
  20 + if(transaction_stack.empty()) //Drop oracle results that are not related to any transaction
  21 + return false;
  22 +
16 23 oracle_results.push_back(o_res);
  24 + return true;
17 25 }
18 26
19 27 void ThreadInfo::pushTransaction(){
4 libinstrument/datastore/threadinfo.h
@@ -31,9 +31,9 @@ class ThreadInfo {
31 31 ThreadInfo(time_interval_t launch_time,
32 32 thread_id_t parent_id);
33 33
34   - void addObservation(Observation::const_ptr obs);
  34 + bool addObservation(Observation::const_ptr obs);
35 35
36   - void addOracleResult(OracleResult::const_ptr o_res);
  36 + bool addOracleResult(OracleResult::const_ptr o_res);
37 37
38 38 void pushTransaction();
39 39 void pushTransaction(Transaction::ptr tr);
2  libinstrument/instrument.h
@@ -57,7 +57,7 @@
57 57 #else
58 58
59 59 #define instr_pmetadata(key, value) (_instr_probe_register_metadata(0, (key), (value));)
60   -#define instr_var(item) (_instr_probe_read((void *)&(item), sizeof(item));)
  60 +#define instr_pvar(item) (_instr_probe_read((void *)&(item), sizeof(item));)
61 61
62 62 #define instr_probe(items...) { \
63 63 _instr_probe_observation_register(0);\
42 libinstrument/io/graphviz.cpp
@@ -17,22 +17,37 @@ static const char GvizObservationPre[] = "Observation";
17 17 static const char GvizOracleResultPre[] = "OracleResult";
18 18 #include "../utils/debug.h"
19 19
  20 +ostream & GvizRGBA(ostream & out, float r, float g, float b, float a) {
  21 + ios::fmtflags flags = out.flags();
  22 + char fill = out.fill('0');
  23 +
  24 + out << hex;
  25 + out << setw(2) << (unsigned) (255 * r);
  26 + out << setw(2) << (unsigned) (255 * g);
  27 + out << setw(2) << (unsigned) (255 * b);
  28 + out << setw(2) << (unsigned) (255 * a);
  29 +
  30 + out.fill(fill);
  31 + out.flags(flags);
  32 + return out;
  33 +
  34 +}
  35 +
20 36 ostream & GvizStateLabel(ostream & out, const State & st) {
21 37 ios::fmtflags flags = out.flags();
  38 + char fill = out.fill('0');
22 39
23 40 out << "Data: ";
24 41 out << hex;
25 42 size_t i = 0;
26 43 for(size_t j = 0; j < st.n_vars; j++) {
27 44 out << " | ";
28   - for(size_t k = st.offset_end[j]; k-- > i;){
29   - out << (unsigned)st.data[k];
30   - if((k - i) % 2 == 0)
31   - out << ".";
32   - }
  45 + for(size_t k = st.offset_end[j]; k-- > i;)
  46 + out << setw(2) << (unsigned)st.data[k];
33 47 i=st.offset_end[j];
34 48 }
35 49 out << " | ";
  50 + out.fill(fill);
36 51 out.flags(flags);
37 52 return out;
38 53 }
@@ -71,23 +86,6 @@ ostream & GvizObservationLinks(ostream & out, thread_id_t t_id, const ThreadInfo
71 86 return out;
72 87 }
73 88
74   -ostream & GvizRGBA(ostream & out, float r, float g, float b, float a) {
75   - ios::fmtflags flags = out.flags();
76   - streamsize width = out.width(2);
77   - char fill = out.fill('0');
78   -
79   - out << hex;
80   - out << setw(2) << (unsigned) (255 * r);
81   - out << setw(2) << (unsigned) (255 * g);
82   - out << setw(2) << (unsigned) (255 * b);
83   - out << setw(2) << (unsigned) (255 * a);
84   -
85   - out.fill(fill);
86   - out.width(width);
87   - out.flags(flags);
88   - return out;
89   -
90   -}
91 89
92 90 ostream & GvizOracleResults(ostream & out, thread_id_t t_id, const ThreadInfo & thr) {
93 91 size_t oracle_result_id = 0;
50 libinstrument/io/spectra.cpp
@@ -3,16 +3,33 @@
3 3 #include "../types.h"
4 4 #include "../utils/stl.h"
5 5
  6 +#include <iomanip>
  7 +
  8 +inline ostream & StateSpectraVariable(ostream & out,
  9 + const void * buf,
  10 + size_t left,
  11 + size_t right) {
  12 + ios::fmtflags flags = out.flags();
  13 + char fill = out.fill('0');
  14 + out << hex << "0x";
  15 + while(right-- > left)
  16 + out << setw(2) << (unsigned)((const unsigned char*)buf)[right];
  17 + out.fill(fill);
  18 + out.flags(flags);
  19 + return out;
  20 +}
  21 +
6 22 inline ostream & StateSpectraState(ostream & out,
7 23 const State & st){
8   - ios::fmtflags flags = out.flags();
  24 +
9 25 size_t i = 0;
10 26 for(size_t j = 0; j < st.n_vars; j++) {
11   - out << "," << j << ":";
12   - for(;i < st.offset_end[j]; i++)
13   - out << (unsigned)st.data[i];
  27 + out << "|";
  28 + StateSpectraVariable(out, st.data, i,
  29 + st.offset_end[j]);
  30 + i=st.offset_end[j];
14 31 }
15   - out.flags(flags);
  32 +
16 33 return out;
17 34 }
18 35
@@ -21,15 +38,14 @@ inline ostream & StateSpectraObservation(ostream & out,
21 38 const Observation & obs){
22 39
23 40 out << "obs,";
24   - out << t_id << ",";
25   - out << obs.time << ",";
26 41 out << obs.p_id << ",";
27   - if(obs.state) {
28   - out << obs.state->n_vars << "";
  42 + out << t_id << ",";
  43 + out << "\"";
  44 + unsigned long time = obs.time;
  45 + StateSpectraVariable(out, &time, 0, sizeof(time));
  46 + if(obs.state)
29 47 StateSpectraState(out, *obs.state);
30   - }
31   - else
32   - out << "0";
  48 + out << "\"";
33 49 return out;
34 50 }
35 51
@@ -38,11 +54,12 @@ inline ostream & StateSpectraOracleResult(ostream & out,
38 54 const OracleResult & o_res){
39 55
40 56 out << "or,";
41   - out << t_id << ",";
42   - out << o_res.time << ",";
43 57 out << o_res.o_id << ",";
44   - out << o_res.health << ",";
45   - out << o_res.confidence;
  58 + out << t_id << ",\"";
  59 + unsigned long time = o_res.time;
  60 + StateSpectraVariable(out, &time, 0, sizeof(time)) << "|";
  61 + out << o_res.health << "|";
  62 + out << o_res.confidence <<"\"";
46 63 return out;
47 64 }
48 65
@@ -96,6 +113,7 @@ inline ostream & StateSpectraArtifacts(ostream & out,
96 113 }
97 114
98 115 ostream & StateSpectra(ostream & out, const DataStore & ds) {
  116 + out << "type, id, first, second\n";
99 117 StateSpectraArtifacts(out, "metapr", ds.probe_metadata);
100 118 StateSpectraArtifacts(out, "metatg", ds.transaction_gate_metadata);
101 119 StateSpectraArtifacts(out, "metaor", ds.oracle_metadata);
2  run_test.sh
@@ -2,7 +2,7 @@
2 2
3 3 BIN_DIR="obj/bin"
4 4 TESTS_DIR="tests"
5   -RUNNER_NAME="run.sh"
  5 +[[ -z $RUNNER_NAME ]] && RUNNER_NAME="run.sh"
6 6
7 7 if [[ $# == 0 ]]; then
8 8 echo "Missing test name" >&2
8 tests/fractal/thread.cpp
@@ -22,16 +22,16 @@ void *threadify(void * v) {
22 22 instr_transaction_start(instr_void);
23 23 for(int i = 0; i < args->count; i++){
24 24 int tmp = rand();
25   - instr_probe(instr_var(i),
26   - instr_var(tmp),
  25 + instr_probe(instr_pvar(i),
  26 + instr_pvar(tmp),
27 27 instr_pmetadata("Name", "Launcher loop"),
28 28 instr_pmetadata("ComponentID", "1234"));
29 29
30 30 pthread_create(&thread[i], NULL, threadify, (void*)args->levelDown());
31   -
  31 +
32 32 instr_oracle(1 - (i + 0.0) / (args->count - 1), (i + 0.0) / (args->count - 1), instr_void);
33 33 if(args->load) load();
34   - if(args->load)
  34 + if(args->load)
35 35 instr_probe(instr_void);
36 36 }
37 37 instr_transaction_end(instr_void);
6 tests/webfs/SConscript
@@ -33,8 +33,8 @@ def buildWebfs(target, passes):
33 33 bin_install = env.Install(build_info['build_dir'] + "/bin", obj)
34 34 env.Default(bin_install)
35 35
36   -buildWebfs('webfsd', "-instrument_prepare")
37   -#buildWebfs('webfsd_function', "-instrument_function -instrument_prepare")
38   -#buildWebfs('webfsd_block', "-instrument_block -instrument_prepare")
  36 +#buildWebfs('webfsd', "-instrument_prepare")
  37 +buildWebfs('webfsd', "-instrument_function -instrument_prepare")
  38 +#buildWebfs('webfsd', "-instrument_block -instrument_prepare")
39 39
40 40
33 tests/webfs/bug.c
... ... @@ -0,0 +1,33 @@
  1 +#include "bug.h"
  2 +
  3 +#include <libinstrument/instrument.h>
  4 +#include <stdlib.h>
  5 +
  6 +
  7 +pthread_mutex_t leak_init_lock=PTHREAD_MUTEX_INITIALIZER;
  8 +
  9 +void _leak_init(leak_t ** l, size_t min, size_t max, size_t total) {
  10 + if(*l != NULL)
  11 + return;
  12 +
  13 + *l = (leak_t *) malloc(sizeof(leak_t));
  14 +
  15 + (*l)->min = min;
  16 + (*l)->max = max;
  17 + (*l)->total = total;
  18 +
  19 + (*l)->leakage_total = 0;
  20 + (*l)->leakage_count = 0;
  21 +
  22 + (*l)->start_time = time(NULL);
  23 + pthread_mutex_init(&((*l)->lock), NULL);
  24 +}
  25 +
  26 +void _leak(leak_t * l){
  27 + l->leakage_total += l->min + (size_t) (rand() / (float) RAND_MAX * (l->max - l->min));
  28 + l->leakage_count++;
  29 +
  30 + instr_oracle(l->leakage_total < l->total,
  31 + 1,
  32 + instr_void);
  33 +}
48 tests/webfs/bug.h
... ... @@ -0,0 +1,48 @@
  1 +#ifndef __BUG_H__
  2 +#define __BUG_H__
  3 +
  4 +#include <pthread.h>
  5 +#include <time.h>
  6 +
  7 +typedef struct {
  8 + //Parameters
  9 + size_t min;
  10 + size_t max;
  11 + size_t total;
  12 +
  13 + //Counters
  14 + size_t leakage_total;
  15 + size_t leakage_count;
  16 +
  17 + time_t start_time;
  18 + //Lock
  19 + pthread_mutex_t lock;
  20 +} leak_t;
  21 +
  22 +extern pthread_mutex_t leak_init_lock;
  23 +
  24 +
  25 +#define leak(min, max, total){\
  26 + static leak_t * l;\
  27 + leak_shared(l, min, max, total);\
  28 +}
  29 +
  30 +#define leak_shared(l, min, max, total){\
  31 + pthread_mutex_lock(&leak_init_lock);\
  32 + _leak_init(&(l), min, max, total);\
  33 + pthread_mutex_unlock(&leak_init_lock);\
  34 +\
  35 + pthread_mutex_lock(&(l->lock));\
  36 +\
  37 + time_t t = time(NULL) - l->start_time;\
  38 + instr_probe(instr_pvar(l->leakage_count), \
  39 + instr_pvar(t), \
  40 + instr_pmetadata("Name", "Bug"));\
  41 + _leak(l);\
  42 + pthread_mutex_unlock(&(l->lock));\
  43 +}
  44 +
  45 +void _leak(leak_t * l);
  46 +void _leak_init(leak_t ** l, size_t min, size_t max, size_t total);
  47 +
  48 +#endif
28 tests/webfs/generate_spectra.sh
... ... @@ -0,0 +1,28 @@
  1 +#!/bin/bash
  2 +
  3 +HTTPD_ROOT=".hroot"
  4 +
  5 +BIG_FILE="$HTTPD_ROOT/big"
  6 +SMALL_FILE="$HTTPD_ROOT/small"
  7 +
  8 +HTTPD_EXEC="webfsd"
  9 +HTTPD_ARGS="-p 8090 -Fr$HTTPD_ROOT -y10"
  10 +
  11 +
  12 +[[ ! -e $HTTPD_ROOT ]] && mkdir -p $HTTPD_ROOT
  13 +[[ ! -e $BIG_FILE ]] && head -c 200M /dev/zero > $BIG_FILE
  14 +[[ ! -e $SMALL_FILE ]] && head -c 200K /dev/zero > $SMALL_FILE
  15 +
  16 +for ((obs=0; obs<20; obs++)); do
  17 + $* $HTTPD_EXEC $HTTPD_ARGS & # 2>/dev/null &
  18 + pid=$!
  19 + sleep 1
  20 + for ((transactions = 0; transactions < 20; transactions++)); do
  21 + curl 127.0.0.1:8090 > /dev/null 2>/dev/null
  22 + done
  23 + echo -n "state" | nc 127.0.0.1 12345 > $obs.log
  24 + kill -9 $pid
  25 + sleep 1
  26 +done
  27 +#gdb ./$HTTPD_DIR/$HTTPD_EXEC $HTTPD_ARGS
  28 +#valgrind -v --leak-check=full ./$HTTPD_DIR/$HTTPD_EXEC $HTTPD_ARGS
2  tests/webfs/request.c
@@ -15,7 +15,6 @@
15 15
16 16 #include "httpd.h"
17 17
18   -#include <libinstrument/instrument.h>
19 18 /* ---------------------------------------------------------------------- */
20 19
21 20 void
@@ -25,7 +24,6 @@ read_request(struct REQUEST *req, int pipelined)
25 24 char *h;
26 25
27 26 restart:
28   - instr_probe(instr_void);
29 27 #ifdef USE_SSL
30 28 if (with_ssl)
31 29 rc = ssl_read(req, req->hreq + req->hdata, MAX_HEADER - req->hdata);
13 tests/webfs/webfsd.c
@@ -20,9 +20,11 @@
20 20 #include <netinet/tcp.h>
21 21 #include <arpa/inet.h>
22 22 #include <netdb.h>
23   -#include <libinstrument/instrument.h>
24 23 #include "httpd.h"
25 24
  25 +#include <libinstrument/instrument.h>
  26 +#include "bug.h"
  27 +
26 28 /* ---------------------------------------------------------------------- */
27 29 /* public variables - server configuration */
28 30
@@ -305,7 +307,6 @@ syslog_init(void)
305 307 static void
306 308 syslog_start(void)
307 309 {
308   - instr_probe(instr_pmetadata("name", "syslog_start"));
309 310 syslog(LOG_NOTICE,
310 311 "started (listen on %s:%d, root=%s, user=%s, group=%s)\n",
311 312 listen_ip ? listen_ip : "*",
@@ -369,7 +370,6 @@ xerror(int loglevel, char *txt, char *peerhost)
369 370 static void*
370 371 mainloop(void *thread_arg)
371 372 {
372   - instr_transaction_start(instr_void);
373 373 struct REQUEST *conns = NULL;
374 374 int curr_conn = 0;
375 375
@@ -456,7 +456,6 @@ mainloop(void *thread_arg)
456 456 xperror(LOG_WARNING,"accept",NULL);
457 457 free(req);
458 458 } else {
459   - instr_transaction_start(instr_void);
460 459 close_on_exec(req->fd);
461 460 fcntl(req->fd,F_SETFL,O_NONBLOCK);
462 461 req->bfd = -1;
@@ -483,14 +482,14 @@ mainloop(void *thread_arg)
483 482 if (debug)
484 483 fprintf(stderr,"%03d: connect from (%s)\n",
485 484 req->fd,req->peerhost);
486   - instr_oracle(1, 1, instr_void);
487   - instr_transaction_end(instr_void);
488 485 }
489 486 }
490 487 }
491 488
492 489 /* check active connections */
493 490 for (req = conns, prev = NULL; req != NULL;) {
  491 + instr_transaction_start(instr_void);
  492 + leak(0, 10, 100);
494 493 /* handle I/O */
495 494 switch (req->state) {
496 495 case STATE_KEEPALIVE:
@@ -673,9 +672,9 @@ mainloop(void *thread_arg)
673 672 prev = req;
674 673 req = req->next;
675 674 }
  675 + instr_transaction_end(instr_void);
676 676 }
677 677 }
678   - instr_transaction_end(instr_void);
679 678 return NULL;
680 679 }
681 680

No commit comments for this range

Something went wrong with that request. Please try again.