<commit_before>// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/sky/shell/systrace_logger.h"
#include "lib/ftl/files/eintr_wrapper.h"

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

namespace sky {
namespace shell {

static const size_t kBufferSize = 256;

SystraceLogger::SystraceLogger()
    : trace_fd_(HANDLE_EINTR(
          ::open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY))),
      pid_(getpid()) {}

SystraceLogger::~SystraceLogger() {
  IGNORE_EINTR(::close(trace_fd_));
}

void SystraceLogger::TraceBegin(const char* label) const {
  char buffer[kBufferSize];
  int buffer_written = snprintf(buffer, sizeof(buffer), "B|%d|%s", pid_, label);

  if (buffer_written <= 0 || buffer_written > kBufferSize) {
    return;
  }

  HANDLE_EINTR(::write(trace_fd_, buffer, buffer_written));
}

void SystraceLogger::TraceEnd() const {
  HANDLE_EINTR(::write(trace_fd_, "E", 1));
}

void SystraceLogger::TraceCount(const char* label, int count) const {
  char buffer[kBufferSize];

  int buffer_written =
      snprintf(buffer, sizeof(buffer), "C|%d|%s|%d", pid_, label, count);

  if (buffer_written <= 0 || buffer_written > kBufferSize) {
    return;
  }

  HANDLE_EINTR(::write(trace_fd_, buffer, buffer_written));
}

}  // namespace shell
}  // namespace sky
<commit_msg>Fix Mac build error due to -Wsign-compare. (#2979)<commit_after>// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/sky/shell/systrace_logger.h"
#include "lib/ftl/files/eintr_wrapper.h"

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

namespace sky {
namespace shell {

static const int kBufferSize = 256;

SystraceLogger::SystraceLogger()
    : trace_fd_(HANDLE_EINTR(
          ::open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY))),
      pid_(getpid()) {}

SystraceLogger::~SystraceLogger() {
  IGNORE_EINTR(::close(trace_fd_));
}

void SystraceLogger::TraceBegin(const char* label) const {
  char buffer[kBufferSize];
  int buffer_written = snprintf(buffer, sizeof(buffer), "B|%d|%s", pid_, label);

  if (buffer_written <= 0 || buffer_written > kBufferSize) {
    return;
  }

  HANDLE_EINTR(::write(trace_fd_, buffer, buffer_written));
}

void SystraceLogger::TraceEnd() const {
  HANDLE_EINTR(::write(trace_fd_, "E", 1));
}

void SystraceLogger::TraceCount(const char* label, int count) const {
  char buffer[kBufferSize];

  int buffer_written =
      snprintf(buffer, sizeof(buffer), "C|%d|%s|%d", pid_, label, count);

  if (buffer_written <= 0 || buffer_written > kBufferSize) {
    return;
  }

  HANDLE_EINTR(::write(trace_fd_, buffer, buffer_written));
}

}  // namespace shell
}  // namespace sky

{'fraction_non_alphanumeric': 0.14266211604095563, 'fraction_numerical': 0.008191126279863481, 'mean_word_length': 4.69126213592233, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3075014', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1006, 'n_words': 237}