[1d97c1]: nouveau-pm / tools / extract.c  Maximize  Restore  History

Download this file

100 lines (86 with data), 2.6 kB

 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
This is a small program that splits the dumps into sections
correcponding to the different periods in the downclocking
The file info.txt shows the frequencies, and the dumps that
contain information about it
XXX: Simplify this using a script?
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *srcFile, *outputFile, * infoFile;
void fileio_error(char *filename, char mode)
{
printf("Error while trying to %s %s\n", ((mode = 'w') ? "write to" : "read from"), filename);
if (outputFile)
fclose(outputFile);
if (infoFile)
fclose(infoFile);
if (srcFile)
fclose(srcFile);
}
int main(int argc, char **argv)
{
char mark_str[100], *nv_str, input_filename[255], output_filename[255];
char *data, buffer[200], *ret, *clock_freq_available, *perf_list_available;
int i, start_to_dump, not_mark, not_unknown;
i = start_to_dump = 0;
not_mark = not_unknown = 0;
if (argc != 2) {
printf("Argument count mismatch\nUsage \"%s mmio-dump\"", argv[0]);
return(1);
}
sscanf (argv[1], "%s", input_filename);
srcFile = fopen(input_filename,"r");
if ( !srcFile ) {
fileio_error(input_filename, 'r');
return(1);
}
infoFile = fopen("info.txt","w");
if ( !infoFile ) {
fileio_error("info.txt", 'r');
return(1);
}
outputFile = NULL;
while ((!feof(srcFile)) & (fgets(buffer, 200, srcFile)!=0)) {
sscanf( buffer , "%s", mark_str);
not_mark = strncmp(mark_str,"MARK",4);
not_unknown = strncmp(mark_str,"UNKNOWN",7);
nv_str = strstr( buffer, "NV_" );
if (not_mark) {
if (start_to_dump)
// Current line is not a MARK and the output file has been open
fputs( buffer, outputFile);
} else if (nv_str) {
// Current line contains "NV_"
perf_list_available = strstr( buffer, "NV_CTRL_STRING_PERFORMANCE_MODES");
if (perf_list_available)
// Dump the list of perf modes to the infofile
fprintf( infoFile,"%s", perf_list_available );
clock_freq_available = strstr( buffer, "NV_CTRL_GPU_CURRENT_CLOCK_FREQS");
if (clock_freq_available) {
// Close any previous outputfile
if (outputFile)
fclose(outputFile);
i++;
// And open a new one
sprintf( output_filename, "transition-%d", i );
outputFile = fopen(output_filename,"w");
fprintf( infoFile,"%s >>>>>> %s <<<<<<\n", clock_freq_available, output_filename );
if ( !outputFile ) {
fileio_error(output_filename, 'w');
return(1);
}
printf("File %s opened\n", output_filename);
start_to_dump = 1;
}
}
}
if (outputFile)
fclose(outputFile);
if (infoFile)
fclose(infoFile);
if (srcFile)
fclose(srcFile);
return 0;
}