Skip to content

Commit

Permalink
Pre commit hooks (#5)
Browse files Browse the repository at this point in the history
Setup pre-commit hooks to make sure codestyle is valid
  • Loading branch information
cedric-chedaleux authored Aug 8, 2023
2 parents f47e943 + 91bfb8c commit 7de7441
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 26 deletions.
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6
hooks:
- id: clang-format
11 changes: 5 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Copyright (c) 2022, Orange
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS AS IS AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -24,4 +24,3 @@ Copyright (c) 2022, Orange
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ This project provides a tiny C++ profiling library for monitoring:
* GPU usage and memory

This library aims at collecting metrics on embedded devices to monitor device
performance while operating heavy tasks or booting for example. Those metrics can
be useful to check that load is properly spread onto all CPU cores or
performance while operating heavy tasks or booting for example. Those metrics can
be useful to check that load is properly spread onto all CPU cores or
that memory is not starved.

This library can also run on non-embedded devices like servers or desktop PCs. It is
This library can also run on non-embedded devices like servers or desktop PCs. It is
compatible with Linux and Windows.

Metrics are stored in a CSV file (the path is configurable).
Expand Down Expand Up @@ -142,7 +142,7 @@ $ ../build-cppuprofile/sample/uprof-sample

## Windows support limitations

The library compiles on Windows but only time execution is supported so far. Monitoring metrics like CPU Usage and system, process and nvidia GPU memory are not supported.
The library compiles on Windows but only time execution is supported so far. Monitoring metrics like CPU Usage and system, process and nvidia GPU memory are not supported.

Contributions are welcomed.

Expand Down
1 change: 0 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,3 @@ INSTALL(TARGETS ${LIBRARY_NAME}
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION lib/pkgconfig
)

2 changes: 1 addition & 1 deletion lib/timestampunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ enum class TimestampUnit {

}

#endif /* TIMESTAMP_UNIT_H_ */
#endif /* TIMESTAMP_UNIT_H_ */
4 changes: 2 additions & 2 deletions lib/uprofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ UPROFAPI void timeBegin(const std::string& title);
/**
* @ingroup uprofile
* @brief Stop monitoring the execution time of the given event
*
*
* The library computes the duration for the given event and saves it into the report file.
*
*
* If no timeBegin() has been called with the given title, the call is ignored.
*/
UPROFAPI void timeEnd(const std::string& title);
Expand Down
5 changes: 3 additions & 2 deletions lib/util/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ void Timer::setTimeout(const std::function<void(void)>& timeout)
m_timeout = timeout;
}

bool Timer::isRunning() {
std::lock_guard<std::mutex> lock(m_mutex);
bool Timer::isRunning()
{
std::lock_guard<std::mutex> lock(m_mutex);
return m_running;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <chrono>
#include <functional>
#include <iostream>
#include <thread>
#include <mutex>
#include <thread>

using namespace std;

Expand Down
1 change: 0 additions & 1 deletion sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME}
)

INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)

17 changes: 9 additions & 8 deletions sample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
//
// Author: Cédric CHEDALEUX <cedric.chedaleux@orange.com> et al

#include <thread>
#include <chrono>
#include <uprofile.h>
#include <stdlib.h>
#include <thread>
#include <uprofile.h>

void printSystemMemory() {
void printSystemMemory()
{
int total = 0, free = 0, available = 0;
uprofile::getSystemMemory(total, free, available);
printf("Memory: total = %i MB, free = %i MB, available = %i MB\n", total / 1000, free / 1000, available / 1000);
}

int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
uprofile::start("./test.log");

Expand All @@ -40,10 +41,10 @@ int main(int argc, char *argv[])
uprofile::timeBegin("UseMemory");

int lengthBuff = 100000000;
char * buf;
char* buf;
printf("Allocating %f MB\n", lengthBuff / sizeof(char) / 1000000.0f);
buf = (char*) malloc (lengthBuff+1);
for (int i=0; i < lengthBuff; i++) {
buf = (char*)malloc(lengthBuff + 1);
for (int i = 0; i < lengthBuff; i++) {
buf[i] = rand() % 26 + 'a';
}
buf[lengthBuff] = '\0';
Expand All @@ -64,7 +65,7 @@ int main(int argc, char *argv[])

// --- WAIT 5 SECONDS ---
uprofile::timeBegin("Sleep2");
std::this_thread::sleep_for(std::chrono::seconds(5));
std::this_thread::sleep_for(std::chrono::seconds(5));
uprofile::timeEnd("Sleep2");

uprofile::stop();
Expand Down

0 comments on commit 7de7441

Please sign in to comment.