Skip to content

Commit

Permalink
Adding AUTOADD_SMARTSTACK macro which senses the function name
Browse files Browse the repository at this point in the history
  • Loading branch information
zcobell committed Sep 30, 2020
1 parent d381051 commit 2cbbb65
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 109 deletions.
4 changes: 3 additions & 1 deletion libsmartstack/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
//------------------------------------------------------------------------//
#include "function.h"

Function::Function(const std::string &name) : m_name(name), m_ncall(0) {}
#include <utility>

Function::Function(std::string name) : m_name(std::move(name)), m_ncall(0) {}

void Function::startFunction() {
this->m_timer.startClock();
Expand Down
2 changes: 1 addition & 1 deletion libsmartstack/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class Function {
public:
SMARTSTACK_EXPORT Function(const std::string &name);
SMARTSTACK_EXPORT explicit Function(std::string name);

void SMARTSTACK_EXPORT startFunction();
void SMARTSTACK_EXPORT endFunction();
Expand Down
2 changes: 1 addition & 1 deletion libsmartstack/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace SmartStack {
class Instrumentation {
public:
SMARTSTACK_EXPORT Instrumentation(const std::string &functionName,
SMARTSTACK_EXPORT explicit Instrumentation(const std::string &functionName,
bool showStack = false)
: m_showStack(showStack) {
SmartStack::Stack::startFunction(functionName, this->m_showStack);
Expand Down
28 changes: 14 additions & 14 deletions libsmartstack/smartstack.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MODULE SMARTSTACKMODULE
USE,INTRINSIC :: ISO_C_BINDING,ONLY:C_PTR
IMPLICIT NONE

INTEGER,PARAMETER :: SMARTSTACK_SORTASCENDING = 10000
INTEGER,PARAMETER :: SMARTSTACK_SORTDECENDING = 10001

Expand All @@ -16,7 +16,7 @@ MODULE SMARTSTACKMODULE
INTEGER,PARAMETER :: SMARTSTACK_SECONDS = 30002
INTEGER,PARAMETER :: SMARTSTACK_MINUTES = 30003
INTEGER,PARAMETER :: SMARTSTACK_HOURS = 30004

INTEGER,PARAMETER :: SMARTSTACK_TABLE = 40000
INTEGER,PARAMETER :: SMARTSTACK_CSV = 40001

Expand All @@ -39,7 +39,7 @@ TYPE(C_PTR) FUNCTION c_createSmartStack(functionName) &
IMPLICIT NONE
CHARACTER(KIND=C_CHAR),INTENT(IN) :: functionName
END FUNCTION c_createSmartStack

TYPE(C_PTR) FUNCTION c_createSmartStackShowTrace(functionName) &
BIND(C,NAME="addSmartStackShowFtn") RESULT(ptr)
USE,INTRINSIC :: ISO_C_BINDING,ONLY:C_PTR,C_CHAR
Expand All @@ -57,16 +57,16 @@ SUBROUTINE c_startSession(session_name,processorId,proc0ToScreen) BIND(C,NAME="s
USE,INTRINSIC :: ISO_C_BINDING,ONLY:C_PTR,C_CHAR,C_INT,C_BOOL
IMPLICIT NONE
CHARACTER(KIND=C_CHAR),INTENT(IN) :: session_name
INTEGER(KIND=C_INT),VALUE,INTENT(IN) :: processorId
INTEGER(KIND=C_INT),VALUE,INTENT(IN) :: processorId
LOGICAL(KIND=C_BOOL),VALUE,INTENT(IN) :: proc0ToScreen
END SUBROUTINE c_startSession

SUBROUTINE c_startSessionLog(session_name,processorId,proc0ToScreen,logFile) BIND(C,NAME="startSessionLogFtn")
USE,INTRINSIC :: ISO_C_BINDING,ONLY:C_PTR,C_CHAR,C_INT,C_BOOL
IMPLICIT NONE
CHARACTER(KIND=C_CHAR),INTENT(IN) :: session_name
CHARACTER(KIND=C_CHAR),INTENT(IN) :: logFile
INTEGER(KIND=C_INT),VALUE,INTENT(IN) :: processorId
INTEGER(KIND=C_INT),VALUE,INTENT(IN) :: processorId
LOGICAL(KIND=C_BOOL),VALUE,INTENT(IN) :: proc0ToScreen
END SUBROUTINE c_startSessionLog

Expand All @@ -77,17 +77,17 @@ END SUBROUTINE c_endSession
SUBROUTINE c_printStack() BIND(C,NAME="printCurrentStackFtn")
IMPLICIT NONE
END SUBROUTINE c_printStack

SUBROUTINE c_printStackMessage(message) BIND(C,NAME="printCurrentStackMessageFtn")
USE,INTRINSIC :: ISO_C_BINDING,ONLY: C_CHAR
IMPLICIT NONE
CHARACTER(KIND=C_CHAR),INTENT(IN) :: message
END SUBROUTINE c_printStackMessage

SUBROUTINE c_printCurrentFunction() BIND(C,NAME="printCurrentFunctionFtn")
IMPLICIT NONE
END SUBROUTINE c_printCurrentFunction

SUBROUTINE c_printCurrentFunctionMessage(message) BIND(C,NAME="printCurrentFunctionMessageFtn")
USE,INTRINSIC :: ISO_C_BINDING,ONLY: C_CHAR
IMPLICIT NONE
Expand Down Expand Up @@ -156,7 +156,7 @@ END SUBROUTINE init_t
FUNCTION constructor(function_name,showStack) RESULT(this)
USE,INTRINSIC :: ISO_C_BINDING,ONLY:C_PTR,C_CHAR,C_BOOL,&
C_NULL_CHAR
LOGICAL,INTENT(IN),OPTIONAL :: showStack
LOGICAL,INTENT(IN),OPTIONAL :: showStack
TYPE(SMARTSTACK) :: this
CHARACTER(*),INTENT(IN) :: function_name
LOGICAL :: doShowStack
Expand Down Expand Up @@ -221,7 +221,7 @@ SUBROUTINE SmartStack_printCurrentStack(message)
CALL c_printStack()
ENDIF
END SUBROUTINE SmartStack_printCurrentStack

SUBROUTINE SmartStack_printCurrentFunction(message)
USE,INTRINSIC :: ISO_C_BINDING,ONLY:C_CHAR,C_NULL_CHAR
IMPLICIT NONE
Expand All @@ -233,7 +233,7 @@ SUBROUTINE SmartStack_printCurrentFunction(message)
ENDIF
END SUBROUTINE SmartStack_printCurrentFunction

SUBROUTINE SmartStack_getCurrentStack(buffer)
SUBROUTINE SmartStack_getCurrentStack(buffer)
IMPLICIT NONE
CHARACTER(*),INTENT(OUT) :: buffer
CALL c_getCurrentStack()
Expand All @@ -246,8 +246,8 @@ SUBROUTINE SmartStack_getCurrentStack(buffer)
buffer = c_string_buffer
DEALLOCATE(c_string_buffer)
END SUBROUTINE SmartStack_getCurrentStack
SUBROUTINE SmartStack_getCurrentFunction(buffer)

SUBROUTINE SmartStack_getCurrentFunction(buffer)
IMPLICIT NONE
CHARACTER(*),INTENT(OUT) :: buffer
CALL c_getCurrentFunction()
Expand Down
10 changes: 8 additions & 2 deletions libsmartstack/smartstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
SmartStack::Instrumentation __SmartStackInstrument = \
SmartStack::addInstrumentation(fname);

#ifdef __func__
#define AUTOADD_SMARTSTACK() ADD_SMARTSTACK(__func__)
#else
#define AUTOADD_SMARTSTACK #error "__func__ not defined"
#endif

#define END_SMARTSTACK() SmartStack::endSession();

namespace SmartStack {
Expand Down Expand Up @@ -61,15 +67,15 @@ printFunction(const std::string &message = std::string()) {
void SMARTSTACK_EXPORT printTimingReport(
SmartStack::Stack::SortType sortType = SmartStack::Stack::SortType::Time,
SmartStack::Stack::SortOrder sortOrder =
SmartStack::Stack::SortOrder::Decending) {
SmartStack::Stack::SortOrder::Descending) {
SmartStack::Stack::printTimingReport(sortType, sortOrder);
}

void SMARTSTACK_EXPORT saveTimingReport(
const std::string &filename,
SmartStack::Stack::SortType sortType = SmartStack::Stack::SortType::Time,
SmartStack::Stack::SortOrder sortOrder =
SmartStack::Stack::SortOrder::Decending) {
SmartStack::Stack::SortOrder::Descending) {
SmartStack::Stack::saveTimingReport(filename, sortType, sortOrder);
}

Expand Down
2 changes: 1 addition & 1 deletion libsmartstack/smartstackftn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ constexpr std::array<SmartStack::Stack::SortType, 3> c_sortTypeList = {

constexpr std::array<SmartStack::Stack::SortOrder, 2> c_sortOrderList = {
SmartStack::Stack::SortOrder::Ascending,
SmartStack::Stack::SortOrder::Decending};
SmartStack::Stack::SortOrder::Descending};

constexpr std::array<SmartStack::Stack::TimeUnits, 5> c_unitsList = {
SmartStack::Stack::Microseconds, SmartStack::Stack::Milliseconds,
Expand Down
Loading

0 comments on commit 2cbbb65

Please sign in to comment.