Skip to content

Commit

Permalink
Fixes boolean types and adds a stream header.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmatzen committed Aug 6, 2016
1 parent 000fbdc commit 2e20990
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
17 changes: 9 additions & 8 deletions include/trace/trace.h
Expand Up @@ -37,6 +37,7 @@ extern "C" {
att_float64,
att_string,
att_wstring,
att_boolean,
att_pointer = 0x80,
};

Expand Down Expand Up @@ -149,7 +150,7 @@ namespace ayxia
AYX_ARGTYPE(uint16_t, att_uint16);
AYX_ARGTYPE(int32_t, att_int32);
AYX_ARGTYPE(uint32_t, att_uint32);
AYX_ARGTYPE(bool, att_int32);
AYX_ARGTYPE(bool, att_boolean);
AYX_ARGTYPE(long, att_int32);
AYX_ARGTYPE(unsigned long, att_uint32);
AYX_ARGTYPE(int64_t, att_int64);
Expand Down Expand Up @@ -215,13 +216,13 @@ namespace ayxia
return res;
}

static ayxia_trace_arg mkarg(bool arg)
{
ayxia_trace_arg res;
res.parg = arg ? "true" : "false";
res.type = argtype<bool>::value;
return res;
}
//static ayxia_trace_arg mkarg(bool arg)
//{
// ayxia_trace_arg res;
// res.parg = &arg;
// res.type = argtype<bool>::value;
// return res;
//}

void operator()()
{
Expand Down
5 changes: 3 additions & 2 deletions src/sample_cpp/sample_cpp.cpp
Expand Up @@ -33,14 +33,14 @@ class TraceTest
{
if (rand() % 10)
return;
TRACE_WARNING("StreamReader::Read::failed", "Checksum failed.");
TRACE_WARNING("StreamReader::Read::failed", "Checksum failed address={0}", (void*)intptr_t(0xdeadbeef));
}

static void error()
{
if (rand() % 15)
return;
TRACE_ERROR("StreamReader::Write", "failed to write {0} bytes.", rand());
TRACE_ERROR("StreamReader::Write", "failed to write {0} bytes. {1}", rand(), rand()?true:false);

}
};
Expand All @@ -50,6 +50,7 @@ int main()
auto init = TraceInitialize("localhost", "sample_cpp", 1024 * 1024);
ayxia_tc_initialize(&init);

TRACE_INFO("boolcheck", "{0} {1}", true, false);
for (int i = 0; i < 100; ++i)
{
ayxia_tc_start_frame();
Expand Down
11 changes: 10 additions & 1 deletion src/trace/context.cpp
Expand Up @@ -22,6 +22,7 @@
namespace
{
const size_t kBufferSize = 65536;
const char * const kStreamHeaderMagicValue = "TRCE";

#if defined _WIN32
thread_local int32_t s_threadid = -1;
Expand Down Expand Up @@ -51,7 +52,10 @@ namespace
return p + len*sizeof(wchar_t);
}


char* write_buffer(char* p, bool arg) {
p = write_buffer(p, static_cast<int8_t>(arg ? 1 : 0));
return p += sizeof(int8_t);
}

template<typename T>
void serialize_arg(char*& p, const ayxia_trace_arg& arg)
Expand Down Expand Up @@ -122,6 +126,7 @@ void ayxia::trace::Context::SendTrace(const ayxia_trace_channel& channel, const
case att_int64:serialize_arg<int64_t>(ptr, *it); break;
case att_float32:serialize_arg<float>(ptr, *it); break;
case att_float64:serialize_arg<double>(ptr, *it); break;
case att_boolean:serialize_arg<bool>(ptr, *it); break;
case att_string:serialize_arg_string<char>(ptr, *it); break;
case att_wstring:serialize_arg_string<wchar_t>(ptr, *it); break;
default: abort();
Expand Down Expand Up @@ -173,6 +178,10 @@ void ayxia::trace::Context::Initialize()
}
std::array<char, 1024> buf;
auto p = buf.data();
unsigned magic;
memcpy(&magic, kStreamHeaderMagicValue, 4);
p = write_buffer<unsigned>(p, magic);
p = write_buffer<short>(p, 0x0100); // stream version
p = write_buffer(p, m_processName.c_str());
SendToLogger(atc_initialize, buf.data(), p - buf.data());
}
Expand Down

0 comments on commit 2e20990

Please sign in to comment.