Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
210010049
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2021
210010049
Commits
f95f5cf9
Commit
f95f5cf9
authored
Sep 30, 2021
by
李弘宇
Browse files
Options
Downloads
Patches
Plain Diff
Delete idle_cal.c
parent
696295ec
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
patch_code/idle_cal.c
+0
-95
0 additions, 95 deletions
patch_code/idle_cal.c
with
0 additions
and
95 deletions
patch_code/idle_cal.c
deleted
100644 → 0
+
0
−
95
View file @
696295ec
#include
<stdlib.h>
#include
<stdio.h>
#include
<fcntl.h>
#include
<string.h>
#include
<unistd.h>
#include
<time.h>
#include
<limits.h>
#include
<sys/time.h>
#define CPUS 4
#define BUFFSIZE 4096
#define HZ 100
#define FILE_NAME "/proc/stat2"
struct
cpu_info
{
char
name
[
BUFFSIZE
];
long
long
value
[
1
];
};
int
main
(
void
)
{
char
buf
[
BUFFSIZE
];
struct
cpu_info
cpus
[
CPUS
+
1
];
struct
cpu_info
cpus_2
[
CPUS
+
1
];
long
long
sub
;
double
value
;
FILE
*
fp
=
fopen
(
FILE_NAME
,
"r"
);
int
i
=
0
;
struct
timeval
start
,
end
;
while
(
i
<
CPUS
+
1
)
{
int
n
=
fscanf
(
fp
,
"%s %lld
\n
"
,
cpus
[
i
].
name
,
&
cpus
[
i
].
value
[
0
]);
if
(
n
<
0
)
{
printf
(
"wrong"
);
return
-
1
;
}
i
+=
1
;
}
for
(
int
i
=
0
;
i
<
CPUS
+
1
;
i
++
)
{
printf
(
"%s %lld
\n
"
,
cpus
[
i
].
name
,
cpus
[
i
].
value
[
0
]);
}
gettimeofday
(
&
start
,
NULL
);
fflush
(
fp
);
fclose
(
fp
);
i
=
0
;
sleep
(
2
);
FILE
*
fp_2
=
fopen
(
FILE_NAME
,
"r"
);
while
(
i
<
CPUS
+
1
)
{
int
n
=
fscanf
(
fp_2
,
"%s %lld
\n
"
,
cpus_2
[
i
].
name
,
&
cpus_2
[
i
].
value
[
0
]);
if
(
n
<
0
)
{
printf
(
"wrong"
);
return
-
1
;
}
i
+=
1
;
}
for
(
int
i
=
0
;
i
<
CPUS
+
1
;
i
++
)
{
printf
(
"%s %lld
\n
"
,
cpus_2
[
i
].
name
,
cpus_2
[
i
].
value
[
0
]);
}
gettimeofday
(
&
end
,
NULL
);
fclose
(
fp_2
);
sub
=
end
.
tv_sec
-
start
.
tv_sec
;
value
=
sub
*
1000000
.
0
+
end
.
tv_usec
-
start
.
tv_usec
;
printf
(
"CPU idle rate %f
\n
"
,
1000000
/
HZ
*
(
cpus_2
[
0
].
value
[
0
]
-
cpus
[
0
].
value
[
0
])
/
value
);
for
(
int
i
=
1
;
i
<
CPUS
+
1
;
i
++
)
{
printf
(
"CPU%d idle rate %f
\n
"
,
i
-
1
,
1000000
/
HZ
*
(
cpus_2
[
i
].
value
[
0
]
-
cpus
[
i
].
value
[
0
])
/
value
);
}
printf
(
"%f
\n
"
,
value
);
long
long
value_sub
=
cpus_2
[
0
].
value
[
0
]
-
cpus
[
0
].
value
[
0
];
printf
(
"%lld %lld %lld
\n
"
,
cpus_2
[
0
].
value
[
0
],
cpus
[
0
].
value
[
0
],
value_sub
);
printf
(
"%ld.%06ld
\n
%ld.%06ld
\n
"
,
start
.
tv_sec
,
start
.
tv_usec
,
end
.
tv_sec
,
end
.
tv_usec
);
printf
(
"%.0f %0.f
\n
"
,
start
.
tv_sec
*
1000000
.
0
+
start
.
tv_usec
,
end
.
tv_sec
*
1000000
.
0
+
end
.
tv_usec
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment