os.cpp 1.2 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Longda on 2010.
//

#include <thread>
L
Longda 已提交
16
#include <execinfo.h>
羽飞's avatar
羽飞 已提交
17 18 19

#include "common/defs.h"
#include "common/os/os.h"
L
Longda 已提交
20
#include "common/log/log.h"
羽飞's avatar
羽飞 已提交
21 22 23

namespace common {
// Don't care windows
24 25
u32_t getCpuNum()
{
羽飞's avatar
羽飞 已提交
26 27 28
  return std::thread::hardware_concurrency();
}

L
Longda 已提交
29 30 31 32 33
#define MAX_STACK_SIZE 32

void print_stacktrace()
{
  int size = MAX_STACK_SIZE;
34
  void *array[MAX_STACK_SIZE];
L
Longda 已提交
35
  int stack_num = backtrace(array, size);
36 37
  char **stacktrace = backtrace_symbols(array, stack_num);
  for (int i = 0; i < stack_num; ++i) {
L
Longda 已提交
38 39 40 41 42
    LOG_INFO("%d ----- %s\n", i, stacktrace[i]);
  }
  free(stacktrace);
}

43
}  // namespace common