Skip to content

Commit

Permalink
Merge pull request #16 from UniStuttgart-VISUS/pure
Browse files Browse the repository at this point in the history
Adds "pure" sampling API.
  • Loading branch information
crowbar27 authored Jun 25, 2023
2 parents 4cc2a94 + 840f4f4 commit 6074bbe
Show file tree
Hide file tree
Showing 44 changed files with 912 additions and 333 deletions.
25 changes: 25 additions & 0 deletions podump/adl_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ void sample_adl_sensor(void) {
}


/*
* ::sample_adl_sensor_data
*/
void sample_adl_sensor_data(void) {
using namespace visus::power_overwhelming;

try {
std::vector<adl_sensor> sensors;
sensors.resize(adl_sensor::for_all(nullptr, 0));
adl_sensor::for_all(sensors.data(), sensors.size());

for (auto &s : sensors) {
std::wcout << s.name() << L":" << std::endl;
auto m = s.sample_data();
std::wcout << m.timestamp() << L": "
<< m.voltage() << L" V, "
<< m.current() << L" A, "
<< m.power() << L" W" << std::endl;
}
} catch (std::exception &ex) {
std::cerr << ex.what() << std::endl;
}
}


/*
* ::sample_adl_sensor_async
*/
Expand Down
5 changes: 5 additions & 0 deletions podump/adl_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
/// </summary>
void sample_adl_sensor(void);

/// <summary>
/// Print data for all supported AMD cards using the pure sample method.
/// </summary>
void sample_adl_sensor_data(void);

/// <summary>
/// Sample all supported ADL sensors for the specified number of seconds.
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions podump/emi_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ void sample_emi_sensor(void) {
}


/*
* ::sample_emi_sensor_data
*/
void sample_emi_sensor_data(void) {
using namespace visus::power_overwhelming;

#if defined(_WIN32)
try {
std::vector<emi_sensor> sensors;
sensors.resize(emi_sensor::for_all(nullptr, 0));
emi_sensor::for_all(sensors.data(), sensors.size());

for (auto &s : sensors) {
std::wcout << s.name() << L":" << std::endl;
auto m = s.sample_data();
std::wcout << m.timestamp() << L": "
<< m.power() << L" W" << std::endl;
}
} catch (std::exception &ex) {
std::cerr << ex.what() << std::endl;
}
#endif /* defined(_WIN32) */
}


/*
* ::sample_emi_sensor_async
*/
Expand Down
6 changes: 6 additions & 0 deletions podump/emi_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
/// </summary>
void sample_emi_sensor(void);

/// <summary>
/// Samples all EMI sensors once using the pure sampling API and prints their
/// values on the console.
/// </summary>
void sample_emi_sensor_data(void);

/// <summary>
/// Samples all EMI sensors for the specified number of seconds.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions podump/msr_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ void sample_msr_sensor(void) {
}


/*
* ::sample_msr_sensor_data
*/
void sample_msr_sensor_data(void) {
using namespace visus::power_overwhelming;

try {
std::vector<msr_sensor> sensors;
sensors.resize(msr_sensor::for_all(nullptr, 0));
msr_sensor::for_all(sensors.data(), sensors.size());

for (auto &s : sensors) {
std::wcout << s.name() << L":" << std::endl;
auto m = s.sample_data();
std::wcout << m.timestamp() << L": "
<< m.power() << L" W" << std::endl;
}
} catch (std::exception &ex) {
std::cerr << ex.what() << std::endl;
}
}


/*
* ::sample_msr_sensor_async
*/
Expand Down
7 changes: 6 additions & 1 deletion podump/msr_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@


/// <summary>
/// Print data for all CPU cores cards.
/// Print data for all CPU cores.
/// </summary>
void sample_msr_sensor(void);

/// <summary>
/// Print data for all CPU cores using the pure sampling API.
/// </summary>
void sample_msr_sensor_data(void);

/// <summary>
/// Sample all supported MSR sensors for the specified number of seconds.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions podump/nvml_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ void sample_nvml_sensor(void) {
}


/*
* ::sample_nvml_sensor_data
*/
void sample_nvml_sensor_data(void) {
using namespace visus::power_overwhelming;

try {
std::vector<nvml_sensor> sensors;
sensors.resize(nvml_sensor::for_all(nullptr, 0));
nvml_sensor::for_all(sensors.data(), sensors.size());

for (auto &s : sensors) {
std::wcout << s.name() << L":" << std::endl;
auto m = s.sample_data();
std::wcout << m.timestamp() << L": " << m.power() << L" W"
<< std::endl;
}
} catch (std::exception &ex) {
std::cerr << ex.what() << std::endl;
}
}


/*
* ::sample_nvml_sensor_async
*/
Expand Down
5 changes: 5 additions & 0 deletions podump/nvml_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
/// </summary>
void sample_nvml_sensor(void);

/// <summary>
/// Print data for all supported NVIDIA cards using the pure sample method.
/// </summary>
void sample_nvml_sensor_data(void);

/// <summary>
/// Sample all supported NVML sensors for the specified number of seconds.
/// </summary>
Expand Down
20 changes: 18 additions & 2 deletions podump/podump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ int _tmain(const int argc, const TCHAR **argv) {
#endif

// AMD sensors
#if false
#if true
#if true
::sample_adl_sensor();
#endif

#if true
::sample_adl_sensor_data();
#endif

#if true
::sample_adl_sensor_async(5);
#endif
Expand All @@ -54,6 +58,10 @@ int _tmain(const int argc, const TCHAR **argv) {
::sample_emi_sensor();
#endif

#if true
::sample_emi_sensor_data();
#endif

#if true
::sample_emi_sensor_async(5);
#endif
Expand All @@ -71,11 +79,15 @@ int _tmain(const int argc, const TCHAR **argv) {
#endif

// NVML sensors
#if false
#if true
#if true
::sample_nvml_sensor();
#endif

#if true
::sample_nvml_sensor_data();
#endif

#if true
::sample_nvml_sensor_async(5);
#endif
Expand All @@ -87,6 +99,10 @@ int _tmain(const int argc, const TCHAR **argv) {
::sample_tinkerforge_sensor();
#endif

#if true
::sample_tinkerforge_sensor_data();
#endif

#if true
::sample_tinkerforge_sensor_async(5);
#endif
Expand Down
33 changes: 33 additions & 0 deletions podump/tinkerforge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,39 @@ void sample_tinkerforge_sensor(void) {
}


/*
* ::sample_tinkerforge_sensor_data
*/
void sample_tinkerforge_sensor_data(void) {
using namespace visus::power_overwhelming;

try {
std::vector<tinkerforge_sensor_definition> descs;
descs.resize(tinkerforge_sensor::get_definitions(nullptr, 0));
auto cnt = tinkerforge_sensor::get_definitions(descs.data(),
descs.size());

if (cnt < descs.size()) {
descs.resize(cnt);
}

for (auto &d : descs) {
tinkerforge_sensor s(d);
std::wcout << s.name() << L":" << std::endl;
auto m = s.sample_data();
std::wcout << m.timestamp() << L": "
<< m.voltage() << " V * "
<< m.current() << " A = "
<< m.power() << L" W"
<< std::endl;
}

} catch (std::exception &ex) {
std::cerr << ex.what() << std::endl;
}
}


/*
* ::sample_tinkerforge_sensor_async
*/
Expand Down
5 changes: 5 additions & 0 deletions podump/tinkerforge.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
/// </summary>
void sample_tinkerforge_sensor(void);

/// <summary>
/// Print values of all Tinkerforge bricklets attached to the machine using the
/// pure sampling API.
/// </summary>
void sample_tinkerforge_sensor_data(void);

/// <summary>
/// Samples all Tinkerforge bricklets attached to the machine for the specified
Expand Down
20 changes: 6 additions & 14 deletions power_overwhelming/include/power_overwhelming/adl_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,6 @@ namespace power_overwhelming {
virtual _Ret_maybenull_z_ const wchar_t *name(
void) const noexcept override;

/// <summary>
/// Sample the sensor.
/// </summary>
/// <param name="resolution">The temporal resolution of the timestamp
/// to be returned.</param>
/// <returns>A sensor sample with the information about power
/// consumption that is available via ADL.</returns>
/// <exception cref="std::runtime_error">If a sensor that has been moved
/// is sampled.</exception>
/// <exception cref="adl_exception">If the sensor could not be sampled.
/// </exception>
virtual measurement sample(
_In_ const timestamp_resolution resolution) const override;

/// <summary>
/// Asynchronously sample the sensor every
/// <paramref name="sampling_period "/> microseconds.
Expand Down Expand Up @@ -246,6 +232,12 @@ namespace power_overwhelming {
/// otherwise.</returns>
virtual operator bool(void) const noexcept override;

protected:

/// <inheritdoc />
measurement_data sample_sync(
_In_ const timestamp_resolution resolution) const override;

private:

detail::adl_sensor_impl *_impl;
Expand Down
10 changes: 6 additions & 4 deletions power_overwhelming/include/power_overwhelming/emi_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ namespace power_overwhelming {
/// is invalid.</returns>
_Ret_maybenull_z_ const char_type *path(void) const noexcept;

/// <inheritdoc />
virtual measurement sample(
_In_ const timestamp_resolution resolution) const override;

/// <summary>
/// Asynchronously sample the sensor every
/// <paramref name="sampling_period "/> microseconds.
Expand Down Expand Up @@ -322,6 +318,12 @@ namespace power_overwhelming {
/// <inheritdoc />
virtual operator bool(void) const noexcept override;

protected:

/// <inheritdoc />
measurement_data sample_sync(
_In_ const timestamp_resolution resolution) const override;

private:

detail::emi_sensor_impl *_impl;
Expand Down
19 changes: 6 additions & 13 deletions power_overwhelming/include/power_overwhelming/hmc8015_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,6 @@ namespace power_overwhelming {
/// processed successfully.</exception>
virtual void reset(void) override;

/// <summary>
/// Samples the sensor one time.
/// </summary>
/// <param name="resolution">The resolution of the timestamp to be
/// generated for the measurement.</param>
/// <returns>The measurement received from the instrument.</returns>
/// <exception cref="std::runtime_error">If the method is called on an
/// object that has been disposed by moving it.</exception>
/// <exception cref="visa_exception">If the VISA command was not
/// processed successfully.</exception>
virtual measurement sample(
_In_ const timestamp_resolution resolution) const override;

using sensor::sample;

/// <summary>
Expand Down Expand Up @@ -318,6 +305,12 @@ namespace power_overwhelming {
return *this;
}

protected:

/// <inheritdoc />
measurement_data sample_sync(
_In_ const timestamp_resolution resolution) const override;

private:

void configure(void);
Expand Down
Loading

0 comments on commit 6074bbe

Please sign in to comment.