ä 2012å08æ31æ 02:29, David Ahern åé:In addition to Andrew's comment about making the stats struct andYes. :-)
functions generic...
Why? Since we don't care about the return value, what's the difference?
On 8/27/12 3:51 AM, Dong Hao wrote:
---8<---
+static void exit_event_decode_key(struct event_key *key, char
decode[20])
+{
+ const char *exit_reason = get_exit_reason(key->key);
+
+ snprintf(decode, 20, "%s", exit_reason);
+}
Use scnprintf rather than snprintf.
Thanks for pointing it out, we will terminate the running instance in
---8<---
+static bool kvm_event_expand(struct kvm_event *event, int vcpu_id)
+{
+ int old_max_vcpu = event->max_vcpu;
+
+ if (vcpu_id < event->max_vcpu)
+ return true;
+
+ while (event->max_vcpu <= vcpu_id)
+ event->max_vcpu += DEFAULT_VCPU_NUM;
+
+ event->vcpu = realloc(event->vcpu,
+ event->max_vcpu * sizeof(*event->vcpu));
+ if (!event->vcpu) {
If realloc fails you leak memory by overwriting the current pointer.
our next
version.
Since 'perf stat' uses relative standard deviation rather than stddev,
---8<---
+static double event_stats_stddev(int vcpu_id, struct kvm_event *event)
+{
+ struct event_stats *stats = &event->total;
+ double variance, variance_mean, stddev;
+
+ if (vcpu_id != -1)
+ stats = &event->vcpu[vcpu_id];
+
+ BUG_ON(!stats->count);
+
+ variance = stats->M2 / (stats->count - 1);
+ variance_mean = variance / stats->count;
+ stddev = sqrt(variance_mean);
+
+ return stddev * 100 / stats->mean;
+}
perf should be consistent in the stddev it shows the user. Any reason
to dump relative stddev versus stddev used by perf-stat?
'perf kvm stat'
just follows the style of 'perf stat'.
---8<---You mean, remove '-a' from the default options, then:
+ /*
+ * Append "-a" only if "-p"/"--pid" is not specified since they
+ * are mutually exclusive.
+ */
+ if (!kvm_record_specified_guest(argc, argv))
+ rec_argv[i++] = STRDUP_FAIL_EXIT("-a");
Other perf-kvm commands rely on perf-record semantics -- i.e., for
user to add the -a or -p option.
if a user wants to record all guest he will use 'perf stat record -a';
and if a user wants to record the specified guest, he should use
'perf stat record -p xxx'?
Well, as the style of other subcommand, e.g., perf lock/perf sched, the
'perf xxx record' record all events on all cpus, no need to use '-a'.
Based on mentioned above, I prefer the original way. ;)