<commit_before>// Copyright (c) 2011 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 "base/sys_info.h"

#include <limits>

#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/sys_info_internal.h"

namespace {

int64 AmountOfMemory(int pages_name) {
  long pages = sysconf(pages_name);
  long page_size = sysconf(_SC_PAGESIZE);
  if (pages == -1 || page_size == -1) {
    NOTREACHED();
    return 0;
  }
  return static_cast<int64>(pages) * page_size;
}

int64 AmountOfPhysicalMemory() {
  return AmountOfMemory(_SC_PHYS_PAGES);
}

size_t MaxSharedMemorySize() {
  std::string contents;
  base::ReadFileToString(base::FilePath("/proc/sys/kernel/shmmax"), &contents);
  DCHECK(!contents.empty());
  if (!contents.empty() && contents[contents.length() - 1] == '\n') {
    contents.erase(contents.length() - 1);
  }

  int64 limit;
  if (!base::StringToInt64(contents, &limit)) {
    limit = 0;
  }
  if (limit < 0 ||
      static_cast<uint64>(limit) > std::numeric_limits<size_t>::max()) {
    limit = 0;
  }
  DCHECK(limit > 0);
  return static_cast<size_t>(limit);
}

base::LazyInstance<
    base::internal::LazySysInfoValue<int64, AmountOfPhysicalMemory> >::Leaky
    g_lazy_physical_memory = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<
    base::internal::LazySysInfoValue<size_t, MaxSharedMemorySize> >::Leaky
    g_lazy_max_shared_memory = LAZY_INSTANCE_INITIALIZER;

}  // namespace

namespace base {
<commit_msg>Parse shmmax as a uint64<commit_after>// Copyright (c) 2011 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 "base/sys_info.h"

#include <limits>

#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/sys_info_internal.h"

namespace {

int64 AmountOfMemory(int pages_name) {
  long pages = sysconf(pages_name);
  long page_size = sysconf(_SC_PAGESIZE);
  if (pages == -1 || page_size == -1) {
    NOTREACHED();
    return 0;
  }
  return static_cast<int64>(pages) * page_size;
}

int64 AmountOfPhysicalMemory() {
  return AmountOfMemory(_SC_PHYS_PAGES);
}

size_t MaxSharedMemorySize() {
  std::string contents;
  base::ReadFileToString(base::FilePath("/proc/sys/kernel/shmmax"), &contents);
  DCHECK(!contents.empty());
  if (!contents.empty() && contents[contents.length() - 1] == '\n') {
    contents.erase(contents.length() - 1);
  }

  uint64 limit;
  if (!base::StringToUint64(contents, &limit)) {
    limit = 0;
  }
  if (limit > std::numeric_limits<size_t>::max()) {
    limit = 0;
  }
  DCHECK(limit > 0);
  return static_cast<size_t>(limit);
}

base::LazyInstance<
    base::internal::LazySysInfoValue<int64, AmountOfPhysicalMemory> >::Leaky
    g_lazy_physical_memory = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<
    base::internal::LazySysInfoValue<size_t, MaxSharedMemorySize> >::Leaky
    g_lazy_max_shared_memory = LAZY_INSTANCE_INITIALIZER;

}  // namespace

namespace base {

{'fraction_non_alphanumeric': 0.14021571648690292, 'fraction_numerical': 0.01633281972265023, 'mean_word_length': 4.786096256684492, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 24, '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': '5593004', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1149, 'n_words': 232}