This repository has been archived by the owner on Dec 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframework.h
77 lines (54 loc) · 1.56 KB
/
framework.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef __powermodels_framework_h__
#define __powermodels_framework_h__
#include "nvml.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <pthread.h>
// the helper methods simply encapsulate calls
// to the nvml library if the user does not want
// to do these themselves
// initializes nvml and returns the first device
int helper_pmfInit(nvmlDevice_t* device);
// shuts down nvml
void helper_pmfShutdown();
typedef struct pmfMeasurement_st {
unsigned int temperature;
unsigned int utilization;
unsigned int power;
} pmfMeasurement_t;
typedef struct pmfTimedData_st {
void* data;
unsigned long long timeMilli;
} pmfTimedData_t;
typedef struct pmf_st {
nvmlDevice_t device;
long startTime;
long endTime;
pthread_t thread;
int alive;
pthread_mutex_t aliveLock;
pmfTimedData_t labels[32];
int labelCount;
// dynamically growing array
pmfTimedData_t* measurements;
int measurementCapacity;
int measurementCount;
unsigned long long lastMeasurement;
} pmf_t;
// starts measurements on a specific device
// by spawning a thread that does continuous
// measurements
pmf_t* pmfStart(nvmlDevice_t device);
void pmfLabel(pmf_t* pmf, char* name);
// stops the measurements by stopping the
// measuring thread
void pmfEnd(pmf_t* pmf);
// writes the measurements to a file
void pmfExport(pmf_t* pmf, char* filename);
// PRIVATE FUNCTIONS BELOW
void insertMeasurement(pmf_t* pmf, pmfMeasurement_t* measurement, unsigned long long timestamp);
unsigned long long currMicro();
void* p_startThread(void*);
#endif