[profiler] Don't flush empty log buffers.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Mon, 12 Sep 2016 08:44:00 +0000 (10:44 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Sun, 2 Oct 2016 16:44:55 +0000 (18:44 +0200)
mono/profiler/mono-profiler-log.c

index 0785378f04bf61bb2e23236848d8bc9ca957cef8..87bf160c10a9e434358cbf8082900571df95d6ed 100644 (file)
@@ -1337,24 +1337,26 @@ dump_buffer (MonoProfiler *profiler, LogBuffer *buf)
        if (buf->next)
                dump_buffer (profiler, buf->next);
 
-       p = write_int32 (p, BUF_ID);
-       p = write_int32 (p, buf->cursor - buf->buf);
-       p = write_int64 (p, buf->time_base);
-       p = write_int64 (p, buf->ptr_base);
-       p = write_int64 (p, buf->obj_base);
-       p = write_int64 (p, buf->thread_id);
-       p = write_int64 (p, buf->method_base);
+       if (buf->cursor - buf->buf) {
+               p = write_int32 (p, BUF_ID);
+               p = write_int32 (p, buf->cursor - buf->buf);
+               p = write_int64 (p, buf->time_base);
+               p = write_int64 (p, buf->ptr_base);
+               p = write_int64 (p, buf->obj_base);
+               p = write_int64 (p, buf->thread_id);
+               p = write_int64 (p, buf->method_base);
 
 #if defined (HAVE_SYS_ZLIB)
-       if (profiler->gzfile) {
-               gzwrite (profiler->gzfile, hbuf, p - hbuf);
-               gzwrite (profiler->gzfile, buf->buf, buf->cursor - buf->buf);
-       } else
+               if (profiler->gzfile) {
+                       gzwrite (profiler->gzfile, hbuf, p - hbuf);
+                       gzwrite (profiler->gzfile, buf->buf, buf->cursor - buf->buf);
+               } else
 #endif
-       {
-               fwrite (hbuf, p - hbuf, 1, profiler->file);
-               fwrite (buf->buf, buf->cursor - buf->buf, 1, profiler->file);
-               fflush (profiler->file);
+               {
+                       fwrite (hbuf, p - hbuf, 1, profiler->file);
+                       fwrite (buf->buf, buf->cursor - buf->buf, 1, profiler->file);
+                       fflush (profiler->file);
+               }
        }
 
        free_buffer (buf, buf->size);