Remove go wrapper (#1268)
This commit is contained in:
Родитель
4a91d794b2
Коммит
375938a215
|
@ -1,2 +0,0 @@
|
|||
example
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
This README describes how to build GoLang wrapper around native C++ Telemetry SDK.
|
||||
|
||||
This not officially supported Go SDK, rather than a sample showing how to route data from Go to 1DS Collector++
|
||||
|
||||
# Installing 3rd party dependencies
|
||||
|
||||
## Linux
|
||||
|
||||
```
|
||||
apt-get install golang swig
|
||||
```
|
||||
|
||||
## Mac OS X
|
||||
|
||||
```
|
||||
brew install golang
|
||||
brew install swig
|
||||
```
|
||||
|
||||
# Building
|
||||
|
||||
Build script would auto-detect the OS (Linux or Mac) and compile/link Go .exe for that OS
|
||||
|
||||
```
|
||||
./build.sh
|
||||
```
|
||||
|
||||
# Running
|
||||
|
||||
Requires root:
|
||||
|
||||
```
|
||||
./run-tests.sh
|
||||
```
|
|
@ -1,23 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
## Uncomment for custom path to golang
|
||||
#export PATH=/build/go/bin:$PATH
|
||||
#export GOROOT=/build/go
|
||||
export GOPATH=`pwd`
|
||||
|
||||
# Determine OS
|
||||
OS_NAME=`uname -a`
|
||||
case "$OS_NAME" in
|
||||
*Darwin*) OS=mac ;;
|
||||
*Linux*) OS=linux ;;
|
||||
*) echo "WARNING: unsupported OS $OS_NAME , exiting.."
|
||||
return 0 ;;
|
||||
esac
|
||||
|
||||
# Link to proper build file for OS
|
||||
MODULE_PATH=`pwd`/src/Microsoft/Telemetry/EventLogger
|
||||
unlink $MODULE_PATH/build.go
|
||||
ln -s $MODULE_PATH/build.go.$OS $MODULE_PATH/build.go
|
||||
|
||||
go version
|
||||
go build -o example
|
|
@ -1,84 +0,0 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
"Microsoft/Telemetry/EventLogger"
|
||||
"runtime"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
func getuptime() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
func printMemoryStats() {
|
||||
var m runtime.MemStats
|
||||
runtime.ReadMemStats(&m)
|
||||
fmt.Printf("\tAlloc = %10vK\tTotalAlloc = %10vK\tSys = %10vK\tNumGC = %10v\n", m.Alloc / 1024, m.TotalAlloc / 1024, m.Sys / 1024, m.NumGC)
|
||||
}
|
||||
|
||||
|
||||
/* This code example shows how to register a signal handler routine in GoLang.
|
||||
* In case if native code experiences an issue, the signal can be trapped here
|
||||
* and decision made what to do next - restart the process or attempt to recover
|
||||
* by reinitializing Aria, etc.
|
||||
*/
|
||||
func registerSignalHandler() {
|
||||
go func() {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGABRT, syscall.SIGTERM)
|
||||
buf := make([]byte, 1<<20)
|
||||
for {
|
||||
<-sigs
|
||||
stacklen := runtime.Stack(buf, true)
|
||||
// Print out detailed stack info to facilitate debugging
|
||||
fmt.Printf("=== received terminate ===\n*** goroutine dump...\n%s\n*** end\n", buf[:stacklen])
|
||||
debug.PrintStack()
|
||||
os.Exit(-1)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func main() {
|
||||
// trap SIGABRT and SIGTERM
|
||||
registerSignalHandler()
|
||||
|
||||
// 1DSCppSdkTest sandbox key
|
||||
token := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-xxxx"
|
||||
|
||||
fmt.Println("Hello from Microsoft Telemetry-Go!\n")
|
||||
logger := EventLogger.NewEventLogger()
|
||||
logger.Init(token)
|
||||
done := false
|
||||
seq := 0
|
||||
for done != true {
|
||||
uptime_start := getuptime()
|
||||
for i := 0 ; i<10000; i++ {
|
||||
event := EventLogger.NewStringMap()
|
||||
event.Set("name", "GoLangTest")
|
||||
event.Set("key1", "value1")
|
||||
event.Set("key2", "value2")
|
||||
event.Set("seq", strconv.Itoa(i))
|
||||
logger.LogEvent(event)
|
||||
/* no defer!! */ EventLogger.DeleteStringMap(event)
|
||||
}
|
||||
uptime_end := getuptime()
|
||||
delta := (uptime_end - uptime_start)
|
||||
fmt.Printf("[%d] sent a batch of 10000 events in %d ms\n", seq, delta)
|
||||
printMemoryStats()
|
||||
time.Sleep(time.Second)
|
||||
seq++
|
||||
}
|
||||
|
||||
logger.Done()
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Clean-up previous results
|
||||
#
|
||||
sudo rm /tmp/aria*.log
|
||||
sudo rm offline*
|
||||
sudo rm -f heap*
|
||||
|
||||
BIN=./example
|
||||
|
||||
case $1 in
|
||||
|
||||
"")
|
||||
echo "Running simple test..."
|
||||
$BIN
|
||||
;;
|
||||
|
||||
1)
|
||||
echo "Running heap check..."
|
||||
export PPROF_PATH=/usr/local/bin
|
||||
export HEAPCHECK=normal
|
||||
# export HEAPPROFILE=/tmp/heapprof
|
||||
# export LD_PRELOAD="/usr/lib/libtcmalloc.so"
|
||||
$BIN
|
||||
;;
|
||||
|
||||
2)
|
||||
echo "Running gdb..."
|
||||
gdb -ex=r --args $BIN
|
||||
;;
|
||||
|
||||
3)
|
||||
echo "Running valgrind..."
|
||||
valgrind -v $BIN
|
||||
;;
|
||||
|
||||
4)
|
||||
echo "Running valgrind leak check..."
|
||||
valgrind -v --track-origins=yes --leak-check=full $BIN
|
||||
# valgrind --vgdb=yes --vgdb-error=0 ./example
|
||||
;;
|
||||
|
||||
5)
|
||||
echo "Running cgroups 500MB memory test..."
|
||||
cgcreate -g memory:/500MB
|
||||
echo $(( 500 * 1024 * 1024 )) > /sys/fs/cgroup/memory/500MB/memory.limit_in_bytes
|
||||
cgexec -g memory:/500MB $BIN
|
||||
;;
|
||||
|
||||
esac
|
|
@ -1,2 +0,0 @@
|
|||
build.go
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#include "EventLogger.h"
|
||||
|
||||
#include "LogManager.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <thread>
|
||||
|
||||
using namespace std;
|
||||
using namespace MAT;
|
||||
|
||||
LOGMANAGER_INSTANCE
|
||||
|
||||
static ILogger *logger;
|
||||
|
||||
void EventLogger::Init(std::string token)
|
||||
{
|
||||
auto& configuration = LogManager::GetLogConfiguration();
|
||||
configuration[CFG_STR_CACHE_FILE_PATH] = "offlinestorage.db"; // ":memory:";
|
||||
configuration[CFG_INT_TRACE_LEVEL_MASK] = 0xFFFFFFFF ^ 128;
|
||||
configuration[CFG_INT_TRACE_LEVEL_MIN] = ACTTraceLevel_Fatal;
|
||||
configuration[CFG_INT_SDK_MODE] = SdkModeTypes::SdkModeTypes_CS;
|
||||
configuration[CFG_INT_MAX_TEARDOWN_TIME] = 5;
|
||||
configuration[CFG_INT_RAM_QUEUE_SIZE] = 32 * 1024 * 1024; // 32 MB heap limit for sqlite3
|
||||
configuration[CFG_INT_CACHE_FILE_SIZE] = 16 * 1024 * 1024; // 16 MB storage file limit
|
||||
|
||||
// TODO: move logger from static to private class member
|
||||
logger = LogManager::Initialize(token);
|
||||
|
||||
// LogManager::SetTransmitProfile(TRANSMITPROFILE_REALTIME);
|
||||
}
|
||||
|
||||
void EventLogger::Pause()
|
||||
{
|
||||
LogManager::PauseTransmission();
|
||||
}
|
||||
|
||||
void EventLogger::Resume()
|
||||
{
|
||||
LogManager::ResumeTransmission();
|
||||
}
|
||||
|
||||
void EventLogger::LogEvent(std::map<std::string, std::string>& event)
|
||||
{
|
||||
static long eventCount = 0;
|
||||
EventProperties props(event["name"]);
|
||||
for(auto &kv : event)
|
||||
{
|
||||
props.SetProperty(kv.first, kv.second);
|
||||
}
|
||||
logger->LogEvent(props);
|
||||
|
||||
eventCount++;
|
||||
|
||||
#if 0 /* emulate async SIGABRT after 20000 events */
|
||||
if (eventCount > 20000) {
|
||||
std::thread t([]() {
|
||||
std::terminate();
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
#endif
|
||||
|
||||
// This is required to fix swig projection memleak :
|
||||
event.clear();
|
||||
}
|
||||
|
||||
void EventLogger::Upload()
|
||||
{
|
||||
printf("LogManager::UploadNow\n");
|
||||
LogManager::UploadNow();
|
||||
}
|
||||
|
||||
void EventLogger::Done()
|
||||
{
|
||||
printf("LogManager::FlushAndTeardown\n");
|
||||
LogManager::FlushAndTeardown();
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#ifndef EventLogger_H
|
||||
#define EventLogger_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class EventLogger
|
||||
{
|
||||
public:
|
||||
EventLogger(){};
|
||||
void Init(std::string token);
|
||||
void LogEvent(std::map<std::string, std::string>& event);
|
||||
void Pause();
|
||||
void Resume();
|
||||
void Upload();
|
||||
void Done();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,16 +0,0 @@
|
|||
%module eventlogger
|
||||
|
||||
%include <typemaps.i>
|
||||
%include "std_string.i"
|
||||
%include "std_map.i"
|
||||
%{
|
||||
#include "EventLogger.h"
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
%template(StringMap) map<std::string, std::string>;
|
||||
|
||||
}
|
||||
|
||||
%include EventLogger.h
|
|
@ -1,5 +0,0 @@
|
|||
package EventLogger
|
||||
// #cgo CFLAGS: -DGENERIC_VALUE=32 -I/usr/local/include/mat
|
||||
// #cgo CXXFLAGS: -std=c++11 -I/usr/local/include/mat
|
||||
// #cgo LDFLAGS: -L/usr/local/lib/x86_64-linux-gnu -lmat -lcurl -lz -lsqlite3 -ldl
|
||||
import "C"
|
|
@ -1,5 +0,0 @@
|
|||
package EventLogger
|
||||
// #cgo CFLAGS: -DGENERIC_VALUE=32 -I/usr/local/include/mat
|
||||
// #cgo CXXFLAGS: -std=c++11 -I/usr/local/include/mat
|
||||
// #cgo LDFLAGS: -L/usr/local/lib -framework CoreFoundation -framework IOKit -lmat -lcurl -lz -lsqlite3 -ldl
|
||||
import "C"
|
Загрузка…
Ссылка в новой задаче