<commit_before>/**
 *  Copyright (c) 2014-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed in accordance with the terms specified in
 *  the LICENSE file found in the root directory of this source tree.
 */

#include <osquery/experimental/tracing/syscalls_tracing_impl.h>

#include <osquery/experimental/events_stream/events_stream.h>
#include <osquery/experimental/tracing/linux/probes.h>

#include <osquery/dispatcher.h>
#include <osquery/logger.h>

#include <osquery/utils/caches/lru.h>
#include <osquery/utils/expected/expected.h>
#include <osquery/utils/json/json.h>
#include <osquery/utils/system/linux/proc/proc.h>
#include <osquery/utils/system/time.h>

namespace osquery {
namespace experimental {
namespace tracing {

namespace {

class ProcCmdlineRetriever {
 public:
  // This is experimentally obtained number for the command line strings
  // preserved in cache. If you need to decrease number of cache misses or to
  // decrease memory consumption don't be shy to change it.
  static constexpr auto kCacheCapacity = std::size_t{256};

  explicit ProcCmdlineRetriever() : cache_(kCacheCapacity) {}

  std::string const& get(pid_t proc_pid) {
    if (auto cmd_ptr = cache_.get(proc_pid)) {
      return *cmd_ptr;
    } else {
      LOG(ERROR)
          << "Experimental tracing: command line string cache miss for pid: "
          << proc_pid;
      return *cache_.insert(proc_pid, proc::cmdline(proc_pid));
    }
  }

 private:
  caches::LRU<pid_t, std::string> cache_;
};

enum class Error {
  InitialisationProblem = 1,
  RuntimeProblem = 2,
  DeinitializationProblem = 3,
};

ExpectedSuccess<Error> runSyscallTracing() {
  auto probes_exp = ::osquery::events::LinuxProbesControl::spawn();
  if (probes_exp.isError()) {
    return createError(Error::InitialisationProblem, probes_exp.takeError())
           << "linux probes control spawn failed";
  }
  auto probes = probes_exp.take();
  auto kill_trace_on_exp = probes.traceKill();
  if (kill_trace_on_exp.isError()) {
    return createError(Error::InitialisationProblem,
                       kill_trace_on_exp.takeError())
           << "kill tracing initialisation failed";
  }
  auto setuid_trace_on_exp = probes.traceSetuid();
  if (setuid_trace_on_exp.isError()) {<commit_msg>Remove dangling noisy log line<commit_after>/**
 *  Copyright (c) 2014-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed in accordance with the terms specified in
 *  the LICENSE file found in the root directory of this source tree.
 */

#include <osquery/experimental/tracing/syscalls_tracing_impl.h>

#include <osquery/experimental/events_stream/events_stream.h>
#include <osquery/experimental/tracing/linux/probes.h>

#include <osquery/dispatcher.h>
#include <osquery/logger.h>

#include <osquery/utils/caches/lru.h>
#include <osquery/utils/expected/expected.h>
#include <osquery/utils/json/json.h>
#include <osquery/utils/system/linux/proc/proc.h>
#include <osquery/utils/system/time.h>

namespace osquery {
namespace experimental {
namespace tracing {

namespace {

class ProcCmdlineRetriever {
 public:
  // This is experimentally obtained number for the command line strings
  // preserved in cache. If you need to decrease number of cache misses or to
  // decrease memory consumption don't be shy to change it.
  static constexpr auto kCacheCapacity = std::size_t{256};

  explicit ProcCmdlineRetriever() : cache_(kCacheCapacity) {}

  std::string const& get(pid_t proc_pid) {
    if (auto cmd_ptr = cache_.get(proc_pid)) {
      return *cmd_ptr;
    } else {
      return *cache_.insert(proc_pid, proc::cmdline(proc_pid));
    }
  }

 private:
  caches::LRU<pid_t, std::string> cache_;
};

enum class Error {
  InitialisationProblem = 1,
  RuntimeProblem = 2,
  DeinitializationProblem = 3,
};

ExpectedSuccess<Error> runSyscallTracing() {
  auto probes_exp = ::osquery::events::LinuxProbesControl::spawn();
  if (probes_exp.isError()) {
    return createError(Error::InitialisationProblem, probes_exp.takeError())
           << "linux probes control spawn failed";
  }
  auto probes = probes_exp.take();
  auto kill_trace_on_exp = probes.traceKill();
  if (kill_trace_on_exp.isError()) {
    return createError(Error::InitialisationProblem,
                       kill_trace_on_exp.takeError())
           << "kill tracing initialisation failed";
  }
  auto setuid_trace_on_exp = probes.traceSetuid();
  if (setuid_trace_on_exp.isError()) {
{'fraction_non_alphanumeric': 0.11200536552649229, 'fraction_numerical': 0.004471272076905879, 'mean_word_length': 4.160322952710496, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 27, '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': '5624658', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1376, 'n_words': 347}