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 24 25 26 27

namespace common {
// Don't care windows
u32_t getCpuNum() {
  return std::thread::hardware_concurrency();
}

L
Longda 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#define MAX_STACK_SIZE 32

void print_stacktrace()
{
  int size = MAX_STACK_SIZE;
  void * array[MAX_STACK_SIZE];
  int stack_num = backtrace(array, size);
  char ** stacktrace = backtrace_symbols(array, stack_num);
  for (int i = 0; i < stack_num; ++i)
  {
    LOG_INFO("%d ----- %s\n", i, stacktrace[i]);
  }
  free(stacktrace);
}

羽飞's avatar
羽飞 已提交
43
}//namespace common