Skip to content

Commit

Permalink
Replaced call to sscanf() with calls to strtoull(). Better. Faster. S…
Browse files Browse the repository at this point in the history
…tronger.
  • Loading branch information
jstedfast committed Aug 13, 2013
1 parent bd130f3 commit b609cbb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mono/utils/mono-proclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ get_cpu_times (int cpu_id, gint64 *user, gint64 *systemt, gint64 *irq, gint64 *s
char buf [256];
char *s;
int hz = get_user_hz ();
long long unsigned int user_ticks, nice_ticks, system_ticks, idle_ticks, iowait_ticks, irq_ticks, sirq_ticks;
guint64 user_ticks, nice_ticks, system_ticks, idle_ticks, iowait_ticks, irq_ticks, sirq_ticks;
FILE *f = fopen ("/proc/stat", "r");
if (!f)
return;
Expand All @@ -578,7 +578,14 @@ get_cpu_times (int cpu_id, gint64 *user, gint64 *systemt, gint64 *irq, gint64 *s
} else {
continue;
}
sscanf (data, "%Lu %Lu %Lu %Lu %Lu %Lu %Lu", &user_ticks, &nice_ticks, &system_ticks, &idle_ticks, &iowait_ticks, &irq_ticks, &sirq_ticks);

user_ticks = strtoull (data, &data, 10);
nice_ticks = strtoull (data, &data, 10);
system_ticks = strtoull (data, &data, 10);
idle_ticks = strtoull (data, &data, 10);
iowait_ticks = strtoull (data, &data, 10);
irq_ticks = strtoull (data, &data, 10);
sirq_ticks = strtoull (data, &data, 10);
break;
}
fclose (f);
Expand Down

0 comments on commit b609cbb

Please sign in to comment.