• Stars
    star
    131
  • Rank 274,272 (Top 6 %)
  • Language
    C++
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HawkTracer is a highly portable, low-overhead, configurable profiling tool built in Amazon Video for getting performance metrics from low-end devices.

Build Status Gitter chat Codacy Badge codecov Build status

HawkTracer

HawkTracer is a highly portable, low-overhead, configurable profiling tool built in Amazon Video for getting performance metrics from low-end devices.

HawkTracer is available on most popular platforms: Linux, Windows, OS X. By default, the library can be used with C and C++, but there are also wrappers for Python and Rust.

The library provides many different types of events (e.g. CPU usage event, duration tracepoint), but the list can easily be extended by the user.

Features

  • Low CPU/memory overhead
  • Multi-platform
  • Highly configurable on runtime
  • Easy build integration (CMake & pkg-config files)
  • Pre-defined and user-defined events
  • Simple macros for code instrumentation
  • Streaming events to file, through TCP/IP protocol, or handling them in custom function
  • Client for receiving event stream
  • Library for parsing event stream (so you can write your own client)

License Summary

This sample code is made available under the MIT license. (See LICENSE file)

Getting Started

Hello World! tutorials

See the tutorial to quickly onboard to HawkTracer or check the examples directory. The tutorial step by step explains how to build and instrument the code like that:

static void hello_world()
{
    HT_G_TRACE_FUNCTION()

    for (int i = 0; i < 100; i++)
    {
        HT_TP_G_STRACEPOINT("iteration")
        printf("2 * %d = %d\n", i, 2*i);

        std::string txt = "Iteration (mod 10): " + std::to_string(i % 10);
        HT_TP_G_DYN_STRACEPOINT(txt.c_str());
        printf("text: %s\n", txt.c_str());
    }
}

You can also follow instructions below to get HawkTracer up and running.

Building library

$ mkdir build       # It'll be different on Windows
$ cd build
$ cmake ..
$ cmake --build .   # This instead of make, so we don't need extra instructions for Windows

Attaching HawkTracer to a project to profile

Build system integration

CMake-based projects

If you use CMake build system, you can use following code to attach HawkTracer library to your project:

project(your_project)

# optionally, you might define a path to HawkTracer's CMake module
# CMake the path below should be a path to a directory where HawkTracerConfig.cmake is located, e.g.:
# list(APPEND CMAKE_MODULE_PATH "/usr/local/lib/cmake/HawkTracer")

find_package(HawkTracer REQUIRED)

add_executable(your_project main.cc)

target_link_libraries(your_project HawkTracer::hawktracer)

pkg-config

HawkTracer library provides pkg-config file which can be used to find required libraries and include paths. You can simply integrate it e.g. with your compilation command:

$ g++ my_project.cpp $(pkg-config --cflags --libs hawktracer)

Instrumenting code

Initialize library

Before you start profiling your code, you need to initialize HawkTracer library. There are 2 functions which always have to be called in projects profiled by HawkTracer: ht_init and ht_deinit. Additionally, you need to specify an event listener. HawkTracer currently provides 2 listeners:

  • TCP listener, which streams events over the network
  • File dump listener, which saves events to a file.

Moreover, HawkTracer allows to provide user-defined listeners. Code below presents example HawkTracer (un)initialization:

int main(int argc, char** argv)
{
  ht_init(argc, argv); // initialize library
  HT_Timeline* timeline = ht_global_timeline_get(); // timeline, where all events are posted. You can define your own timeline, or use global timeline
  const size_t buffer_size = 4096; // size of internal listener's buffer
  ht_file_dump_listener_register(ht_global_timeline_get(), "hello-world-out.htdump", 2048, NULL); // create listener and attach it to timeline

  // your code goes here...

  ht_deinit(); // uninitialize library

  return 0;
}

The code registers file dump listener, which saves all the events to a file file_name.htdump. The file should be then converted to a viewer's format (see here for details).

Instrumenting the code

HawkTracer requires explicit code instrumentation. The library provides a few helper macros for reporting data to a timeline:

// Pushes any type of event to a timeline
HT_TIMELINE_PUSH_EVENT(TIMELINE, EVENT_TYPE, EVENT_PARAMETERS,...)

// Reports a duration of specific block of code (available only for C++ or C GNU compiler)
HT_TRACE(TIMELINE, LABEL)

// The same as above, but automatically sets label to current function name
HT_TRACE_FUNCTION(TIMELINE)

There are few macros which report events to a global timeline, they're prefixed with G_:

HT_G_TRACE(LABEL)
HT_G_TRACE_OPT_STATIC(LABEL)
HT_G_TRACE_OPT_DYNAMIC(LABEL)
HT_G_TRACE_FUNCTION()

For example, you can instrument following code:

void foo()
{
  HT_G_TRACE_FUNCTION() // measure duration of foo function execution

  for (int i = 0; i < 100; i++)
  {
    HT_G_TRACE_OPT_STATIC("in-loop") // measure duration of single loop iteration
    bar();
  }
}

Collect the data

For now HawkTracer provides a simple application for converting event stream to a JSON format which can be consumed by the viewing application: hawktracer-to-json. You can use it with a file or with a network stream. Assuming your events have been saved to file_name.htdump file, you can generate the JSON file running following command:

hawktracer-to-json --source file_name.htdump --output output_file.json

Analyzing the data

  • Install google-chrome or chromium browser
  • Open the browser, and open chrome://tracing/ webpage
  • Click load button and open file generated in the previous section
  • You should see a callstack with timing

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Acknowledgment

  • Hat tip to anyone who's code was used
  • Inspiration
  • etc

More Repositories

1

style-dictionary

A build system for creating cross-platform styles.
JavaScript
3,855
star
2

computer-vision-basics-in-microsoft-excel

Computer Vision Basics in Microsoft Excel (using just formulas)
2,391
star
3

selling-partner-api-docs

This repository contains documentation for developers to use to call Selling Partner APIs.
1,541
star
4

smoke-framework

A light-weight server-side service framework written in the Swift programming language.
Swift
1,430
star
5

alexa-skills-kit-js

SDK and example code for building voice-enabled skills for the Amazon Echo.
1,134
star
6

ion-java

Java streaming parser/serializer for Ion.
Java
840
star
7

sketch-constructor

Read/write/manipulate Sketch files in Node without Sketch plugins!
JavaScript
538
star
8

selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Mustache
532
star
9

pecos

PECOS - Prediction for Enormous and Correlated Spaces
Python
501
star
10

amzn-drivers

Official AWS drivers repository for Elastic Network Adapter (ENA) and Elastic Fabric Adapter (EFA)
C
444
star
11

ion-js

A JavaScript implementation of Amazon Ion.
TypeScript
323
star
12

convolutional-handwriting-gan

ScrabbleGAN: Semi-Supervised Varying Length Handwritten Text Generation (CVPR20)
Python
260
star
13

xfer

Transfer Learning library for Deep Neural Networks.
Python
250
star
14

awsssmchaosrunner

Amazon's light-weight library for chaos engineering on AWS. It can be used for EC2 and ECS (with EC2 launch type).
Kotlin
247
star
15

ion-python

A Python implementation of Amazon Ion.
Python
210
star
16

amazon-pay-sdk-php

Amazon Pay PHP SDK
PHP
209
star
17

fire-app-builder

Fire App Builder is a framework for building java media apps for Fire TV, allowing you to add your feed of media content to a configuration file and build an app to browse and play it quickly.
Java
178
star
18

exoplayer-amazon-port

Official port of ExoPlayer for Amazon devices
Java
168
star
19

oss-dashboard

A dashboard for viewing many GitHub organizations at once.
Ruby
158
star
20

ion-c

A C implementation of Amazon Ion.
C
149
star
21

metalearn-leap

Original PyTorch implementation of the Leap meta-learner (https://arxiv.org/abs/1812.01054) along with code for running the Omniglot experiment presented in the paper.
Python
147
star
22

ion-go

A Go implementation of Amazon Ion.
Go
146
star
23

distance-assistant

Pedestrian monitor that provides visual feedback to help ensure proper social distancing guidelines are being observed
Python
135
star
24

auction-gym

AuctionGym is a simulation environment that enables reproducible evaluation of bandit and reinforcement learning methods for online advertising auctions.
Jupyter Notebook
135
star
25

trans-encoder

Trans-Encoder: Unsupervised sentence-pair modelling through self- and mutual-distillations
Python
131
star
26

smoke-aws

AWS services integration for the Smoke Framework
Swift
109
star
27

amazon-payments-magento-2-plugin

Extension to enable Amazon Pay on Magento 2
PHP
105
star
28

MXFusion

Modular Probabilistic Programming on MXNet
Python
102
star
29

amazon-weak-ner-needle

Named Entity Recognition with Small Strongly Labeled and Large Weakly Labeled Data
Python
99
star
30

amazon-advertising-api-php-sdk

⛔️ DEPRECATED - Amazon Advertising API PHP Client Library
PHP
93
star
31

ion-rust

Rust implementation of Amazon Ion
Rust
86
star
32

ads-advanced-tools-docs

Code samples and supplements for the Amazon Ads advanced tools center
Jupyter Notebook
83
star
33

image-to-recipe-transformers

Code for CVPR 2021 paper: Revamping Cross-Modal Recipe Retrieval with Hierarchical Transformers and Self-supervised Learning
Python
82
star
34

oss-attribution-builder

The OSS Attribution Builder is a website that helps teams create attribution documents (notices, "open source screens", credits, etc) commonly found in software products.
TypeScript
79
star
35

smoke-http

Specialised HTTP Client for service operations abstracted from the HTTP protocol.
Swift
69
star
36

amazon-ray

Staging area for ongoing enhancements to Ray focused on improving integration with AWS and other Amazon technologies.
Python
66
star
37

alexa-coho

Sample code for building skill adapters for Alexa Connected Home using the Lighting API
JavaScript
62
star
38

amazon-pay-sdk-ruby

Amazon Pay Ruby SDK
Ruby
58
star
39

amazon-pay-sdk-java

Amazon Pay Java SDK
Java
53
star
40

amazon-pay-sdk-python

Amazon Pay Python SDK
Python
53
star
41

zero-shot-rlhr

Python
51
star
42

supply-chain-simulation-environment

Python
49
star
43

amazon-pay-sdk-csharp

Amazon Pay C# SDK
C#
47
star
44

ion-dotnet

A .NET implementation of Amazon Ion.
C#
47
star
45

multiconer-baseline

Python
47
star
46

amazon-pay-api-sdk-php

Amazon Pay API SDK (PHP)
PHP
47
star
47

zeek-plugin-enip

Zeek network security monitor plugin that enables parsing of the Ethernet/IP and Common Industrial Protocol standards
Zeek
45
star
48

amazon-pay-sdk-samples

Amazon Pay SDK Sample Code
PHP
43
star
49

oss-contribution-tracker

Track contributions made to external projects and manage CLAs
TypeScript
40
star
50

amazon-s3-gst-plugin

A collection of Amazon S3 GStreamer elements.
C
40
star
51

fashion-attribute-disentanglement

Python
39
star
52

zeek-plugin-s7comm

Zeek network security monitor plugin that enables parsing of the S7 protocol
Zeek
39
star
53

milan

Milan is a Scala API and runtime infrastructure for building data-oriented systems, built on top of Apache Flink.
Scala
39
star
54

selling-partner-api-samples

Sample code for Amazon Selling Partner API use cases
Python
37
star
55

orthogonal-additive-gaussian-processes

Light-weighted code for Orthogonal Additive Gaussian Processes
Python
37
star
56

jekyll-doc-project

This repository contains an open-source Jekyll theme for authoring and publishing technical documentation. This theme is used by Appstore/Alexa tech writers and other community members. Most of the theme's files are stored in a Ruby Gem (called jekyll-doc-project).
HTML
36
star
57

smoke-dynamodb

SmokeDynamoDB is a library to make it easy to use DynamoDB from Swift-based applications, with a particular focus on usage with polymorphic database tables (tables that do not have a single schema for all rows).
Swift
34
star
58

amazon-pay-api-sdk-nodejs

Amazon Pay API SDK (Node.js)
JavaScript
34
star
59

zeek-plugin-bacnet

Zeek network security monitor plugin that enables parsing of the BACnet standard building controls protocol
Zeek
30
star
60

ss-aga-kgc

Python
30
star
61

chalet-charging-location-for-electric-trucks

Optimization tool to identify charging locations for electric trucks
Python
30
star
62

amazon-pay-api-sdk-java

Amazon Pay API SDK (Java)
Java
29
star
63

credence-to-causal-estimation

A framework for generating complex and realistic datasets for use in evaluating causal inference methods.
Python
29
star
64

sparse-vqvae

Experimental implementation for a sparse-dictionary based version of the VQ-VAE2 paper
Python
28
star
65

zeek-plugin-profinet

Zeek network security monitor plugin that enables parsing of the Profinet protocol
Zeek
28
star
66

ion-tests

Test vectors for testing compliant Ion implementations.
25
star
67

differential-privacy-bayesian-optimization

This repo contains the underlying code for all the experiments from the paper: "Automatic Discovery of Privacy-Utility Pareto Fronts"
Python
25
star
68

buy-with-prime-cdk-constructs

This package extends common CDK constructs with opinionated defaults to help create an organization strategy around infrastructure as code.
TypeScript
25
star
69

basis-point-sets

Python
24
star
70

ion-hive-serde

A Apache Hive SerDe (short for serializer/deserializer) for the Ion file format.
Java
24
star
71

zeek-plugin-tds

Zeek network security monitor plugin that enables parsing of the Tabular Data Stream (TDS) protocol
Zeek
24
star
72

ion-intellij-plugin

Support for Ion in Intellij IDEA.
Kotlin
23
star
73

ion-schema-kotlin

A Kotlin reference implementation of the Ion Schema Specification.
Kotlin
23
star
74

smoke-framework-application-generate

Code generator to generate SmokeFramework-based applications from service models.
Swift
23
star
75

emukit-playground

A web page explaining concepts of statistical emulation and making decisions under uncertainty in an interactive way.
JavaScript
22
star
76

ftv-livetv-sample-tv-app

Java
22
star
77

smoke-framework-examples

Sample applications showing the usage of the SmokeFramework and related libraries.
Swift
22
star
78

ion-hash-go

A Go implementation of Amazon Ion Hash.
Go
22
star
79

pretraining-or-self-training

Codebase for the paper "Rethinking Semi-supervised Learning with Language Models"
Python
22
star
80

tiny-attribution-generator

A small tool and library to create attribution notices from various formats
TypeScript
20
star
81

confident-sinkhorn-allocation

Pseudo-labeling for tabular data
Jupyter Notebook
20
star
82

ion-docs

Source for the GitHub Pages for Ion.
Java
19
star
83

autotrail

AutoTrail is a highly modular, partial automation workflow engine providing run time execution control
Python
19
star
84

git-commit-template

Set commit templates for git
JavaScript
19
star
85

smoke-aws-generate

Code generator to generate the SmokeAWS library from service models.
Swift
18
star
86

amazon-codeguru-profiler-for-spark

A Spark plugin for CPU and memory profiling
Java
17
star
87

smoke-aws-credentials

A library to obtain and assume automatically rotating AWS IAM roles written in the Swift programming language.
Swift
17
star
88

service-model-swift-code-generate

Modular code generator to generate Swift applications from service models.
Swift
17
star
89

amazon-pay-api-sdk-dotnet

Amazon Pay API SDK (.NET)
C#
17
star
90

sample-fire-tv-app-video-skill

This sample Fire TV app shows how to integrate an Alexa video skill in a simple, basic way.
Java
16
star
91

amazon-template-library

A collection of general purpose C++ utilities that play well with the Standard Library and Boost.
C++
16
star
92

ion-cli

Rust
15
star
93

refuel-open-domain-qa

Python
15
star
94

rheoceros

Cloud-based AI / ML workflow and data application development framework
Python
15
star
95

amazon-instant-access-sdk-php

PHP SDK to aid in 3p integration with Instant Access
PHP
14
star
96

amazon-mcf-plugin-for-magento-1

Plugin code to enable Amazon MCF in Magento 1.
PHP
14
star
97

login-with-amazon-wordpress

A pre-integrated plugin that can be installed into a Wordpress powered website to integrate with Login with Amazon.
PHP
14
star
98

amzn-ec2-ena-utilities

Python
14
star
99

firetv-sample-touch-app

This sample Android project demonstrates how to build the main UI of a Fire TV application in order to support both Touch interactions and Remote D-Pad controls.
Java
13
star
100

eslint-plugin-no-date-parsing

Disallow string parsing with new Date and Date.parse.
TypeScript
13
star