<commit_before>/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "trace_posix.h"

#include <cassert>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#ifdef __linux__
    #include <sys/syscall.h>
#endif
#ifdef WEBRTC_ANDROID
    #include <pthread.h>
#else
    #include <iostream>
#endif

#if defined(_DEBUG)
    #define BUILDMODE "d"
#elif defined(DEBUG)
    #define BUILDMODE "d"
#elif defined(NDEBUG)
    #define BUILDMODE "r"
#else
    #define BUILDMODE "?"
#endif
#define BUILDTIME __TIME__
#define BUILDDATE __DATE__
// example: "Oct 10 2002 12:05:30 r"
#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE

namespace webrtc {
TracePosix::TracePosix()
{
    _prevAPITickCount = time(NULL);
    _prevTickCount = _prevAPITickCount;
}

TracePosix::~TracePosix()
{
    StopThread();
}

WebRtc_Word32 TracePosix::AddThreadId(char* traceMessage) const {
#ifdef __linux__
  pid_t threadId = (pid_t) syscall(SYS_gettid);
  sprintf(traceMessage, "%10d; ", threadId);
#else
  WebRtc_UWord64 threadId = (WebRtc_UWord64)pthread_self();
  sprintf(traceMessage, "%10llu; ",
          static_cast<long long unsigned int>(threadId));
#endif
  // 12 bytes are written.
  return 12;
}

WebRtc_Word32 TracePosix::AddTime(char* traceMessage,
                                  const TraceLevel level) const
{
    time_t dwCurrentTimeInSeconds = time(NULL);
    struct tm systemTime;
    gmtime_r(&dwCurrentTimeInSeconds, &systemTime);

    if(level == kTraceApiCall)
    {
        WebRtc_UWord32 dwDeltaTime = dwCurrentTimeInSeconds - _prevTickCount;<commit_msg>Use a more common macro to get thread id Review URL: http://webrtc-codereview.appspot.com/342004<commit_after>/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "trace_posix.h"

#include <cassert>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#ifdef __linux__
    #include <sys/syscall.h>
#endif
#ifdef WEBRTC_ANDROID
    #include <pthread.h>
#else
    #include <iostream>
#endif

#if defined(_DEBUG)
    #define BUILDMODE "d"
#elif defined(DEBUG)
    #define BUILDMODE "d"
#elif defined(NDEBUG)
    #define BUILDMODE "r"
#else
    #define BUILDMODE "?"
#endif
#define BUILDTIME __TIME__
#define BUILDDATE __DATE__
// example: "Oct 10 2002 12:05:30 r"
#define BUILDINFO BUILDDATE " " BUILDTIME " " BUILDMODE

namespace webrtc {
TracePosix::TracePosix()
{
    _prevAPITickCount = time(NULL);
    _prevTickCount = _prevAPITickCount;
}

TracePosix::~TracePosix()
{
    StopThread();
}

WebRtc_Word32 TracePosix::AddThreadId(char* traceMessage) const {
#ifdef __linux__
  pid_t threadId = (pid_t) syscall(__NR_gettid);
  sprintf(traceMessage, "%10d; ", threadId);
#else
  WebRtc_UWord64 threadId = (WebRtc_UWord64)pthread_self();
  sprintf(traceMessage, "%10llu; ",
          static_cast<long long unsigned int>(threadId));
#endif
  // 12 bytes are written.
  return 12;
}

WebRtc_Word32 TracePosix::AddTime(char* traceMessage,
                                  const TraceLevel level) const
{
    time_t dwCurrentTimeInSeconds = time(NULL);
    struct tm systemTime;
    gmtime_r(&dwCurrentTimeInSeconds, &systemTime);

    if(level == kTraceApiCall)
    {
        WebRtc_UWord32 dwDeltaTime = dwCurrentTimeInSeconds - _prevTickCount;
{'fraction_non_alphanumeric': 0.10090361445783133, 'fraction_numerical': 0.01857429718875502, 'mean_word_length': 3.98125, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6427286', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1342, 'n_words': 388}