Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into 1.8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Jun 25, 2015
2 parents 587100d + 206ed76 commit 4de3a00
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
27 changes: 21 additions & 6 deletions vm/builtin/location.cpp
Expand Up @@ -8,6 +8,7 @@
#include "builtin/variable_scope.hpp"
#include "call_frame.hpp"
#include "ontology.hpp"
#include "on_stack.hpp"

namespace rubinius {
void Location::init(STATE) {
Expand Down Expand Up @@ -82,11 +83,22 @@ namespace rubinius {
return loc;
}

Array* Location::from_call_stack(STATE, CallFrame* start_call_frame,
Array* Location::from_call_stack(STATE, CallFrame* call_frame,
bool include_vars, bool on_ip)
{
Array* bt = Array::create(state, 5);
CallFrame* call_frame = start_call_frame;
size_t count = 0;

CallFrame* c = call_frame;
while(c) {
if(c->compiled_code) count++;
c = c->previous;
}

Array* bt = 0;
Location* loc = 0;
OnStack<2> os(state, bt, loc);

bt = Array::create(state, count);

// Initial edge.
if(!call_frame) return bt;
Expand All @@ -98,7 +110,7 @@ namespace rubinius {
if(!call_frame) return bt;
}

Location* loc = Location::create(state, call_frame, include_vars);
loc = Location::create(state, call_frame, include_vars);
if(on_ip) loc->set_ip_on_current(state);

bt->append(state, loc);
Expand All @@ -110,7 +122,7 @@ namespace rubinius {
if(call_frame->compiled_code) {
bt->append(state, Location::create(state, call_frame, include_vars));
} else if(NativeMethodFrame* nmf = call_frame->native_method_frame()) {
Location* loc = Location::create(state, nmf);
loc = Location::create(state, nmf);
if(loc) bt->append(state, loc);
}

Expand All @@ -121,6 +133,9 @@ namespace rubinius {
}

Array* Location::mri_backtrace(STATE, CallFrame* call_frame) {
Array* bt = 0;
OnStack<1> os(state, bt);

size_t count = 0;

CallFrame* c = call_frame;
Expand All @@ -129,7 +144,7 @@ namespace rubinius {
c = c->previous;
}

Array* bt = Array::create(state, count);
bt = Array::create(state, count);

while(call_frame) {
// Ignore synthetic frames
Expand Down
23 changes: 17 additions & 6 deletions vm/metrics.cpp
Expand Up @@ -78,7 +78,7 @@ namespace rubinius {
cleanup();
}

#define RBX_METRICS_FILE_BUFLEN 22
#define RBX_METRICS_FILE_BUFLEN 256

void FileEmitter::send_metrics() {
char buf[RBX_METRICS_FILE_BUFLEN];
Expand All @@ -93,7 +93,10 @@ namespace rubinius {
logger::error("%s: unable to write file metrics", strerror(errno));
}
}
write(fd_, "\n", 1);

if(write(fd_, "\n", 1)) {
logger::error("%s: unable to write file metrics", strerror(errno));
}
}

void FileEmitter::initialize() {
Expand All @@ -102,14 +105,22 @@ namespace rubinius {
}

if(lseek(fd_, 0, SEEK_END) == 0) {
char buf[RBX_METRICS_FILE_BUFLEN];

for(MetricsMap::iterator i = metrics_map_.begin();
i != metrics_map_.end();
++i)
{
if(i != metrics_map_.begin()) write(fd_, ", ", 2);
write(fd_, (*i)->first.c_str(), (*i)->first.size());
snprintf(buf, RBX_METRICS_FILE_BUFLEN, "%s%s",
i == metrics_map_.begin() ? "" : ", ", (*i)->first.c_str());
if(write(fd_, buf, strlen(buf)) < 0) {
logger::error("%s: unable to write file metrics", strerror(errno));
}
}

if(write(fd_, "\n", 1)) {
logger::error("%s: unable to write file metrics", strerror(errno));
}
write(fd_, "\n", 1);
}
}

Expand Down Expand Up @@ -196,7 +207,7 @@ namespace rubinius {
i != metrics_map_.end();
++i)
{
snprintf(buf, RBX_METRICS_STATSD_BUFLEN, "%s%s:%lld|c",
snprintf(buf, RBX_METRICS_STATSD_BUFLEN, "%s%s:%lld|g",
prefix_.c_str(), (*i)->first.c_str(), (long long unsigned int)(*i)->second);
if(send(socket_fd_, buf, strlen(buf), 0) < 0) {
logger::error("%s: unable to send StatsD metrics", strerror(errno));
Expand Down

0 comments on commit 4de3a00

Please sign in to comment.