Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
loganek committed Apr 13, 2018
0 parents commit cf6dea2
Show file tree
Hide file tree
Showing 26 changed files with 1,878 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.0)

project(hawktracer
VERSION 0.1.0)

set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-parameter")

option(ENABLE_UNITTESTS "Build unit tests" ON)
option(WITH_GCOV "Build with code coverage calculation" OFF)
option(DISABLE_CLIENT "Disable hawktracer profiling client" OFF)

if(WITH_GCOV)
add_definitions(-fprofile-arcs -ftest-coverage)
link_libraries(gcov)
endif(WITH_GCOV)

include_directories(src)
add_subdirectory(src)

if(ENABLE_UNITTESTS)
enable_testing()
add_subdirectory(test)
endif(ENABLE_UNITTESTS)
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.1.0 (unstable) - 30.06.2017:
* implement prototype of tracing server
* implement client for receiving tracepoints
* implement simple tool for searching tracepoints in LUA and C++ files
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_subdirectory(hawktracer)

if(NOT DISABLE_CLIENT)
add_subdirectory(profiler)
endif()
73 changes: 73 additions & 0 deletions src/hawktracer/Action.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "Action.h"

#include <cassert>
#include <ctime>
#include <cstring>

#define NANOSECS_PER_MILLISEC 1000000

namespace hawktracer
{

Action::Action() :
Action(0)
{
stopTime = startTime;
}

Action::Action(Label label) :
label(label)
{
startTime = get_time_now_nanoseconds();
}

NanoTime_t Action::get_time_now_nanoseconds()
{
return HRClock::get_current_timestamp();
}

void Action::serialize(char *outBuffer, std::size_t outBufferSize)
{
assert(outBufferSize >= STRUCT_SIZE);

std::size_t outSize = 0;

#define SERIALIZE_FIELD(FIELD) do { \
memcpy(outBuffer + outSize, (char*)&FIELD, sizeof(FIELD)); \
outSize += sizeof(FIELD); \
} while (false)

SERIALIZE_FIELD(actionId);
SERIALIZE_FIELD(startTime);
SERIALIZE_FIELD(stopTime);
SERIALIZE_FIELD(label);
SERIALIZE_FIELD(threadId);
#undef SERIALIZE_FIELD
}

void Action::deserialize(const char* inBuffer, std::size_t inBufferSize)
{
assert(inBufferSize >= STRUCT_SIZE);

int outSize = 0;

#define DESERIALIZE_FIELD(FIELD) do { \
memcpy((char*)&FIELD, inBuffer + outSize, sizeof(FIELD)); \
outSize += sizeof(FIELD); \
} while (false)

DESERIALIZE_FIELD(actionId);
DESERIALIZE_FIELD(startTime);
DESERIALIZE_FIELD(stopTime);
DESERIALIZE_FIELD(label);
DESERIALIZE_FIELD(threadId);
#undef DESERIALIZE_FIELD
}


double Action::to_milliseconds(NanoTime_t time)
{
return static_cast<double>(time) / NANOSECS_PER_MILLISEC;
}

} // namespace hawktracer
38 changes: 38 additions & 0 deletions src/hawktracer/Action.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef HAWKTRACER_ACTION_H_
#define HAWKTRACER_ACTION_H_

#include <hawktracer/HRClock.h>

#include <cstddef>
#include <cstdint>

namespace hawktracer
{

struct Action
{
using Id = uint32_t;
using Label = uint32_t;

NanoTime_t startTime = 0;
NanoTime_t stopTime = 0;
Label label = 0;
Id actionId = 0;
uint8_t threadId = 0;

enum { STRUCT_SIZE = sizeof(label) + sizeof(startTime) + sizeof(stopTime) + sizeof(threadId) + sizeof(actionId) };

Action();
explicit Action(Label label);

static NanoTime_t get_time_now_nanoseconds();

void serialize(char *outBuffer, size_t outBufferSize);
void deserialize(const char* inBuffer, size_t inBufferSize);

static double to_milliseconds(NanoTime_t time);
};

} // namespace hawktracer

#endif // HAWKTRACER_ACTION_H_
32 changes: 32 additions & 0 deletions src/hawktracer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
if(UNIX)
set(platform unix)
else()
message(ERROR "Unsupported platform ${CMAKE_SYSTEM_NAME}")
endif(UNIX)

set(hawktracer_PUBLIC_HEADERS
Action.h
CircularBuffer.h
config.h
TCPClient.h
TCPServer.h
Timeline.h
TimelineNetworkListener.h
TracepointTimeline.h
Vector.h)

add_library(hawktracer STATIC
Action.cpp
TCPClient.cpp
TCPServer.cpp
Timeline.cpp
TimelineNetworkListener.cpp
platform/${platform}/HRClock.cpp)

set_target_properties(hawktracer PROPERTIES COMPILE_FLAGS " -Wall -std=c++0x")

install(
TARGETS hawktracer
DESTINATION "lib")
install(FILES ${hawktracer_PUBLIC_HEADERS} DESTINATION "include/hawktracer/")

75 changes: 75 additions & 0 deletions src/hawktracer/CircularBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef HAWKTRACER_CIRCULARBUFFER_H
#define HAWKTRACER_CIRCULARBUFFER_H

#include <cassert>
#include <stdexcept>

namespace hawktracer
{

template<typename T, std::size_t SIZE>
class CircularBuffer
{
static_assert(SIZE > 0, "CircularBuffer size must be greater than 0");
public:
std::size_t _head;
std::size_t _tail;
bool _empty = true;

T _data[SIZE];

public:
void push(const T& value)
{
if (_empty)
{
_head = _tail = 0;
_empty = false;
}
else
{
std::size_t next = (_head + 1) % SIZE;

if (next == _tail)
{
_tail = (_tail + 1) % SIZE;
}

_head = next;
}

_data[_head] = value;
}

T pop()
{
T value = front();

if (_head == _tail)
{
_empty = true;
}
else
{
_tail = (_tail + 1) % SIZE;
}

return value;
}

T front()
{
assert(!_empty && "try to get front element from empty queue");

return _data[_tail];
}

bool empty() const
{
return _empty;
}
};

} // namespace hawktracer

#endif // HAWKTRACER_CIRCULARBUFFER_H
19 changes: 19 additions & 0 deletions src/hawktracer/HRClock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef HAWKTRACER_HRCLOCK_H_
#define HAWKTRACER_HRCLOCK_H_

#include <cstdint>

namespace hawktracer
{

using NanoTime_t = int64_t;

class HRClock
{
public:
static NanoTime_t get_current_timestamp();
};

} // namespace hawktracer

#endif // HAWKTRACER_HRCLOCK_H_
Loading

0 comments on commit cf6dea2

Please sign in to comment.