자택경비대

Unix/Linux 명령어 옵션 벤치마크 하는방법

Programming

time 명령어를 사용하여, 인자로 전달된 명령어의 실행 시간, CPU 사용량 등을 측정하여 보여주도록 할 수 있다.


make 명령어의 옵션 측정 예

# time make
make  16.50s user 1.73s system 98% cpu 18.561 total
make -j4  19.80s user 2.07s system 329% cpu 6.634 total
make -j8  23.94s user 2.35s system 472% cpu 5.568 total

Makefile에서 dependency가 누락되는 현상 해결법

Programming

예를 들면 다음과 같다:

all: foo bar

foo:
    echo foo

bar:
    echo bar

이렇게 Makefile이 존재할 때 make all을 하면 foo는 실행되는데 bar은 안된다던가, bar는 실행되지만 foo를 건너뛰는 등의 경우이다.

이런 경우에는 같은 폴더에 foo, bar과 같은 이름의 폴더가 존재하기 때문에 이런 결과가 나타난다.

해결방법은 .PHONY 구문을 이용하여 예외로 지정해주면 간단히 해결된다.

.PHONY: foo bar
all: foo bar

foo:
    echo foo

bar:
    echo bar

google test 컴파일 에러 해결법

Programming

google test는 C++ 단위 테스트 환경 구축을 위한 프레임워크이다.

In file included from sample.cpp:1:
In file included from /usr/local/include/gtest/gtest.h:62:
In file included from /usr/local/include/gtest/internal/gtest-internal.h:40:
/usr/local/include/gtest/internal/gtest-port.h:826:12: error: no member named
      'make_tuple' in namespace 'std'
using std::make_tuple;
      ~~~~~^
/usr/local/include/gtest/internal/gtest-port.h:827:12: error: no member named 'tuple' in
      namespace 'std'
using std::tuple;
      ~~~~~^
/usr/local/include/gtest/internal/gtest-port.h:906:3: warning: deleted function
      definitions are a C++11 extension [-Wc++11-extensions]
  GTEST_DISALLOW_ASSIGN_(RE);
  ^
/usr/local/include/gtest/internal/gtest-port.h:672:34: note: expanded from macro
      'GTEST_DISALLOW_ASSIGN_'
  void operator=(type const &) = delete
                                 ^
/usr/local/include/gtest/internal/gtest-port.h:949:3: warning: deleted function
      definitions are a C++11 extension [-Wc++11-extensions]
  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
  ^
/usr/local/include/gtest/internal/gtest-port.h:677:24: note: expanded from macro
      'GTEST_DISALLOW_COPY_AND_ASSIGN_'
  type(type const &) = delete; \
...

위의 에러는 google test를 포함한 테스트 코드가 -std=c++11 혹은 이상의 플래그를 포함하지 않아서 발생하는 문제이다.

Makefile의 경우에는 CXXFLAGS=-std=c++11을 추가해주면 해결된다.


+추가내용)

Undefined symbols for architecture x86_64:
"testing::Test::SetUp()", referenced from:
...

위의 경우에는 라이브러리가 연결되지 않아서 발생하는 문제이다.

마찬가지로 Makefile에서는 LDLIBS=-lgtest_main -lgtest -pthread 플래그를 추가하여 해결 할 수 있다.

MacOS 상태바 아이콘 위치 조정하는법

misc

Source: https://github.com/dwarvesf/hidden

⌘ 키 + 클릭 & 드래그 로 위의 gif 처럼 원하는 위치로 아이콘을 옮겨놓는것이 가능하다.

... 맥북 5년 사용하는 동안 처음알았다.

try/catch 구문에서 finally의 요점이 뭘까요?

stackoverflow

지난 몇년간 여러 프로그래밍 언어를 사용하면서 try-catch/except-finally 구문을 오래 사용해 왔습니다.
누군가 오늘 저에게 finally의 존재의의에 대해서 질문하였고, 저는 그것에 대해 대답할 수 없었습니다.

질문은 이렇습니다: try-catch 구문 이후에 코드를 작성하면 되는것을 굳이 finally를 사용할 필요가 있을까요?
혹은, 다음 코드에서 어떤 차이점이 있는지 말씀해 주실 수 있을까요?

try{ /* a */ }
catch { /* b */ }
finally { /* c */ }


try{ /* a */ }
catch{ /* b */ }
/* c */

finally 구문은 다음과 같은 3가지 상황 에서 catch 구문으로는 깔끔하게 처리하지 못하는 상황에서 빛을 발합니다:

  • 만약 try 안에 있는 코드에서 return을 할 경우.
  • catch 블록 안에서 잡아낸 예외를 다시 던지는 경우, 혹은 고의 혹은 실수로 새로운 예외를 던질 경우.
  • 만약 catch구문에서 잡아낼 수 없는 예외가 try 블록에서 발생 하였을 때.

물론 finally 구문의 코드를 각각의 return, throw 이전에 붙여넣고 catch 블록을 새로운 try/catch로 감싸서 새로운 예외가 던져질 가능성을 배제할 수 있겠지만, finally 구문을 사용하여 처리하는것이 가장 쉽고 깔끔한 방법입니다.